-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.go
38 lines (32 loc) · 945 Bytes
/
control.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
package main
import (
"fmt"
"github.com/nsf/termbox-go"
)
// getKeyboardCommand sends all keys pressed on the keyboard as runes (characters) on the key chan.
// getKeyboardCommand will NOT work if termbox isn't initialised (in startControlServer)
func getKeyboardCommand(key chan<- rune) {
for {
event := termbox.PollEvent()
if event.Type == termbox.EventKey {
if event.Key != 0 {
key <- rune(event.Key)
} else if event.Ch != 0 {
key <- event.Ch
}
}
}
}
// startControlServer initialises termbox and prints basic information about the game configuration.
func startControlServer(p golParams) {
e := termbox.Init()
check(e)
fmt.Println("Threads:", p.threads)
fmt.Println("Width:", p.imageWidth)
fmt.Println("Height:", p.imageHeight)
}
// StopControlServer closes termbox.
// If the program is terminated without closing termbox the terminal window may misbehave.
func StopControlServer() {
termbox.Close()
}