golang-exercises/golangr/counter/main.go

35 lines
472 B
Go
Raw Normal View History

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