Documentation
¶
Overview ¶
Package keymap is the terminal UI's one table of actions: each action has its keys, its command-line name and its help text, so the footer, the help overlay, the command line and the menus are all generated from the same entries (design/tui.md "Keys").
Index ¶
- Constants
- func Closest(word string, choices []string) string
- func ParseCommand(line string) (string, []string, error)
- func Quote(s string) string
- type Action
- type Arg
- type Completion
- type FuzzyMatch
- type Names
- type Registry
- func (r *Registry) Add(a ...Action)
- func (r *Registry) All() []Action
- func (r *Registry) ByID(id string) (Action, bool)
- func (r *Registry) Command(id string) (Action, error)
- func (r *Registry) Commands() []string
- func (r *Registry) Complete(line string, cursor int, n Names) Completion
- func (r *Registry) InScope(scopes ...Scope) []Action
- func (r *Registry) Lookup(key string, scopes ...Scope) (Action, bool)
- func (r *Registry) Variants(id string) []Action
- type Scope
Constants ¶
const ( RankLoose = iota RankWordStart RankPrefix RankExact )
The kinds of match, best first: the query's first word is the text's first word ("restart" for Restart web), begins it ("res"), begins a later word of it ("web"), or only appears in it as a subsequence ("rw").
Variables ¶
This section is empty.
Functions ¶
func ParseCommand ¶
ParseCommand splits a command line into the command and its arguments; double quotes keep spaces in one argument, and a leading colon is optional. "q" is quit.
Types ¶
type Action ¶
type Action struct {
// ID is the action's name and its command: `:restart` runs "restart".
ID string
// Keys are key names as tea.KeyPressMsg.String() gives them: "s",
// "space", "ctrl+d", "shift+down".
Keys []string
Scope Scope
// Help is the description in the help overlay and the menus; Short is
// the footer's word ("restart").
Help, Short string
// Group is the section in the help overlay.
Group string
Footer bool
// Arg is the command line's argument; Optional makes it optional (the
// selection is used then).
Arg Arg
Optional bool
// Menu puts the action in the menu of its scope (x or a right click).
Menu bool
// Destructive marks an action that removes something; it asks first,
// and the palette and menus mark it.
Destructive bool
}
Action is one thing the user can do.
type Arg ¶
type Arg int
Arg is what an action's one command-line argument names: completion offers those names and the command line checks the argument against them before it runs anything.
type Completion ¶
Completion is what can replace the word under the cursor: the runes [Start, End) of the line, with one of Items (quoted when needed). Word is that word's index: 0 for the command.
type FuzzyMatch ¶
FuzzyMatch is how a query matches a text: Rank is the kind of match, Score orders matches of one kind and At holds the matched rune indexes of the text, ascending, for highlighting.
func Fuzzy ¶
func Fuzzy(query, text string) (m FuzzyMatch, ok bool)
Fuzzy matches query against text, ignoring case: every word of query must appear in text as a subsequence, else ok is false. Rank comes from the query's first word and the text's words (FuzzyMatch). Score adds, per query word, its matched runes with bonuses for runs and word starts and more for a word found whole; it loses two points for every space-separated word of text that no match touches, so of two equally matched texts the one the query explains better wins ("res" ranks Restart web above Restart the daemon in place).
type Names ¶
type Names struct {
Servers, Groups, Containers, Projects, Themes, Icons, States, Computers []string
}
Names are the names the command line's arguments take.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the actions in table order.
func Default ¶
func Default() *Registry
Default is the action table. The keys follow lazygit and lazydocker (design/tui.md "Keys"): h and l or the arrows move between panes, [ and ] between tabs, J and K scroll the main panel from anywhere, x opens the focused pane's menu, ? lists the keys, : runs a command and ctrl+p finds an action or a server in the palette.
func (*Registry) ByID ¶
ByID returns the first action with the id, in table order (an id in several scopes, such as "attach", has the same meaning in each).
func (*Registry) Command ¶
Command resolves a command name: the exact id, else the only id it begins, else the shortest of the ids it begins when that one begins all of them ("rest" is restart, not restart-group).
func (*Registry) Complete ¶
func (r *Registry) Complete(line string, cursor int, n Names) Completion
Complete returns the completions of the word at cursor, a rune index into line: a command name for the first word, else a name of the kind the command's argument takes; names that begin with the typed part come first, then those that contain it.