From cebc72c201ded20eee99e85c3b832fba12ab4a34 Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Sat, 24 Jan 2015 14:23:46 +0100 Subject: [PATCH] Add Modifier ModNone. Simplify examples --- _examples/demo.go | 20 ++++++++++---------- _examples/layout.go | 2 +- _examples/overlap.go | 2 +- _examples/wrap.go | 21 ++++++--------------- keybinding.go | 3 ++- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/_examples/demo.go b/_examples/demo.go index 2ab53e5..20adbef 100644 --- a/_examples/demo.go +++ b/_examples/demo.go @@ -110,35 +110,35 @@ func quit(g *gocui.Gui, v *gocui.View) error { } func keybindings(g *gocui.Gui) error { - if err := g.SetKeybinding("side", gocui.KeyCtrlSpace, 0, nextView); err != nil { + if err := g.SetKeybinding("side", gocui.KeyCtrlSpace, gocui.ModNone, nextView); err != nil { return err } - if err := g.SetKeybinding("main", gocui.KeyCtrlSpace, 0, nextView); err != nil { + if err := g.SetKeybinding("main", gocui.KeyCtrlSpace, gocui.ModNone, nextView); err != nil { return err } - if err := g.SetKeybinding("", gocui.KeyArrowDown, 0, cursorDown); err != nil { + if err := g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil { return err } - if err := g.SetKeybinding("", gocui.KeyArrowUp, 0, cursorUp); err != nil { + if err := g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil { return err } - if err := g.SetKeybinding("", gocui.KeyArrowLeft, 0, cursorLeft); err != nil { + if err := g.SetKeybinding("", gocui.KeyArrowLeft, gocui.ModNone, cursorLeft); err != nil { return err } - if err := g.SetKeybinding("", gocui.KeyArrowRight, 0, cursorRight); err != nil { + if err := g.SetKeybinding("", gocui.KeyArrowRight, gocui.ModNone, cursorRight); err != nil { return err } - if err := g.SetKeybinding("", gocui.KeyCtrlC, 0, quit); err != nil { + if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { return err } - if err := g.SetKeybinding("side", gocui.KeyEnter, 0, getLine); err != nil { + if err := g.SetKeybinding("side", gocui.KeyEnter, gocui.ModNone, getLine); err != nil { return err } - if err := g.SetKeybinding("msg", gocui.KeyEnter, 0, delMsg); err != nil { + if err := g.SetKeybinding("msg", gocui.KeyEnter, gocui.ModNone, delMsg); err != nil { return err } - if err := g.SetKeybinding("main", gocui.KeyCtrlS, 0, saveMain); err != nil { + if err := g.SetKeybinding("main", gocui.KeyCtrlS, gocui.ModNone, saveMain); err != nil { return err } return nil diff --git a/_examples/layout.go b/_examples/layout.go index c1e0f8d..24a865d 100644 --- a/_examples/layout.go +++ b/_examples/layout.go @@ -42,7 +42,7 @@ func main() { g.SetLayout(layout) - if err := g.SetKeybinding("", gocui.KeyCtrlC, 0, quit); err != nil { + if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) } diff --git a/_examples/overlap.go b/_examples/overlap.go index 97dce79..0f6c3e9 100644 --- a/_examples/overlap.go +++ b/_examples/overlap.go @@ -65,7 +65,7 @@ func main() { defer g.Close() g.SetLayout(layout) - if err := g.SetKeybinding("", gocui.KeyCtrlC, 0, quit); err != nil { + if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) } diff --git a/_examples/wrap.go b/_examples/wrap.go index 834ab64..1699a0b 100644 --- a/_examples/wrap.go +++ b/_examples/wrap.go @@ -5,9 +5,9 @@ package main import ( - "bytes" "fmt" "log" + "strings" "github.com/jroimartin/gocui" ) @@ -20,6 +20,10 @@ func layout(g *gocui.Gui) error { } v.Wrap = true v.WrapPrefix = "> " + + line := strings.Repeat("This is a long line -- ", 10) + fmt.Fprintf(v, "%v\n\n", line) + fmt.Fprint(v, "Short") } return nil } @@ -38,25 +42,12 @@ func main() { defer g.Close() g.SetLayout(layout) - if err := g.SetKeybinding("", gocui.KeyCtrlC, 0, quit); err != nil { + if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) } - go func() { - var line bytes.Buffer - for i := 0; i < 10; i++ { - line.WriteString("This is a long line -- ") - } - fmt.Fprint(g.View("main"), line.String()) - - fmt.Fprintln(g.View("main"), "") - - fmt.Fprint(g.View("main"), "Short") - }() - err = g.MainLoop() if err != nil && err != gocui.ErrorQuit { log.Panicln(err) } - } diff --git a/keybinding.go b/keybinding.go index 9d69b0e..23a6244 100644 --- a/keybinding.go +++ b/keybinding.go @@ -96,7 +96,8 @@ const ( // Modifiers. const ( - ModAlt Modifier = Modifier(termbox.ModAlt) + ModNone Modifier = Modifier(0) + ModAlt = Modifier(termbox.ModAlt) ) // Keybidings are used to link a given key-press event with an action.