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 ¶
const DefaultAvailability = "action_available?"
DefaultAvailability is the availability predicate an entry uses when it declares none.
Variables ¶
var ( PaletteAlways = PaletteRule{Always: true} PaletteNever = PaletteRule{} )
PaletteAlways and PaletteNever are the two constant rules.
var Contexts = []Context{List, Detail, TaskEdit, Modal, Filter, ModalFilter, Form, Picker, ContextPicker, Prompt, Global}
Contexts is the closed set of lookup contexts.
var ErrUnknownContext = errors.New("unknown shortcut context")
ErrUnknownContext is returned for a lookup in a context that does not exist.
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.
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 ¶
Entries lists the bindings active in a context. Global bindings are included unless includeGlobal is false.
func EntriesForHostContext ¶ added in v1.1.0
EntriesForHostContext returns registry entries in runtime dispatch order.
func Match ¶
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 ¶
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
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
Description string
Context string
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
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`).
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.