2024-01-18 00:08:37 -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 (
|
2024-02-06 20:45:08 -06:00
|
|
|
"syscall"
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-02-06 20:45:08 -06:00
|
|
|
// handle ctrl+z
|
|
|
|
func handle_ctrl_z(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
gocui.Suspend()
|
|
|
|
log.Info("got ctrl+z")
|
|
|
|
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
2024-11-14 10:05:43 -06:00
|
|
|
log.Info("got ctrl+z syscall() done")
|
2024-02-06 20:45:08 -06:00
|
|
|
gocui.Resume()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
func defaultKeybindings(g *gocui.Gui) error {
|
|
|
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-02-06 20:45:08 -06:00
|
|
|
// setup ctrl+z
|
|
|
|
keyForced, modForced := gocui.MustParse("ctrl+z")
|
|
|
|
if err := g.SetKeybinding("", keyForced, modForced, handle_ctrl_z); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
for _, n := range []string{"but1", "but2", "help", "but3"} {
|
|
|
|
if err := g.SetKeybinding(n, gocui.MouseLeft, gocui.ModNone, showMsg); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding("", gocui.MouseRelease, gocui.ModNone, mouseUp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// mouseDown() runs whenever you click on an unknown view (?)
|
|
|
|
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, mouseDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModMouseCtrl, ctrlDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// if err := g.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click); err != nil {
|
|
|
|
// return err
|
|
|
|
// }
|
|
|
|
/*
|
|
|
|
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if err := g.SetKeybinding("msg", gocui.MouseLeft, gocui.ModNone, msgDown); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
addDebugKeys(g)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func addDebugKeys(g *gocui.Gui) {
|
|
|
|
// show debugging buttons
|
|
|
|
g.SetKeybinding("", 'd', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
fakeStartWidth = me.FakeW
|
|
|
|
fakeStartHeight = me.TabH + me.FramePadH
|
|
|
|
if showDebug {
|
2024-01-29 23:39:33 -06:00
|
|
|
showFake()
|
2024-01-18 00:08:37 -06:00
|
|
|
showDebug = false
|
|
|
|
} else {
|
2024-01-29 23:39:33 -06:00
|
|
|
hideFake()
|
2024-01-18 00:08:37 -06:00
|
|
|
showDebug = true
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// display the help menu
|
|
|
|
g.SetKeybinding("", '?', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if showHelp {
|
|
|
|
helplayout()
|
|
|
|
showHelp = false
|
2024-02-03 19:28:19 -06:00
|
|
|
if me.dropdownV == nil {
|
|
|
|
me.dropdownV = makeDropdownView("addWidget() ddview")
|
|
|
|
}
|
|
|
|
me.dropdownV.Show()
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
|
|
|
me.baseGui.DeleteView("help")
|
|
|
|
showHelp = true
|
2024-02-03 19:28:19 -06:00
|
|
|
me.dropdownV.Hide()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// redraw all the widgets
|
|
|
|
g.SetKeybinding("", 'r', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = me.treeRoot.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
if redoWidgets {
|
2024-01-29 23:01:39 -06:00
|
|
|
wRoot := me.treeRoot.TK.(*guiWidget)
|
|
|
|
wRoot.redoWindows(0, 0)
|
2024-01-18 00:08:37 -06:00
|
|
|
redoWidgets = false
|
|
|
|
} else {
|
2024-01-28 02:20:31 -06:00
|
|
|
w.hideWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
redoWidgets = true
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// hide all widgets
|
|
|
|
g.SetKeybinding("", 'h', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = me.treeRoot.TK.(*guiWidget)
|
|
|
|
w.hideWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// show all widgets
|
|
|
|
g.SetKeybinding("", 's', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = me.treeRoot.TK.(*guiWidget)
|
|
|
|
w.showWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// list all widgets
|
|
|
|
g.SetKeybinding("", 'L', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-28 02:20:31 -06:00
|
|
|
me.treeRoot.ListWidgets()
|
2024-11-13 21:32:44 -06:00
|
|
|
|
2024-11-14 03:50:59 -06:00
|
|
|
tk := me.logStdout.TK.(*guiWidget)
|
2024-11-14 10:05:43 -06:00
|
|
|
// msg := fmt.Sprintf("test out kb %d\n", ecount)
|
|
|
|
// tk.Write([]byte(msg))
|
2024-11-14 03:50:59 -06:00
|
|
|
if tk == nil {
|
|
|
|
log.Log(ERROR, "tk = nil")
|
|
|
|
}
|
|
|
|
if tk.v == nil {
|
|
|
|
log.Log(ERROR, "tk.v = nil")
|
2024-11-14 04:59:09 -06:00
|
|
|
} else {
|
2024-11-14 10:05:43 -06:00
|
|
|
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
|
|
|
|
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
|
|
|
|
log.CaptureMode(tk)
|
2024-11-14 04:28:12 -06:00
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// list all widgets with positions
|
|
|
|
g.SetKeybinding("", 'M', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-28 11:44:36 -06:00
|
|
|
w := me.treeRoot.TK.(*guiWidget)
|
2024-01-28 14:03:06 -06:00
|
|
|
w.dumpTree("M")
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// redo windows
|
|
|
|
g.SetKeybinding("", 'w', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-29 23:01:39 -06:00
|
|
|
wRoot := me.treeRoot.TK.(*guiWidget)
|
|
|
|
wRoot.redoWindows(0, 0)
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// log to output window
|
|
|
|
g.SetKeybinding("", 'o', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-11-14 03:50:59 -06:00
|
|
|
log.Log(ERROR, "TODO: trying re-implement this")
|
|
|
|
tk := me.logStdout.TK.(*guiWidget)
|
|
|
|
if tk == nil {
|
|
|
|
log.Log(ERROR, "tk = nil")
|
|
|
|
}
|
|
|
|
if tk.v == nil {
|
|
|
|
log.Log(ERROR, "tk.v = nil")
|
|
|
|
}
|
|
|
|
if tk.Visible() {
|
|
|
|
log.Log(ERROR, "setting visible to false")
|
|
|
|
tk.SetVisible(false)
|
|
|
|
// setOutput(os.Stdout)
|
|
|
|
} else {
|
|
|
|
log.Log(ERROR, "setting visible to true")
|
|
|
|
tk.SetVisible(true)
|
|
|
|
// setOutput(me.logStdout.tk)
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// exit
|
|
|
|
g.SetKeybinding("", 'q', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
standardExit()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
standardExit()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if showDebug {
|
2024-01-28 02:20:31 -06:00
|
|
|
me.myTree.SendEnableDebugger()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// panic
|
|
|
|
g.SetKeybinding("", 'p', gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
2024-01-30 11:54:57 -06:00
|
|
|
standardClose()
|
2024-01-18 00:08:37 -06:00
|
|
|
panic("forced panic in gocui")
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|