gocui/help.go

105 lines
2.1 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-07 03:26:05 -06:00
"Tab: toggle through windows",
2025-02-23 23:15:31 -06:00
"O: toggle STDOUT",
"H: toggle this gocui menu",
"L: toggle light/dark mode",
2025-02-23 18:57:40 -06:00
"CTRL-c: quit()",
2025-02-07 03:26:05 -06:00
"",
"Debugging:",
2025-02-23 23:15:31 -06:00
"S: Supermouse mode",
"M: list all widget positions",
2025-02-06 04:15:36 -06:00
"L: list all widgets in tree",
}
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)
}
}
2025-03-03 22:21:39 -06:00
a := maxX - (newW + me.FramePadW)
b := me.notify.help.offsetH
c := maxX - 1
d := me.notify.help.offsetH + len(helpText) + me.FramePadH
help, err := g.SetView("help", a, b, c, d, 0)
if err != nil {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
help.SelBgColor = gocui.ColorGreen
help.SelFgColor = gocui.ColorBlack
fmt.Fprintln(help, strings.Join(helpText, "\n"))
if _, err := g.SetCurrentView("help"); err != nil {
return err
}
}
g.SetViewOnTop("help")
me.helpLabel = help
/*
if me.treeRoot == nil {
log.Info("gogui makeClock() error. treeRoot == nil")
return nil
} else {
if me.stdout.tk == nil {
makeOutputWidget(me.baseGui, "made this in showHelp()")
msg := fmt.Sprintf("test to stdout from in showHelp() %d\n", me.ecount)
me.stdout.Write([]byte(msg))
log.Log(NOW, "log.log(NOW) test")
}
}
*/
return nil
}