shortcuts

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 5 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 shortcuts is the declarative registry for every keyboard action shown in help. Contexts decide where a binding is active; the application owns only dispatch order and the action implementations. Optional form/confirmation metadata is consumed by the command palette.

Go port of Ruby's lib/tui/shortcuts.rb. Handlers and availability predicates are named as strings here, exactly as Ruby names them as symbols; the application resolves a name to a method. Validation against a concrete handler set is offered as an option rather than performed by reflection.

Index

Constants

View Source
const DefaultAvailability = "action_available?"

DefaultAvailability is the availability predicate an entry uses when it declares none.

Variables

View Source
var (
	PaletteAlways = PaletteRule{Always: true}
	PaletteNever  = PaletteRule{}
)

PaletteAlways and PaletteNever are the two constant rules.

Contexts is the closed set of lookup contexts.

View Source
var ErrUnknownContext = errors.New("unknown shortcut context")

ErrUnknownContext is returned for a lookup in a context that does not exist.

View Source
var Registry = []Entry{}/* 103 elements not displayed */

Registry is the complete key table, in dispatch/help order.

Functions

func Validate

func Validate(opts ValidateOptions) error

Validate checks the registry's structural invariants and its per-context key collisions.

Types

type Context

type Context string

Context is where a binding is active.

const (
	List          Context = "list"
	Detail        Context = "detail"
	TaskEdit      Context = "task_edit"
	Modal         Context = "modal"
	Filter        Context = "filter"
	ModalFilter   Context = "modal_filter"
	Form          Context = "form"
	Picker        Context = "picker"
	ContextPicker Context = "context_picker"
	Prompt        Context = "prompt"
	Global        Context = "global"
)

type Entry

type Entry struct {
	Sequences []string
	// DisplayKey is what the help modal shows.
	DisplayKey      string
	HelpDisplayKey  string
	HelpDescription string
	HideInHelp      bool
	// Description is the help text; it doubles as the palette label.
	Description string
	// CommandID is the stable host-facing action identifier. Empty entries
	// derive it from Handler, keeping the registry as the only command table.
	CommandID string
	// FooterLabel and FooterPriority are host projection metadata. Priority
	// 1 is most important; 4+ is normally palette-only.
	FooterLabel    string
	FooterPriority int
	Contexts       []Context
	// Handler names the application method that performs the action. Empty
	// only for DocOnly entries.
	Handler string
	// Availability names the predicate that decides whether the action can run
	// right now. A bound but unavailable key is still consumed.
	Availability string
	Palette      PaletteRule
	// Form and Confirmation are metadata for the palette and future consumers.
	Form         string
	Confirmation string
	// DocOnly entries appear in help but bind no key and run no handler.
	DocOnly bool
}

Entry is one binding.

func Entries

func Entries(context Context, includeGlobal bool) ([]Entry, error)

Entries lists the bindings active in a context. Global bindings are included unless includeGlobal is false.

func EntriesForHostContext added in v1.1.0

func EntriesForHostContext(name string) []Entry

EntriesForHostContext returns registry entries in runtime dispatch order.

func Match

func Match(sequence string, context Context, resolve func(string) bool) (Entry, bool)

Match returns the binding for a sequence in a context, even when it is unavailable: dispatch must consume such a key instead of falling through to another context. resolve answers availability predicates; a nil resolve returns the first binding regardless of availability.

func PaletteEntries

func PaletteEntries(context Context, resolve func(string) bool) []Entry

PaletteEntries lists the context's palette-visible, currently available actions. Global bindings are excluded, as in Ruby. resolve answers both the availability and the palette predicates; a nil resolve admits nothing.

type ExportedBinding added in v1.1.0

type ExportedBinding struct {
	Key       string
	CommandID string
	Context   string
}

ExportedBinding is one host-consumable default key binding.

func ExportBindings added in v1.1.0

func ExportBindings() []ExportedBinding

ExportBindings projects Registry's raw terminal sequences into Bubble Tea's canonical key names. Conditional same-key actions remain in registry order.

type ExportedCommand added in v1.1.0

type ExportedCommand struct {
	ID              string
	FooterLabel     string
	Description     string
	Context         string
	FooterPriority  int
	DefaultBindings []string
}

ExportedCommand is host-facing command-palette and footer metadata.

func ExportCommands added in v1.1.0

func ExportCommands() []ExportedCommand

ExportCommands returns one command per command ID and host context, with all of that entry's default bindings folded onto it.

type ExportedContext added in v1.1.0

type ExportedContext struct {
	Name              string
	ConsumesTextInput bool
}

ExportedContext describes a stable interaction context even when its keys are owned by an input widget rather than the shortcut registry.

func ExportContexts added in v1.1.0

func ExportContexts() []ExportedContext

ExportContexts returns every stable host focus context.

type PaletteRule

type PaletteRule struct {
	// Always makes the entry unconditionally palette-visible.
	Always bool
	// Predicate names an availability method; empty means "not in the palette"
	// unless Always is set.
	Predicate string
}

PaletteRule says whether an entry appears in the command palette.

func PaletteWhen

func PaletteWhen(predicate string) PaletteRule

PaletteWhen makes palette visibility conditional on a named predicate.

func (PaletteRule) Active

func (p PaletteRule) Active() bool

Active reports whether the rule is set at all (Ruby's truthy `palette`).

func (PaletteRule) Enabled

func (p PaletteRule) Enabled(resolve func(string) bool) bool

Enabled reports whether this rule admits the entry, given a predicate resolver. A nil resolver treats every named predicate as false.

type ValidateOptions

type ValidateOptions struct {
	Entries []Entry
	// Handlers, when non-nil, must contain every entry's handler name.
	Handlers map[string]bool
	// Predicates, when non-nil, must contain every availability and palette
	// predicate name.
	Predicates map[string]bool
	// KeyedHandlers names handlers that require the original key. A
	// palette-enabled entry may not use one, because the palette invokes the
	// action without a key.
	KeyedHandlers map[string]bool
}

ValidateOptions optionally checks handler and predicate names against the set the application actually implements.

Jump to

Keyboard shortcuts

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