keys

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package keys provides types and function for defining user-configurable keymappings in bubbletea components. Example:

var quit = NewBinding(
	WithKeys("q"),
	WithAction(func(m tea.Model) any {
		return tea.Quit()
	}),
	WithHelp("q", "quit"),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func(tea.Model) any

Action is a callback function executed when a keybinding is pressed

type Binding

type Binding struct {
	*key.Binding
	// contains filtered or unexported fields
}

Binding describes a set of keybindings and a callback to execute when pressed, along with their associated help text.

func NewBinding

func NewBinding(opts ...BindingOpt) Binding

NewBinding returns a new keybinding from a set of BindingOpt options.

func (*Binding) ExecuteAction

func (b *Binding) ExecuteAction(model tea.Model) any

ExecuteAction calls the action for the keybinding

type BindingOpt

type BindingOpt func(*Binding)

BindingOpt is an initialization option for a keybinding. It's used as an argument to NewBinding.

func WithAction

func WithAction(act Action) BindingOpt

WithAction initializes a keybinding with the given callback to execute when pressed.

func WithDisabled

func WithDisabled() BindingOpt

WithDisabled initializes a disabled keybinding.

func WithHelp

func WithHelp(k, desc string) BindingOpt

WithHelp initializes a keybinding with the given help text.

func WithKeys

func WithKeys(keys ...string) BindingOpt

WithKeys initializes a keybinding with the given keystrokes.

type Help

type Help struct {
	Key  string
	Desc string
}

Help is help information for a given keybinding.

Jump to

Keyboard shortcuts

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