-
Notifications
You must be signed in to change notification settings - Fork 2
/
screen.go
52 lines (34 loc) · 974 Bytes
/
screen.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
package main
import "github.com/nsf/termbox-go"
type screen struct{}
func (s *screen) init() {
err := termbox.Init()
if err != nil {
panic(err)
}
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
s.drawText(strHeader, 0, 0)
drawHelp()
termbox.Flush()
}
func drawHelp() {
scr.drawColoredText(" ^C ", 0, 23, termbox.ColorBlack, termbox.ColorWhite)
scr.drawText("Exit", 5, 23)
scr.drawColoredText(" P ", 13, 23, termbox.ColorBlack, termbox.ColorWhite)
scr.drawText("Pause Timer", 17, 23)
}
func (s *screen) drawColoredText(text string, startX, y int, fg, bg termbox.Attribute) {
currX := startX
for i := 0; i < len(text); i++ {
termbox.SetCell(currX, y, rune(text[i]), fg, bg)
currX++
}
}
func (s *screen) drawText(text string, startX, y int) {
scr.drawColoredText(text, startX, y, termbox.ColorDefault, termbox.ColorDefault)
}
func (s *screen) close() {
if termbox.IsInit {
defer termbox.Close()
}
}