2020-01-22 00:01:30 +00:00
|
|
|
# cbind
|
2020-02-07 01:37:48 +00:00
|
|
|
[![GoDoc](https://gitlab.com/tslocum/godoc-static/-/raw/master/badge.svg)](https://docs.rocketnine.space/gitlab.com/tslocum/cbind)
|
2020-01-22 00:01:30 +00:00
|
|
|
[![CI status](https://gitlab.com/tslocum/cbind/badges/master/pipeline.svg)](https://gitlab.com/tslocum/cbind/commits/master)
|
|
|
|
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
|
|
|
|
|
|
|
|
Key event handling library for tcell
|
|
|
|
|
2020-10-16 17:58:26 +00:00
|
|
|
## Features
|
|
|
|
|
|
|
|
- Set `KeyEvent` handlers
|
|
|
|
- Encode and decode `KeyEvent`s as human-readable strings
|
|
|
|
|
2020-10-13 19:41:54 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```go
|
2020-10-16 17:46:57 +00:00
|
|
|
// Create a new input configuration to store the key bindings.
|
|
|
|
c := NewConfiguration()
|
2020-10-13 19:41:54 +00:00
|
|
|
|
2021-03-09 08:02:20 +00:00
|
|
|
// Define save event handler.
|
2020-10-16 17:46:57 +00:00
|
|
|
handleSave := func(ev *tcell.EventKey) *tcell.EventKey {
|
2020-10-13 19:41:54 +00:00
|
|
|
return nil
|
2020-10-16 17:46:57 +00:00
|
|
|
}
|
2020-10-13 19:41:54 +00:00
|
|
|
|
2021-03-09 08:02:20 +00:00
|
|
|
// Define open event handler.
|
2020-10-16 17:46:57 +00:00
|
|
|
handleOpen := func(ev *tcell.EventKey) *tcell.EventKey {
|
2020-10-13 19:41:54 +00:00
|
|
|
return nil
|
2020-10-16 17:46:57 +00:00
|
|
|
}
|
2020-10-13 19:41:54 +00:00
|
|
|
|
2021-03-09 08:02:20 +00:00
|
|
|
// Define exit event handler.
|
2020-10-16 17:46:57 +00:00
|
|
|
handleExit := func(ev *tcell.EventKey) *tcell.EventKey {
|
2020-10-13 19:41:54 +00:00
|
|
|
return nil
|
2020-10-16 17:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2020-10-13 19:41:54 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
```
|
|
|
|
|
2020-01-22 00:01:30 +00:00
|
|
|
## Documentation
|
|
|
|
|
2020-02-07 01:37:48 +00:00
|
|
|
Documentation is available via [gdooc](https://docs.rocketnine.space/gitlab.com/tslocum/cbind).
|
2020-01-22 00:01:30 +00:00
|
|
|
|
2021-03-09 08:02:20 +00:00
|
|
|
The utility program `whichkeybind` is available to determine and validate key combinations.
|
2020-10-13 19:41:54 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
go get gitlab.com/tslocum/cbind/whichkeybind
|
|
|
|
```
|
|
|
|
|
2020-01-22 00:01:30 +00:00
|
|
|
## Support
|
|
|
|
|
2020-02-08 14:08:29 +00:00
|
|
|
Please share issues and suggestions [here](https://gitlab.com/tslocum/cbind/issues).
|