-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.go
173 lines (128 loc) · 3.69 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package main
import (
"github.com/gdamore/tcell/v2"
)
type Screen struct {
tabBuffer *TabBuffer
tScreen tcell.Screen
debugAreaHeight int
fileInfoAreaHeight int
}
func NewTestScreen(argv []string) (*Screen, error) {
const DEBUG_AREA_HEIGHT = 5
const FILE_INFO_AREA_HEIGHT = 1
s := tcell.NewSimulationScreen("UTF-8")
if err := s.Init(); err != nil {
return nil, err
}
defStyle := tcell.StyleDefault.
Background(tcell.ColorBlack).
Foreground(tcell.ColorWhite)
s.SetStyle(defStyle)
screen := &Screen{tScreen: s}
var filename string
if len(argv) > 1 {
filename = argv[1]
} else {
filename = ""
}
screen.debugAreaHeight = DEBUG_AREA_HEIGHT
screen.fileInfoAreaHeight = FILE_INFO_AREA_HEIGHT
screen.CreateDebugArea()
screen.CreateFileInfoArea()
screen.WriteFileName(filename, 0)
width, height := s.Size()
bounds := [4][2]int{
{0, screen.fileInfoAreaHeight},
{width, screen.fileInfoAreaHeight},
{0, height - screen.debugAreaHeight},
{width, height - screen.debugAreaHeight},
}
if filename == "" {
screen.tabBuffer = NewTabBuffer("", 10, screen, filename, bounds)
} else {
screen.tabBuffer = NewTabBufferFromFile(filename, screen, bounds)
}
// screen.tabBuffer.cursor.SetPos(0, bounds[0][1], screen.tabBuffer)
return screen, nil
}
func NewScreen(argv []string) (*Screen, error) {
const DEBUG_AREA_HEIGHT = 5
const FILE_INFO_AREA_HEIGHT = 1
s, err := tcell.NewScreen()
if err != nil {
return nil, err
}
if err := s.Init(); err != nil {
return nil, err
}
defStyle := tcell.StyleDefault.
Background(tcell.ColorBlack).
Foreground(tcell.ColorWhite)
s.SetStyle(defStyle)
screen := &Screen{tScreen: s}
var filename string
if len(argv) > 1 {
filename = argv[1]
} else {
filename = ""
}
screen.debugAreaHeight = DEBUG_AREA_HEIGHT
screen.fileInfoAreaHeight = FILE_INFO_AREA_HEIGHT
screen.CreateDebugArea()
screen.CreateFileInfoArea()
screen.WriteFileName(filename, 0)
width, height := s.Size()
bounds := [4][2]int{
{0, screen.fileInfoAreaHeight},
{width, screen.fileInfoAreaHeight},
{0, height - screen.debugAreaHeight},
{width, height - screen.debugAreaHeight},
}
if filename == "" {
screen.tabBuffer = NewTabBuffer("", 10, screen, filename, bounds)
} else {
screen.tabBuffer = NewTabBufferFromFile(filename, screen, bounds)
}
// screen.tabBuffer.cursor.SetPos(0, bounds[0][1], screen.tabBuffer)
return screen, nil
}
// creates the debug area at the bottom of the screen
func (s *Screen) CreateDebugArea() {
style := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite)
sWidth, sHeight := s.tScreen.Size()
for y := sHeight - s.debugAreaHeight ; y < sHeight; y++ {
for x := 0; x < sWidth; x++ {
s.tScreen.SetContent(x, y, ' ', nil, style)
}
}
s.tScreen.Show()
}
func (s *Screen) WriteDebug(str string, y int) {
style := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite)
_, sHeight := s.tScreen.Size()
startingPoint := 5
for i, char := range str {
s.tScreen.SetContent(i, (sHeight-startingPoint)+y, char, nil, style)
}
s.tScreen.Show()
}
func (s *Screen) CreateFileInfoArea() {
style := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite)
sWidth, _ := s.tScreen.Size()
for y := 0; y < s.fileInfoAreaHeight; y++ {
for x := 0; x < sWidth; x++ {
s.tScreen.SetContent(x, y, ' ', nil, style)
}
}
s.tScreen.Show()
}
func (s *Screen) WriteFileName(str string, row int) {
style := tcell.StyleDefault.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite)
sWidth, _ := s.tScreen.Size()
lenStr := len(str)
for i, char := range str {
s.tScreen.SetContent(((sWidth/2)-lenStr/2)+i, row, char, nil, style)
}
s.tScreen.Show()
}