gocui/help.go

117 lines
2.6 KiB
Go
Raw Normal View History

// Copyright 2014 The gocui Authors. All rights reserved.
2025-02-01 11:42:31 -06:00
// 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 (
"errors"
"fmt"
"strings"
"github.com/awesome-gocui/gocui"
2025-02-01 19:00:15 -06:00
log "go.wit.com/log"
)
2025-01-31 16:05:34 -06:00
/*
This in helpText doesn't print
"\x1b[0;32m  \x1b[0m", // this was a test to see what might be
// possible with gocui. it doesn't seem to work for me
*/
2025-02-06 04:15:36 -06:00
var helpText []string = []string{"Help Menu",
"",
2025-02-06 02:15:21 -06:00
"H: toggle (H)elp",
"O: toggle (O)output (os.STDOUT)",
2025-01-31 16:05:34 -06:00
"S: super mouse",
"M: list all widgets positions",
2025-02-06 04:15:36 -06:00
"L: list all widgets in tree",
2025-02-06 07:01:27 -06:00
"Tab: toggle through windows",
"q: quit()",
"",
}
2025-02-01 19:00:15 -06:00
func hideHelp() {
if me.showHelp {
log.Info("help is already down")
me.showHelp = true
return
}
me.showHelp = true
me.baseGui.DeleteView("help")
}
2025-02-01 19:00:15 -06:00
func showHelp() error {
if !me.showHelp {
log.Info("help is already up")
me.showHelp = false
return nil
}
me.showHelp = false
g := me.baseGui
var err error
maxX, _ := g.Size()
var newW int = 8
for _, s := range helpText {
if newW < len(s) {
newW = len(s)
}
}
help, err := g.SetView("help", maxX-(newW+me.FramePadW), 0, maxX-1, len(helpText)+me.FramePadH, 0)
if err != nil {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
help.SelBgColor = gocui.ColorGreen
help.SelFgColor = gocui.ColorBlack
// fmt.Fprintln(help, "Enter: Click Button")
// fmt.Fprintln(help, "Tab/Space: Switch Buttons")
// fmt.Fprintln(help, "Backspace: Delete Button")
// fmt.Fprintln(help, "Arrow keys: Move Button")
fmt.Fprintln(help, strings.Join(helpText, "\n"))
if _, err := g.SetCurrentView("help"); err != nil {
return err
}
}
g.SetViewOnTop("help")
me.helpLabel = help
return nil
}
2025-02-06 02:15:21 -06:00
// 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")
}
2025-02-06 02:15:21 -06:00
2025-02-06 02:40:44 -06:00
if me.stdout.outputOnTop {
2025-02-06 02:15:21 -06:00
me.baseGui.SetViewOnTop("msg")
} else {
me.baseGui.SetViewOnBottom("msg")
}
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)
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)
}
}