-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscreen_handler_physical.go
61 lines (50 loc) · 1.15 KB
/
screen_handler_physical.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
package main
import (
"fmt"
"os"
"github.com/gdamore/tcell"
)
type physicalScreenHandler struct {
screen tcell.Screen
}
func (s *physicalScreenHandler) close() {
s.screen.Fini()
}
func (s *physicalScreenHandler) sync() {
s.screen.Show()
}
func (s *physicalScreenHandler) putStr(x, y int, b rune) {
s.screen.SetContent(x, y, b, []rune{}, tcell.StyleDefault)
}
func (s *physicalScreenHandler) clearStr(x, y int) {
s.putStr(x, y, 0)
}
func (s *physicalScreenHandler) getSize() (int, int) {
return s.screen.Size()
}
func (s *physicalScreenHandler) pollKeyPress() interface{} {
for {
switch ev := s.screen.PollEvent().(type) {
case *tcell.EventKey:
return keyEvent{rn: ev.Rune(), k: ev.Key()}
case *tcell.EventResize:
return resizeEvent{}
}
}
}
func initPhysicalScreenHandler() screenHandler {
s, e := tcell.NewScreen()
if e != nil {
fmt.Fprintf(os.Stderr, "Error 1: %v\n", e)
os.Exit(1)
}
if e := s.Init(); e != nil {
fmt.Fprintf(os.Stderr, "Error 2:%v\n", e)
os.Exit(1)
}
defStyle := tcell.StyleDefault.
Background(tcell.ColorBlack).
Foreground(tcell.ColorWhite)
s.SetStyle(defStyle)
return &physicalScreenHandler{screen: s}
}