-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapollo.go
43 lines (38 loc) · 795 Bytes
/
apollo.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
package main
import (
"github.com/nsf/termbox-go"
"log"
)
// Loop is the main loop of the application. It creates a new goroutine to fetch new events
// and forwards all of them to Apollo. The screen is redrawn after each event.
func (a *Apollo) loop() {
go func() {
for {
a.events <- termbox.PollEvent()
}
}()
for a.running {
select {
case ev := <-a.events:
err := a.handleEvent(&ev)
a.draw()
if err != nil {
a.running = false
log.Fatal(err)
}
}
}
}
// Main function of the application. Initializes termbox, creates a new Apollo,
// and calls the main loop.
func main() {
err := termbox.Init()
if err != nil {
log.Fatal(err)
}
defer termbox.Close()
termbox.SetInputMode(termbox.InputAlt)
apollo := newApollo()
apollo.draw()
apollo.loop()
}