2022-11-06 12:59:24 -06:00
|
|
|
// Copyright 2014 The gocui Authors. All rights reserved.
|
|
|
|
// 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"
|
2022-11-13 08:53:03 -06:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2022-11-06 12:59:24 -06:00
|
|
|
|
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
)
|
|
|
|
|
|
|
|
const delta = 1
|
|
|
|
|
|
|
|
var (
|
|
|
|
views = []string{}
|
|
|
|
curView = -1
|
|
|
|
idxView = 0
|
|
|
|
currentX = 5
|
|
|
|
currentY = 2
|
|
|
|
groupSize = 0
|
|
|
|
baseGui *gocui.Gui
|
2022-11-13 08:53:03 -06:00
|
|
|
helpLabel *gocui.View
|
|
|
|
err error
|
|
|
|
ch chan(func ())
|
2022-11-14 14:30:28 -06:00
|
|
|
outf *os.File
|
2022-11-06 12:59:24 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func Init() {
|
2022-11-13 08:53:03 -06:00
|
|
|
baseGui, err = gocui.NewGui(gocui.OutputNormal, true)
|
2022-11-06 12:59:24 -06:00
|
|
|
if err != nil {
|
2023-03-12 08:47:16 -05:00
|
|
|
exit(err)
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
baseGui.Highlight = true
|
|
|
|
baseGui.SelFgColor = gocui.ColorRed
|
|
|
|
baseGui.SelFrameColor = gocui.ColorRed
|
2022-11-06 12:59:24 -06:00
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
baseGui.Cursor = true
|
|
|
|
baseGui.Mouse = true
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
baseGui.SetManagerFunc(layout)
|
2022-11-06 12:59:24 -06:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
if err := initKeybindings(baseGui); err != nil {
|
2023-03-12 08:47:16 -05:00
|
|
|
exit(err)
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
2022-11-06 19:57:20 -06:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
viewWidget = make(map[*gocui.View]*toolkit.Widget)
|
|
|
|
stringWidget = make(map[string]*toolkit.Widget)
|
2022-11-06 19:57:20 -06:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
ch = make(chan func())
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
outf, err = os.OpenFile("/tmp/witgui.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
|
|
|
|
if err != nil {
|
2023-03-12 08:47:16 -05:00
|
|
|
exit("error opening file: %v", err)
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
|
|
|
// hmm. where to put this?
|
|
|
|
// defer outf.Close()
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
setOutput(outf)
|
|
|
|
log("This is a test log entry")
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
2022-11-06 12:59:24 -06:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
func Queue(f func()) {
|
2023-03-12 08:47:16 -05:00
|
|
|
log("QUEUEEEEE")
|
2022-11-13 08:53:03 -06:00
|
|
|
f()
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
func Main(f func()) {
|
2022-11-14 14:30:28 -06:00
|
|
|
// close the STDOUT log file
|
|
|
|
defer outf.Close()
|
2022-11-13 08:53:03 -06:00
|
|
|
if (baseGui == nil) {
|
|
|
|
panic("WTF Main()")
|
|
|
|
}
|
|
|
|
defer baseGui.Close()
|
|
|
|
// log.Println("ADDDDDDDD BUTTTTTTTTTON")
|
|
|
|
// addButton("test 3")
|
|
|
|
f()
|
2022-11-06 12:59:24 -06:00
|
|
|
if err := baseGui.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
2023-03-12 08:47:16 -05:00
|
|
|
exit(err)
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
baseGui.Close()
|
|
|
|
os.Exit(0)
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func layout(g *gocui.Gui) error {
|
|
|
|
var err error
|
|
|
|
maxX, _ := g.Size()
|
2022-11-13 08:53:03 -06:00
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
helpLabel, err = g.SetView("help", maxX-32, 0, maxX-1, 12, 0)
|
2022-11-06 12:59:24 -06:00
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Fprintln(helpLabel, "KEYBINDINGS")
|
|
|
|
fmt.Fprintln(helpLabel, "Enter: Click Button")
|
|
|
|
fmt.Fprintln(helpLabel, "Tab/Space: Switch Buttons")
|
|
|
|
fmt.Fprintln(helpLabel, "")
|
|
|
|
fmt.Fprintln(helpLabel, "h: Help")
|
|
|
|
fmt.Fprintln(helpLabel, "Backspace: Delete Button")
|
|
|
|
fmt.Fprintln(helpLabel, "Arrow keys: Move Button")
|
|
|
|
fmt.Fprintln(helpLabel, "t: Move Button to the top")
|
|
|
|
fmt.Fprintln(helpLabel, "b: Move Button to the button")
|
2022-11-14 14:30:28 -06:00
|
|
|
fmt.Fprintln(helpLabel, "STDOUT: /tmp/witgui.log")
|
2022-11-06 12:59:24 -06:00
|
|
|
fmt.Fprintln(helpLabel, "Ctrl-C or Q: Exit")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|