130 lines
3.2 KiB
Go
130 lines
3.2 KiB
Go
|
// Copyright 2014 The gocui Authors. All rights reserved.
|
||
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||
|
// Use of this source code is governed by the GPL 3.0
|
||
|
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
|
||
|
"github.com/awesome-gocui/gocui"
|
||
|
log "go.wit.com/log"
|
||
|
"go.wit.com/toolkits/tree"
|
||
|
"go.wit.com/widget"
|
||
|
)
|
||
|
|
||
|
// create a new widget in the binary tree
|
||
|
func makeNewInternalWidget(wId int) *guiWidget {
|
||
|
if me.treeRoot == nil {
|
||
|
log.Info("GOGUI Init ERROR. treeRoot == nil")
|
||
|
return nil
|
||
|
}
|
||
|
n := new(tree.Node)
|
||
|
n.WidgetType = widget.Flag
|
||
|
n.WidgetId = wId
|
||
|
n.ParentId = 0
|
||
|
|
||
|
// store the internal toolkit information
|
||
|
tk := new(guiWidget)
|
||
|
tk.frame = true
|
||
|
|
||
|
tk.node = n
|
||
|
tk.node.Parent = me.treeRoot
|
||
|
|
||
|
// set the name used by gocui to the id
|
||
|
tk.cuiName = fmt.Sprintf("%d DR", wId)
|
||
|
|
||
|
tk.setColorInput()
|
||
|
|
||
|
// add this new widget on the binary tree
|
||
|
tk.parent = me.treeRoot.TK.(*guiWidget)
|
||
|
if tk.parent == nil {
|
||
|
panic("makeNewFlagWidget() didn't get treeRoot guiWidget")
|
||
|
} else {
|
||
|
tk.parent.children = append(tk.parent.children, tk)
|
||
|
}
|
||
|
|
||
|
n.TK = tk
|
||
|
return tk
|
||
|
}
|
||
|
|
||
|
func makeClock(wId int) {
|
||
|
if me.treeRoot == nil {
|
||
|
log.Info("gogui makeClock() error. treeRoot == nil")
|
||
|
return
|
||
|
}
|
||
|
me.notify.clock.tk = makeNewInternalWidget(wId)
|
||
|
me.notify.clock.tk.dumpWidget("init() clock")
|
||
|
w, h := me.baseGui.MousePosition()
|
||
|
me.notify.clock.tk.MoveToOffset(w, h)
|
||
|
me.notify.clock.tk.labelN = time.Now().Format("15:04:05")
|
||
|
me.notify.clock.tk.frame = false
|
||
|
me.notify.clock.tk.setColorLabel()
|
||
|
me.notify.clock.tk.Show()
|
||
|
me.notify.clock.active = true
|
||
|
me.notify.clock.tk.dumpWidget("showClock()")
|
||
|
}
|
||
|
|
||
|
// in the very end of redrawing things, this will place the help and stdout on the top or botton
|
||
|
// depending on the state the user has chosen
|
||
|
func setThingsOnTop() {
|
||
|
if me.showHelp { // terrible variable name. FIXME
|
||
|
// log.Info("help does not exist")
|
||
|
} else {
|
||
|
me.baseGui.SetViewOnTop("help")
|
||
|
}
|
||
|
if me.notify.clock.tk != nil {
|
||
|
me.baseGui.SetViewOnTop(me.notify.clock.tk.v.Name())
|
||
|
}
|
||
|
|
||
|
if me.stdout.tk == nil {
|
||
|
makeOutputWidget(me.baseGui, "from setThingsOnTop()")
|
||
|
}
|
||
|
if me.stdout.tk == nil {
|
||
|
return
|
||
|
}
|
||
|
if me.stdout.tk.v == nil {
|
||
|
return
|
||
|
}
|
||
|
if me.dark {
|
||
|
me.stdout.tk.v.FgColor = gocui.ColorWhite
|
||
|
me.stdout.tk.v.BgColor = gocui.ColorBlack
|
||
|
} else {
|
||
|
me.stdout.tk.v.FgColor = gocui.ColorBlack
|
||
|
me.stdout.tk.v.BgColor = gocui.AttrNone
|
||
|
}
|
||
|
|
||
|
if me.stdout.outputOnTop {
|
||
|
me.baseGui.SetViewOnTop("msg")
|
||
|
} else {
|
||
|
me.baseGui.SetViewOnBottom("msg")
|
||
|
}
|
||
|
if me.stdout.startOnscreen {
|
||
|
// log.Info("THIS TRIGGERS STDOUT") // todo: make a proper init() & move this there
|
||
|
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
||
|
me.stdout.startOnscreen = false
|
||
|
}
|
||
|
setBottomBG()
|
||
|
}
|
||
|
|
||
|
func setBottomBG() {
|
||
|
// this attempts to find the "BG" widget and set it to the background on the very very bottom
|
||
|
rootTK := me.treeRoot.TK.(*guiWidget)
|
||
|
if tk := rootTK.findBG(); tk != nil {
|
||
|
// log.Info("found BG. setting to bottom", tk.cuiName)
|
||
|
if me.dark {
|
||
|
tk.v.BgColor = gocui.ColorBlack
|
||
|
} else {
|
||
|
tk.v.BgColor = gocui.ColorWhite
|
||
|
}
|
||
|
tk.v.Clear()
|
||
|
me.baseGui.SetViewOnBottom(tk.cuiName)
|
||
|
w, h := me.baseGui.Size()
|
||
|
me.baseGui.SetView(tk.cuiName, -1, -1, w+1, h+1, 0)
|
||
|
}
|
||
|
}
|