Key event handling library for tcell
Go to file
Trevor Slocum b2d7b80afc Update README 2020-10-16 10:58:26 -07:00
whichkeybind Add usage example to README 2020-10-13 12:48:32 -07:00
.gitignore Initial release 2020-01-22 15:20:20 -08:00
.gitlab-ci.yml Add CtrlKey support 2020-02-06 17:37:48 -08:00
CHANGELOG Return ErrInvalidKeyEvent when encoding or decoding fails 2020-10-16 10:46:57 -07:00
LICENSE Initial release 2020-01-22 15:20:20 -08:00
README.md Update README 2020-10-16 10:58:26 -07:00
configuration.go Return ErrInvalidKeyEvent when encoding or decoding fails 2020-10-16 10:46:57 -07:00
configuration_test.go Return ErrInvalidKeyEvent when encoding or decoding fails 2020-10-16 10:46:57 -07:00
doc.go Initial release 2020-01-22 15:20:20 -08:00
go.mod Add usage example to README 2020-10-13 12:48:32 -07:00
go.sum Add usage example to README 2020-10-13 12:48:32 -07:00
key.go Return ErrInvalidKeyEvent when encoding or decoding fails 2020-10-16 10:46:57 -07:00
key_test.go Upgrade tcell to v2 2020-08-26 14:45:15 -07:00

README.md

cbind

GoDoc CI status 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()

handleSave := func(ev *tcell.EventKey) *tcell.EventKey {
    // Save
    return nil
}

handleOpen := func(ev *tcell.EventKey) *tcell.EventKey {
    // Open
    return nil
}

handleExit := func(ev *tcell.EventKey) *tcell.EventKey {
    // Exit
    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 may be used to determine and validate key combinations.

go get gitlab.com/tslocum/cbind/whichkeybind

Support

Please share issues and suggestions here.