// 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 ( "github.com/awesome-gocui/gocui" "go.wit.com/log" ) func defaultKeybindings(g *gocui.Gui) error { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { return err } 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 { showFake() showDebug = false } else { hideFake() 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 } else { me.baseGui.DeleteView("help") showHelp = true } return nil }) // redraw all the widgets g.SetKeybinding("", 'r', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { var w *guiWidget w = me.treeRoot.TK.(*guiWidget) if redoWidgets { wRoot := me.treeRoot.TK.(*guiWidget) wRoot.redoWindows(0, 0) redoWidgets = false } else { w.hideWidgets() redoWidgets = true } return nil }) // hide all widgets g.SetKeybinding("", 'h', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { var w *guiWidget w = me.treeRoot.TK.(*guiWidget) w.hideWidgets() return nil }) // show all widgets g.SetKeybinding("", 's', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { var w *guiWidget w = me.treeRoot.TK.(*guiWidget) w.showWidgets() return nil }) // list all widgets g.SetKeybinding("", 'L', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { me.treeRoot.ListWidgets() return nil }) // list all widgets with positions g.SetKeybinding("", 'M', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { w := me.treeRoot.TK.(*guiWidget) w.dumpTree("M") return nil }) // redo windows g.SetKeybinding("", 'w', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { wRoot := me.treeRoot.TK.(*guiWidget) wRoot.redoWindows(0, 0) return nil }) // log to output window g.SetKeybinding("", 'o', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { log.Log(ERROR, "TODO: re-implement this") /* if me.logStdout.Visible() { me.logStdout.SetVisible(false) // setOutput(os.Stdout) } else { me.logStdout.SetVisible(true) // setOutput(me.logStdout.tk) } */ 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 { me.myTree.SendEnableDebugger() } 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 { standardExit() panic("forced panic in gocui") return nil }) }