golang-exercises/golangr/counter/main.go

35 lines
472 B
Go

package main
import (
"fmt"
"os"
"strconv"
"time"
)
var delay time.Duration
var num int16
func clear() {
fmt.Print("\033[H\033[2J")
}
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: ./counter 1000 (measured in miliseconds)")
os.Exit(1)
}
delay, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Printf("\nERROR:\n%v\n", err)
}
for i := 0; true; i++ {
clear()
fmt.Println(i)
time.Sleep(time.Duration(delay) * time.Millisecond)
}
}