-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.08 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Press ESC to exit the program.
package main
import (
"fmt"
"os"
"time"
"github.com/gdamore/tcell"
)
func main() {
tcell.SetEncodingFallback(tcell.EncodingFallbackASCII)
s, e := tcell.NewScreen()
if e != nil {
fmt.Fprintf(os.Stderr, "%v\n", e)
os.Exit(1)
}
if e = s.Init(); e != nil {
fmt.Fprintf(os.Stderr, "%v\n", e)
os.Exit(1)
}
s.SetStyle(tcell.StyleDefault.
Background(tcell.ColorBlack))
s.Clear()
quit := make(chan struct{})
go func() {
for {
ev := s.PollEvent()
switch ev := ev.(type) {
case *tcell.EventKey:
switch ev.Key() {
case tcell.KeyEscape, tcell.KeyEnter:
close(quit)
return
}
case *tcell.EventResize:
s.Sync()
}
}
}()
cnt := 0
dur := time.Duration(0)
render := NewRender(s)
loop:
for {
select {
case <-quit:
break loop
case <-time.After(time.Millisecond * 100):
}
start := time.Now()
render.rend()
cnt++
dur += time.Now().Sub(start)
}
s.Fini()
// fmt.Printf("Finished %d boxes in %s\n", cnt, dur)
// fmt.Printf("Average is %0.3f ms / box\n", (float64(dur)/float64(cnt))/1000000.0)
}