Add Modifier ModNone. Simplify examples

This commit is contained in:
Roi Martin 2015-01-24 14:23:46 +01:00
parent 9b902f9bec
commit cebc72c201
5 changed files with 20 additions and 28 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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.