-
Notifications
You must be signed in to change notification settings - Fork 3
/
inputScreen.go
94 lines (77 loc) · 2 KB
/
inputScreen.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
package main
import (
ui "github.com/gizak/termui"
)
type InputScreen struct {
prompt string
input *ui.Par
stats *pairStats
}
func NewInputScreen(prompt string) *InputScreen {
in := ui.NewPar("")
in.Border = true
in.X = 20
in.Y = 13
in.Height = 3
in.Width = 60
in.BorderLabel = prompt
return &InputScreen{prompt: prompt, input: in}
}
func (i *InputScreen) Buffers() []ui.Bufferer {
bufs := []ui.Bufferer{i.input}
bufs = append(bufs, i.stats.Buffers()...)
return bufs
}
func (i *InputScreen) Handle(e string) {
Log.Println(e)
// All the keys that could be used to "undo" - as of right now github.com/gizak/termui is not
// working correctly and backspaces are coming through as "C-8>" - when this is fixed/PR'ed
// these conditions as well as what we allow through anyKey in main, can be updated.
if e == "<Backspace>" || e == "<Delete>" || e == "C-8>" {
if len(i.input.Text) > 0 {
i.input.Text = i.input.Text[:len(i.input.Text)-1]
}
return
}
if len(e) >= 4 {
return
}
// append the character to the text
i.input.Text += e
}
func (i *InputScreen) Text() string {
return i.input.Text
}
type LoadingScreen struct {
load *ui.Par
}
func NewLoadingScreen(text string) *LoadingScreen {
load := ui.NewPar(text)
load.X = DefaultLoadingConfig.X + 10
load.Y = DefaultLoadingConfig.Y
load.Width = DefaultLoadingConfig.Width
load.Height = DefaultLoadingConfig.Height
load.TextFgColor = ui.ColorYellow
load.BorderFg = ui.ColorRed
return &LoadingScreen{load: load}
}
func (l *LoadingScreen) Buffers() []ui.Bufferer {
return []ui.Bufferer{l.load}
}
type ErrorScreen struct {
err *ui.Par
}
func NewErrorScreen(text string) *ErrorScreen {
err := ui.NewPar(text)
err.X = DefaultLoadingConfig.X - 15
err.Y = DefaultLoadingConfig.Y
err.Width = len(text) + 4
err.Height = DefaultLoadingConfig.Height
err.TextFgColor = ui.ColorYellow
err.BorderFg = ui.ColorRed
err.BorderLabel = "Error"
return &ErrorScreen{err: err}
}
func (e *ErrorScreen) Buffers() []ui.Bufferer {
return []ui.Bufferer{e.err}
}