summaryrefslogtreecommitdiff
path: root/color.go
blob: 5b570353a3a3352450561dc44b444634c1ad8244 (plain)
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

// information about how terminfo works
// https://jvns.ca/blog/2024/10/01/terminal-colours/

import (
	"math/rand"

	"github.com/gdamore/tcell/v2"

	"github.com/awesome-gocui/gocui"

	"go.wit.com/log"
)

//w.v.SelBgColor = gocui.ColorCyan
//color.go:       w.v.SelFgColor = gocui.ColorBlack
//color.go:               w.v.BgColor = gocui.ColorGreen

var none gocui.Attribute = gocui.AttrNone
var lightPurple gocui.Attribute = gocui.GetColor("#DDDDDD")    // light purple
var darkPurple gocui.Attribute = gocui.GetColor("#FFAA55")     // Dark Purple
var heavyPurple gocui.Attribute = gocui.GetColor("#88AA55")    // heavy purple
var powdererBlue gocui.Attribute = gocui.GetColor("#B0E0E6")   // w3c 'powerder blue'
var superLightGrey gocui.Attribute = gocui.GetColor("#55AAFF") // super light grey

// Standard defined colors from gocui:
// ColorBlack ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite

// v.BgColor = gocui.GetColor("#111111") // crazy red
// v.BgColor = gocui.GetColor("#FF9911") // heavy red
// v.SelBgColor = gocui.GetColor("#FFEE11") // blood red

// v.BgColor = gocui.GetColor("#55AAFF") // super light grey
// v.BgColor = gocui.GetColor("#FFC0CB") // 'w3c pink' yellow

//	Normal Text                             On mouseover
//
// Widget Frame         Text              background              Text           background
var colorWindow colorT = colorT{
	frame: none,
	fg:    gocui.ColorBlue,
	bg:    none,
	selFg: gocui.ColorWhite,
	// selBg: powdererBlue,
	selBg: gocui.ColorBlue,
	name:  "normal window",
}

var colorActiveW colorT = colorT{
	frame: none,
	fg:    gocui.ColorWhite,
	bg:    gocui.ColorBlue,
	selFg: gocui.ColorBlue,
	selBg: none,
	name:  "normal window",
}

// var colorActiveW colorT = colorT{none, none, powdererBlue, none, powdererBlue, "active window"} // sets the window to blue

var colorTab colorT = colorT{gocui.ColorBlue, gocui.ColorBlue, none, none, powdererBlue, "normal tab"}
var colorActiveT colorT = colorT{gocui.ColorBlue, none, powdererBlue, none, powdererBlue, "active tab"}

// var colorLabel colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal label"}
// var colorGroup colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal group"}

var colorDisabled colorT = colorT{
	frame: superLightGrey,
	fg:    superLightGrey,
	bg:    superLightGrey,
	selFg: gocui.ColorBlack,
	selBg: gocui.ColorBlack,
	name:  "disabled widget",
}

var colorLabel colorT = colorT{
	frame: gocui.ColorWhite,
	fg:    none,
	bg:    none,
	selFg: none,
	selBg: none,
	name:  "normal label",
}

var colorGroup colorT = colorT{
	frame: none,
	fg:    none,
	bg:    none,
	selFg: gocui.ColorWhite,
	selBg: none,
	name:  "normal label",
}

var colorButton colorT = colorT{
	frame: gocui.ColorGreen,
	fg:    none,
	bg:    none,
	selFg: gocui.ColorGreen,
	selBg: none,
	name:  "normal button",
}

var colorButtonDense colorT = colorT{
	frame: none,
	fg:    none,
	bg:    gocui.ColorGreen,
	// bg:    tcell.ColorGreen,
	selFg: none,
	selBg: gocui.ColorWhite,
	name:  "normal button",
}

var colorDropdown colorT = colorT{
	frame: gocui.ColorYellow,
	fg:    none,
	bg:    none,
	selFg: gocui.ColorYellow,
	selBg: gocui.ColorBlack,
	name:  "normal dropdown",
}

var colorCombobox colorT = colorT{
	frame: gocui.ColorBlue,
	fg:    none,
	bg:    none,
	selFg: gocui.ColorBlue,
	selBg: gocui.ColorBlack,
	name:  "normal combobox",
}

var colorCheckbox colorT = colorT{
	frame: gocui.ColorRed,
	fg:    none,
	bg:    none,
	selFg: gocui.ColorRed,
	selBg: gocui.ColorWhite,
	name:  "normal checkbox",
}

// widget debugging colors. these widgets aren't displayed unless you are debugging
var colorRoot colorT = colorT{gocui.ColorRed, none, powdererBlue, none, gocui.ColorBlue, "debug root"}
var colorFlag colorT = colorT{gocui.ColorRed, none, powdererBlue, none, gocui.ColorGreen, "debug flag"}
var colorBox colorT = colorT{gocui.ColorRed, none, lightPurple, none, gocui.ColorCyan, "debug box"}
var colorGrid colorT = colorT{gocui.ColorRed, none, lightPurple, none, gocui.ColorRed, "debug grid"}
var colorNone colorT = colorT{none, none, none, none, none, "debug none"}

// actually sets the colors for the gocui element
// the user will see the colors change when this runs
// TODO: add black/white only flag for ttyS0
// TODO: or fix kvm/qemu serial console & SIGWINCH.
// TODO: and minicom and uboot and 5 million other things.
// TODO: maybe enough of us could actually do that if we made it a goal.
// TODO: start with riscv boards and fix it universally there
// TODO: so just a small little 'todo' item here
func (tk *guiWidget) setColor(newColor *colorT) {
	if tk.color == newColor {
		// nothing to do since the colors have nto changed
		return
	}
	tk.color = newColor
	if tk.v == nil {
		return
	}
	if tk.color == nil {
		// log.Log(NOW, "Set the node to color = nil")
		tk.color = &colorNone
	}
	// log.Log(NOW, "Set the node to color =", tk.color.name)
	tk.Show()
}

func (w *guiWidget) disableColor() {
	if w.color != &colorDisabled {
		w.defaultColor = w.color
	}
	w.setColor(&colorDisabled)
}

func (w *guiWidget) enableColor() {
	w.setColor(w.defaultColor)
}

func (w *guiWidget) setDefaultHighlight() {
	if w.v == nil {
		log.Log(ERROR, "SetColor() failed on view == nil")
		return
	}
	w.v.SelBgColor = gocui.ColorGreen
	w.v.SelFgColor = gocui.ColorBlack
}

func randColor() gocui.Attribute {
	colors := []string{"Green", "#FFAA55", "Yellow", "Blue", "Red", "Black", "White"}
	i := rand.Intn(len(colors))
	log.Log(NOW, "randColor() i =", i)
	return gocui.GetColor(colors[i])
}

func (w *guiWidget) redoColor(draw bool) {
	if w == nil {
		return
	}

	log.Sleep(.05)
	w.setDefaultHighlight()
	// w.setDefaultWidgetColor()
	w.Show()

	for _, child := range w.children {
		child.redoColor(draw)
	}
}

// what genius figured this out?
// originally from github.com/dimasma0305/GoFetch
func get_teminal_color_palette() string {
	// var runes rune
	// color1 := "\x1b[0;29m  \x1b[0m"
	// runes = []rune(color1)
	// view.WriteRunes(runes)

	color1 := "\x1b[0;29m  \x1b[0m"
	color2 := "\x1b[0;31m  \x1b[0m"
	color3 := "\x1b[0;32m  \x1b[0m"
	color4 := "\x1b[0;33m  \x1b[0m"
	color5 := "\x1b[0;34m  \x1b[0m"
	color6 := "\x1b[0;35m  \x1b[0m"
	color7 := "\x1b[0;36m  \x1b[0m"
	color8 := "\x1b[0;37m  \x1b[0m"

	return color1 + " " + color2 + " " + color3 + " " + color4 + " " + color5 + " " + color6 + " " + color7 + " " + color8
}

func (tk *guiWidget) SetColorRed() {
	tk.color = new(colorT)
	tk.color.fg = gocui.ColorRed
}

func (tk *guiWidget) setColorBlue() {
	// r, g, b :=
	// newgreen := gocui.NewRGBColor(tcell.ColorLightBlue.RGB())

	// tk.color.fg = gocui.ColorBlue
	tk.color.bg = gocui.NewRGBColor(tcell.ColorLightBlue.RGB())
}

// weird. lots of color problems for me on debian sid using the traditional Andy Herzfield 'gnome'
func (tk *guiWidget) setColorButtonDenseOLD() {
	/*
		cellgreen := tcell.ColorLightGreen
		r, g, b := cellgreen.RGB()
		newgreen := gocui.NewRGBColor(r, g, b)
	*/

	// tk.color.fg = gocui.ColorBlue
	if tk.color == nil {
		tk.color = new(colorT)
	}
	lightGreen := gocui.GetColor("0x90EE90")
	lightGreen = gocui.GetColor("0x008000")
	lightGreen = gocui.NewRGBColor(0x00, 0x80, 0x00)

	tk.color.frame = gocui.ColorYellow
	tk.color.fg = gocui.AttrNone
	tk.color.bg = gocui.ColorGreen
	tk.color.bg = lightGreen
	tk.color.bg = gocui.Attribute(tcell.ColorLightGreen)
	tk.color.bg = superLightGrey
	// bg:    gocui.ColorGreen,
	tk.color.selFg = gocui.AttrNone
	tk.color.selBg = gocui.ColorGreen

	// tk.color = &colorButtonDense

	/*
		tk.color.selFg = gocui.AttrNone
		r, g, b := tcell.ColorLightGreen.RGB()
		log.Info("color =", tcell.ColorLightGreen.CSS(), r, g, b)
		tk.color.selBg = gocui.NewRGBColor(r, g, b)
	*/
}