Browse Source

Update cbind

tablepad
Trevor Slocum 2 years ago
parent
commit
27a707dceb
  1. 34
      demos/focusmanager/main.go
  2. 4
      go.mod
  3. 11
      go.sum

34
demos/focusmanager/main.go

@ -9,6 +9,13 @@ import (
"gitlab.com/tslocum/cview"
)
func wrap(f func()) func(ev *tcell.EventKey) *tcell.EventKey {
return func(ev *tcell.EventKey) *tcell.EventKey {
f()
return nil
}
}
func main() {
app := cview.NewApplication()
app.EnableMouse(true)
@ -39,40 +46,17 @@ func main() {
inputHandler := cbind.NewConfiguration()
for _, key := range cview.Keys.MovePreviousField {
mod, key, ch, err := cbind.Decode(key)
err := inputHandler.Set(key, wrap(focusManager.FocusPrevious))
if err != nil {
log.Fatal(err)
}
if key == tcell.KeyRune {
inputHandler.SetRune(mod, ch, func(ev *tcell.EventKey) *tcell.EventKey {
focusManager.FocusPrevious()
return nil
})
} else {
inputHandler.SetKey(mod, key, func(ev *tcell.EventKey) *tcell.EventKey {
focusManager.FocusPrevious()
return nil
})
}
}
for _, key := range cview.Keys.MoveNextField {
mod, key, ch, err := cbind.Decode(key)
err := inputHandler.Set(key, wrap(focusManager.FocusNext))
if err != nil {
log.Fatal(err)
}
if key == tcell.KeyRune {
inputHandler.SetRune(mod, ch, func(ev *tcell.EventKey) *tcell.EventKey {
focusManager.FocusNext()
return nil
})
} else {
inputHandler.SetKey(mod, key, func(ev *tcell.EventKey) *tcell.EventKey {
focusManager.FocusNext()
return nil
})
}
}
app.SetInputCapture(inputHandler.Capture)
app.SetRoot(grid, true)

4
go.mod

@ -7,6 +7,6 @@ require (
github.com/lucasb-eyer/go-colorful v1.0.3
github.com/mattn/go-runewidth v0.0.9
github.com/rivo/uniseg v0.1.0
gitlab.com/tslocum/cbind v0.1.2
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 // indirect
gitlab.com/tslocum/cbind v0.1.3
golang.org/x/sys v0.0.0-20201016160150-f659759dc4ca // indirect
)

11
go.sum

@ -10,13 +10,12 @@ github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/Qd
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
gitlab.com/tslocum/cbind v0.1.2 h1:ptDjO7WeOl1HglprsK18L8I9JeRkmtuBoBBaYw/6/Ow=
gitlab.com/tslocum/cbind v0.1.2/go.mod h1:HfB7qAhHSZbn1rFK8M9SvSN5NG6ScAg/3h3iE6xdeeI=
gitlab.com/tslocum/cbind v0.1.3 h1:FT/fTQ4Yj3eo5021lB3IbkIt8eVtYGhrw/xur+cjvUU=
gitlab.com/tslocum/cbind v0.1.3/go.mod h1:RvwYE3auSjBNlCmWeGspzn+jdLUVQ8C2QGC+0nP9ChI=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201013132646-2da7054afaeb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201016160150-f659759dc4ca h1:mLWBs1i4Qi5cHWGEtn2jieJQ2qtwV/gT0A2zLrmzaoE=
golang.org/x/sys v0.0.0-20201016160150-f659759dc4ca/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

Loading…
Cancel
Save