Repository navigation
Expand file tree
/
Copy pathtext_widget.go
More file actions
136 lines (105 loc) · 3.19 KB
/
Copy pathtext_widget.go
File metadata and controls
136 lines (105 loc) · 3.19 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
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
package wtf
import (
"fmt"
"github.com/olebedev/config"
"github.com/rivo/tview"
)
var Config *config.Config
type TextWidget struct {
enabled bool
focusable bool
focusChar string
Name string
RefreshInt int
View *tview.TextView
Position
}
func NewTextWidget(app *tview.Application, name string, configKey string, focusable bool) TextWidget {
focusCharValue := Config.UInt(fmt.Sprintf("wtf.mods.%s.focusChar", configKey), -1)
focusChar := string('0' + focusCharValue)
if focusCharValue == -1 {
focusChar = ""
}
widget := TextWidget{
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
focusable: focusable,
focusChar: focusChar,
Name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
}
widget.Position = NewPosition(
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)),
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)),
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)),
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)),
)
widget.addView(app, configKey)
return widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *TextWidget) BorderColor() string {
if widget.Focusable() {
return Config.UString("wtf.colors.border.focusable", "red")
}
return Config.UString("wtf.colors.border.normal", "gray")
}
func (widget *TextWidget) ContextualTitle(defaultStr string) string {
if widget.FocusChar() == "" {
return fmt.Sprintf(" %s ", defaultStr)
}
return fmt.Sprintf(" %s [darkgray::u]%s[::-][green] ", defaultStr, widget.FocusChar())
}
func (widget *TextWidget) Disable() {
widget.enabled = false
}
func (widget *TextWidget) Disabled() bool {
return !widget.Enabled()
}
func (widget *TextWidget) Enabled() bool {
return widget.enabled
}
func (widget *TextWidget) Focusable() bool {
return widget.enabled && widget.focusable
}
func (widget *TextWidget) FocusChar() string {
return widget.focusChar
}
func (widget *TextWidget) RefreshInterval() int {
return widget.RefreshInt
}
func (widget *TextWidget) SetFocusChar(char string) {
widget.focusChar = char
}
func (widget *TextWidget) TextView() *tview.TextView {
return widget.View
}
/* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) addView(app *tview.Application, configKey string) {
view := tview.NewTextView()
view.SetBackgroundColor(ColorFor(
Config.UString(fmt.Sprintf("wtf.mods.%s.colors.background", configKey),
Config.UString("wtf.colors.background", "black"),
),
))
view.SetTextColor(ColorFor(
Config.UString(
fmt.Sprintf("wtf.mods.%s.colors.text", configKey),
Config.UString("wtf.colors.text", "white"),
),
))
view.SetTitleColor(ColorFor(
Config.UString(
fmt.Sprintf("wtf.mods.%s.colors.title", configKey),
Config.UString("wtf.colors.title", "white"),
),
))
view.SetBorder(true)
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetChangedFunc(func() {
app.Draw()
})
view.SetDynamicColors(true)
view.SetTitle(widget.ContextualTitle(widget.Name))
view.SetWrap(false)
widget.View = view
}