Key event handling library for tcell
Go to file
Trevor Slocum 91bcd66e25 Remove code.rocketnine.space migration notice 2021-03-28 12:11:18 -07:00
whichkeybind Add code.rocketnine.space migration notice 2021-03-28 12:09:56 -07:00
.gitignore Initial release 2020-01-22 15:20:20 -08:00
CHANGELOG Add code.rocketnine.space migration notice 2021-03-28 12:09:56 -07:00
LICENSE Initial release 2020-01-22 15:20:20 -08:00
README.md Remove code.rocketnine.space migration notice 2021-03-28 12:11:18 -07:00
configuration.go Add code.rocketnine.space migration notice 2021-03-28 12:09:56 -07:00
configuration_test.go Update Configuration test 2021-03-09 00:49:42 -08:00
doc.go Initial release 2020-01-22 15:20:20 -08:00
go.mod Add code.rocketnine.space migration notice 2021-03-28 12:09:56 -07:00
go.sum Update README and usage examples 2021-03-09 00:02:20 -08:00
key.go Update README and usage examples 2021-03-09 00:02:20 -08:00
key_test.go Upgrade tcell to v2 2020-08-26 14:45:15 -07:00

README.md

cbind

GoDoc Donate

Key event handling library for tcell

Features

  • Set KeyEvent handlers
  • Encode and decode KeyEvents as human-readable strings

Usage

// Create a new input configuration to store the key bindings.
c := NewConfiguration()

// Define save event handler.
handleSave := func(ev *tcell.EventKey) *tcell.EventKey {
    return nil
}

// Define open event handler.
handleOpen := func(ev *tcell.EventKey) *tcell.EventKey {
    return nil
}

// Define exit event handler.
handleExit := func(ev *tcell.EventKey) *tcell.EventKey {
    return nil
}

// Bind Alt+s.
if err := c.Set("Alt+s", handleSave); err != nil {
    log.Fatalf("failed to set keybind: %s", err)
}

// Bind Alt+o.
c.SetRune(tcell.ModAlt, 'o', handleOpen)

// Bind Escape.
c.SetKey(tcell.ModNone, tcell.KeyEscape, handleExit)

// Capture input. This will differ based on the framework in use (if any).
// When using tview or cview, call Application.SetInputCapture before calling
// Application.Run.
app.SetInputCapture(c.Capture)

Documentation

Documentation is available via gdooc.

The utility program whichkeybind is available to determine and validate key combinations.

go get code.rocketnine.space/tslocum/cbind/whichkeybind

Support

Please share issues and suggestions here.