cbind

package module
v0.0.0-...-ab6e3eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 5 Imported by: 0

README

cbind

GoDoc builds.sr.ht status Donate

Key event handling library for tcell

Documentation

Documentation is available via gdooc.

Support

Please share issues/suggestions here.

Documentation

Overview

Package cbind provides tcell key event encoding, decoding and handling.

The NewConfiguration example demonstrates how to use cbind.

There are some limitations on reading keyboard input, which is explained in the tcell.EventKey documentation:

https://godoc.org/github.com/gdamore/tcell#EventKey

Index

Examples

Constants

View Source
const (
	LabelCtrl  = "ctrl"
	LabelAlt   = "alt"
	LabelMeta  = "meta"
	LabelShift = "shift"
)

Modifier labels

Variables

This section is empty.

Functions

func Decode

func Decode(s string) (mod tcell.ModMask, key tcell.Key, ch rune, err error)

Decode decodes a string as a key or combination of keys.

func Encode

func Encode(mod tcell.ModMask, key tcell.Key, ch rune) (string, error)

Encode encodes a key or combination of keys a string.

Types

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

Configuration processes key events by mapping keys to event handlers.

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration returns a new input configuration.

Example

Example of creating and using an input configuration.

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

// Set keybind Alt+S.
c.SetRune(tcell.ModAlt, 's', func(ev *tcell.EventKey) *tcell.EventKey {
	// Save
	return nil
})

// Set keybind Alt+O.
c.SetRune(tcell.ModAlt, 'o', func(ev *tcell.EventKey) *tcell.EventKey {
	// Open
	return nil
})

// Set keybind Escape.
c.SetKey(tcell.ModNone, tcell.KeyEscape, func(ev *tcell.EventKey) *tcell.EventKey {
	// Exit
	return nil
})

// Before calling Application.Run, call Application.SetInputCapture:
// app.SetInputCapture(c.Capture)
Output:

func (*Configuration) Capture

func (c *Configuration) Capture(ev *tcell.EventKey) *tcell.EventKey

Capture handles key events.

func (*Configuration) SetKey

func (c *Configuration) SetKey(mod tcell.ModMask, key tcell.Key, handler func(ev *tcell.EventKey) *tcell.EventKey)

SetKey sets the handler for a key.

func (*Configuration) SetRune

func (c *Configuration) SetRune(mod tcell.ModMask, ch rune, handler func(ev *tcell.EventKey) *tcell.EventKey)

SetRune sets the handler for a rune.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL