forked from jmhobbs/terminal-parrot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparrot.go
47 lines (40 loc) · 940 Bytes
/
parrot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import "github.com/nsf/termbox-go"
import "time"
import "flag"
func main() {
loops := flag.Int("loops", 0, "number of times to loop (default: infinite)")
delay := flag.Int("delay", 75, "frame delay in ms")
orientation := flag.String("orientation", "regular", "regular or aussie")
flag.Parse()
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
event_queue := make(chan termbox.Event)
go func() {
for {
event_queue <- termbox.PollEvent()
}
}()
termbox.SetOutputMode(termbox.Output256)
loop_index := 0
draw(*orientation)
loop:
for {
select {
case ev := <-event_queue:
if (ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc) || ev.Type == termbox.EventInterrupt {
break loop
}
default:
loop_index++
if *loops > 0 && (loop_index/9) >= *loops {
break loop
}
draw(*orientation)
time.Sleep(time.Duration(*delay) * time.Millisecond)
}
}
}