Open mchirico opened 3 years ago
Create an animated clock. See the program below, which is very similar
This program prints and animated spinner. Mutex isn't needed; but, makes it makes it thread safe.
repl.it
package main import ( "fmt" "sync" "time" ) type MF struct { l int sync.Mutex } func (mf *MF)mfmt(txt string,timeSleep int) { mf.Mutex.Lock() defer mf.Mutex.Unlock() for i:=0;i<mf.l;i++ { fmt.Printf("\b") // backspace } mf.l = len(txt) fmt.Printf("%s",txt) time.Sleep(time.Duration(timeSleep) * time.Millisecond) } func main() { msg := []string{"\\ ","| ","/ ","- ","+ ","- ","* "} m := &MF{} for i :=0; i < 100 ; i++ { for _, v := range msg { m.mfmt(v, 50) } } }
package main import ( "fmt" "time" ) func main() { now := time.Now() fmt.Printf("%02d:%02d:%02d\n",now.Hour(),now.Minute(),now.Second()) }
mchirico, Thanks for opening this issue!
is the spinning per second or should it go with the hour:min
@ZoeChiri Your choice...
Create Animated Clock
Create an animated clock. See the program below, which is very similar
This program prints and animated spinner. Mutex isn't needed; but, makes it makes it thread safe.
repl.it
Helper