This repository has been archived by the owner on Aug 8, 2021. It is now read-only.
forked from Bios-Marcel/cordless
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
199 lines (158 loc) · 3.86 KB
/
main.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package main
import (
tcell "github.com/gdamore/tcell/v2"
tview "github.com/gord-project/gview"
)
func main() {
app := tview.NewApplication()
err := app.Run()
if err != nil {
panic(err)
}
}
// CoreLayout implements tview.Primitive and represents the core component layout
// of the application, handling not only the layouting, but also the borders.
type CoreLayout struct {
visible bool
x, y int
width, height int
dm tview.Primitive
servers tview.Primitive
channels tview.Primitive
messages tview.Primitive
input tview.Primitive
terminal tview.Primitive
userList tview.Primitive
}
func NewCoreLayout() *CoreLayout {
return &CoreLayout{
visible: true,
dm: NewDemoComponent('d'),
servers: NewDemoComponent('s'),
channels: NewDemoComponent('c'),
messages: NewDemoComponent('m'),
input: NewDemoComponent('i'),
terminal: NewDemoComponent('t'),
userList: NewDemoComponent('u'),
}
}
func (c *CoreLayout) Draw(screen tcell.Screen) bool {
return true
}
func (c *CoreLayout) SetVisible(visible bool) {
c.visible = visible
}
func (c *CoreLayout) IsVisible() bool {
return c.visible
}
func (c *CoreLayout) GetRect() (int, int, int, int) {
return c.x, c.y, c.width, c.height
}
func (c *CoreLayout) SetRect(x, y, width, height int) {
c.x = x
c.y = y
c.width = width
c.height = height
}
func (c *CoreLayout) InputHandler() tview.InputHandlerFunc {
panic("implement me")
}
func (c *CoreLayout) Focus(delegate func(p tview.Primitive)) {
panic("implement me")
}
func (c *CoreLayout) Blur() {
panic("implement me")
}
func (c *CoreLayout) SetOnFocus(handler func()) {
panic("implement me")
}
func (c *CoreLayout) SetOnBlur(handler func()) {
panic("implement me")
}
func (c *CoreLayout) GetFocusable() tview.Focusable {
panic("implement me")
}
func (c *CoreLayout) NextFocusableComponent(direction tview.FocusDirection) tview.Primitive {
panic("implement me")
}
func (c *CoreLayout) OnPaste(runes []rune) {
panic("implement me")
}
func (c *CoreLayout) SetParent(parent tview.Primitive) {
//Do nothing
}
func (c *CoreLayout) GetParent() tview.Primitive {
return nil
}
func NewDemoComponent(r rune) *demoComponent {
return &demoComponent{visible: true, fillWith: r}
}
type demoComponent struct {
visible bool
x, y int
width, height int
fillWith rune
}
func genRuneArray(r rune, length int) []rune {
array := make([]rune, length, length)
for i := 0; i < length; i++ {
array[i] = r
}
return array
}
func (d *demoComponent) Draw(screen tcell.Screen) bool {
if !d.visible {
return false
}
for h := 0; h < d.height; h++ {
screen.SetCell(d.x, d.y+h, tcell.StyleDefault, genRuneArray(d.fillWith, d.width)...)
}
return true
}
func (d *demoComponent) SetVisible(visible bool) {
d.visible = visible
}
func (d *demoComponent) IsVisible() bool {
return d.visible
}
func (d *demoComponent) GetRect() (int, int, int, int) {
return d.x, d.y, d.width, d.height
}
func (d *demoComponent) SetRect(x, y, width, height int) {
d.x = x
d.y = y
d.width = width
d.height = height
}
func (d *demoComponent) InputHandler() tview.InputHandlerFunc {
return func(event *tcell.EventKey, setFocus func(p tview.Primitive)) *tcell.EventKey {
return event
}
}
func (d *demoComponent) Focus(delegate func(p tview.Primitive)) {
//Do nothing
}
func (d *demoComponent) Blur() {
//Do nothing
}
func (d *demoComponent) SetOnFocus(handler func()) {
//Do nothing
}
func (d *demoComponent) SetOnBlur(handler func()) {
//Do nothing
}
func (d *demoComponent) GetFocusable() tview.Focusable {
return nil
}
func (d *demoComponent) NextFocusableComponent(direction tview.FocusDirection) tview.Primitive {
return nil
}
func (d *demoComponent) OnPaste(runes []rune) {
panic("implement me")
}
func (d *demoComponent) SetParent(parent tview.Primitive) {
//Do nothing
}
func (d *demoComponent) GetParent() tview.Primitive {
return nil
}