-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.go
More file actions
67 lines (50 loc) · 1.12 KB
/
screen.go
File metadata and controls
67 lines (50 loc) · 1.12 KB
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
62
63
64
65
66
67
package main
import (
"log"
"github.com/tncardoso/gocurses"
)
// Screen represents the application screen
type Screen struct {
w int
h int
}
var screen Screen
// Setup performs setup for screen
func (s *Screen) Setup() {
log.Println("setup screen...")
gocurses.Initscr()
gocurses.Cbreak()
gocurses.Noecho()
gocurses.CursSet(0)
s.h, s.w = gocurses.Getmaxyx()
// Endlessly wait for input, so keypresses do not affect the screen
go func() {
for {
gocurses.Stdscr.Getch()
}
}()
}
// AddChar adds a character to the screen buffer
func (s *Screen) AddChar(char rune, x, y int) {
gocurses.Mvaddch(y, x, char)
}
// Clear clears the screen buffer
func (s *Screen) Clear() {
gocurses.Clear()
}
// Flush flushes the screen buffer, writing everything to the screen
func (s *Screen) Flush() {
gocurses.Refresh()
}
// Resize updates the screen size to the latest
func (s *Screen) Resize() {
log.Println("resize screen...")
gocurses.End()
gocurses.Refresh()
s.h, s.w = gocurses.Getmaxyx()
}
// Teardown performs teardown for screen
func (s *Screen) Teardown() {
log.Println("teardown screen...")
gocurses.End()
}