keys

package
v3.0.0-beta.testing Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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