2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
//w.v.SelBgColor = gocui.ColorCyan
|
|
|
|
//color.go: w.v.SelFgColor = gocui.ColorBlack
|
|
|
|
//color.go: w.v.BgColor = gocui.ColorGreen
|
|
|
|
|
|
|
|
type colorT struct {
|
|
|
|
frame gocui.Attribute
|
|
|
|
fg gocui.Attribute
|
|
|
|
bg gocui.Attribute
|
|
|
|
selFg gocui.Attribute
|
|
|
|
selBg gocui.Attribute
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2024-01-30 03:17:15 -06:00
|
|
|
var colorWindow colorT = colorT{
|
2024-01-30 02:38:06 -06:00
|
|
|
frame: none,
|
2024-01-30 03:17:15 -06:00
|
|
|
fg: gocui.ColorBlue,
|
|
|
|
bg: none,
|
2024-01-30 02:38:06 -06:00
|
|
|
selFg: none,
|
|
|
|
selBg: powdererBlue,
|
2024-01-30 03:17:15 -06:00
|
|
|
name: "normal window",
|
2024-01-30 02:38:06 -06:00
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
var colorActiveW colorT = colorT{none, none, powdererBlue, none, powdererBlue, "active window"}
|
|
|
|
|
|
|
|
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"}
|
|
|
|
|
2024-01-30 03:17:15 -06:00
|
|
|
var colorDisabled colorT = colorT{
|
2024-01-30 02:38:06 -06:00
|
|
|
frame: superLightGrey,
|
2024-01-30 03:17:15 -06:00
|
|
|
fg: superLightGrey,
|
|
|
|
bg: superLightGrey,
|
2024-01-30 02:38:06 -06:00
|
|
|
selFg: gocui.ColorBlack,
|
|
|
|
selBg: gocui.ColorBlack,
|
2024-01-30 03:17:15 -06:00
|
|
|
name: "disabled widget",
|
2024-01-30 02:38:06 -06:00
|
|
|
}
|
|
|
|
|
2024-02-01 11:37:46 -06:00
|
|
|
var colorButton colorT = colorT{
|
|
|
|
frame: gocui.ColorGreen,
|
|
|
|
fg: none,
|
|
|
|
bg: gocui.ColorWhite,
|
|
|
|
selFg: gocui.ColorGreen,
|
|
|
|
selBg: gocui.ColorBlack,
|
|
|
|
name: "normal button",
|
|
|
|
}
|
|
|
|
|
2024-02-01 18:28:59 -06:00
|
|
|
var colorDropdown colorT = colorT{
|
|
|
|
frame: gocui.ColorYellow,
|
|
|
|
fg: none,
|
|
|
|
bg: gocui.ColorWhite,
|
|
|
|
selFg: gocui.ColorYellow,
|
|
|
|
selBg: gocui.ColorBlack,
|
|
|
|
name: "normal button",
|
|
|
|
}
|
|
|
|
|
|
|
|
var colorCombobox colorT = colorT{
|
|
|
|
frame: gocui.ColorBlue,
|
|
|
|
fg: none,
|
|
|
|
bg: gocui.ColorWhite,
|
|
|
|
selFg: gocui.ColorBlue,
|
|
|
|
selBg: gocui.ColorBlack,
|
|
|
|
name: "normal button",
|
|
|
|
}
|
|
|
|
|
2024-02-01 11:37:46 -06:00
|
|
|
var colorCheckbox colorT = colorT{
|
|
|
|
frame: gocui.ColorRed,
|
|
|
|
fg: none,
|
|
|
|
bg: gocui.ColorWhite,
|
2024-02-01 18:28:59 -06:00
|
|
|
selFg: gocui.ColorRed,
|
2024-02-01 11:37:46 -06:00
|
|
|
selBg: gocui.ColorBlack,
|
|
|
|
name: "normal checkbox",
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
// 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
|
2024-01-28 11:07:51 -06:00
|
|
|
func (tk *guiWidget) setColor(newColor *colorT) {
|
2024-01-18 00:08:37 -06:00
|
|
|
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)
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.recreateView()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-30 02:38:06 -06:00
|
|
|
func (w *guiWidget) disableColor() {
|
|
|
|
if w.color != &colorDisabled {
|
|
|
|
w.defaultColor = w.color
|
|
|
|
}
|
|
|
|
w.setColor(&colorDisabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *guiWidget) enableColor() {
|
|
|
|
w.setColor(w.defaultColor)
|
|
|
|
}
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) setDefaultWidgetColor() {
|
2024-01-28 02:20:31 -06:00
|
|
|
w.showView()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) setDefaultHighlight() {
|
2024-01-18 00:08:37 -06:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) redoColor(draw bool) {
|
2024-01-18 00:08:37 -06:00
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Sleep(.05)
|
2024-01-28 11:07:51 -06:00
|
|
|
w.setDefaultHighlight()
|
|
|
|
w.setDefaultWidgetColor()
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
2024-01-18 00:08:37 -06:00
|
|
|
child.redoColor(draw)
|
|
|
|
}
|
|
|
|
}
|