diff --git a/_examples/keybinds.go b/_examples/keybinds.go index c3de5b6..75cc056 100644 --- a/_examples/keybinds.go +++ b/_examples/keybinds.go @@ -2,15 +2,18 @@ package main import ( "errors" + "fmt" "log" + "syscall" + "github.com/awesome-gocui/gocui" ) // layout generates the view func layout(g *gocui.Gui) error { maxX, maxY := g.Size() - if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2, 0); err != nil { + if v, err := g.SetView("hello", maxX/2-15, maxY/2-7, maxX/2+15, maxY/2+7, 0); err != nil { if !errors.Is(err, gocui.ErrUnknownView) { return err } @@ -30,6 +33,15 @@ func quit(_ *gocui.Gui, _ *gocui.View) error { return gocui.ErrQuit } +// handle ctrl+z +func handle_ctrl_z(g *gocui.Gui, v *gocui.View) error { + gocui.Suspend() + fmt.Fprintf(v, "\ngot ctrl+z") + syscall.Kill(syscall.Getpid(), syscall.SIGSTOP) + gocui.Resume() + return nil +} + func main() { // Create a gui g, err := gocui.NewGui(gocui.OutputNormal, false) @@ -54,6 +66,12 @@ func main() { log.Panicln(err) } + // setup ctrl+z + keyForced, modForced = gocui.MustParse("ctrl+z") + if err := g.SetKeybinding("", keyForced, modForced, handle_ctrl_z); err != nil { + log.Panicln(err) + } + // We can blacklist a keybinding. // This allows us to prevent setting the keybinding. if err := g.BlacklistKeybinding(gocui.KeyCtrlC); err != nil {