-
Notifications
You must be signed in to change notification settings - Fork 0
/
mamba.go
60 lines (50 loc) · 881 Bytes
/
mamba.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
package mamba
import (
"os"
"github.com/gdamore/tcell/v2"
)
type Screen struct {
s tcell.Screen
f *Frame
}
func NewScreen() (*Screen, error) {
screen, err := tcell.NewScreen()
if err != nil {
return nil, err
}
if err := screen.Init(); err != nil {
return nil, err
}
w, h := screen.Size()
frame, err := NewFrame(screen, 0, 0, w, h)
if err != nil {
return nil, err
}
return &Screen{screen, frame}, nil
}
// Run is a blocking operation.
func (s *Screen) Run() {
quit := func() {
s.s.Fini()
os.Exit(0)
}
for {
s.s.Show()
ev := s.s.PollEvent()
switch ev := ev.(type) {
case *tcell.EventResize:
s.s.Clear()
w, h := ev.Size()
s.f.Resize(w, h)
s.f.Show()
s.s.Sync()
case *tcell.EventKey:
if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
quit()
}
}
}
}
func (s *Screen) Frame() *Frame {
return s.f
}