keymap

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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 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

View Source
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 Closest

func Closest(word string, choices []string) string

Closest returns the choice nearest to word within a few edits, or "".

func ParseCommand

func ParseCommand(line string) (string, []string, error)

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.

func Quote

func Quote(s string) string

Quote returns s as one command-line word: quoted when it holds a space or a quote, or is empty.

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 puts the action in the footer of its scope, in table order.
	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.

func (Action) CheckArgs

func (a Action) CheckArgs(args []string) error

CheckArgs checks the number of arguments a command line gives an action: none for ArgNone, at most one otherwise, exactly one when the argument is not optional.

func (Action) Command

func (a Action) Command(arg string) string

Command is the action's command line with an argument: "restart web". An argument with spaces or quotes is quoted.

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.

const (
	ArgNone Arg = iota
	ArgServer
	ArgGroup
	ArgServerOrGroup
	ArgContainer
	ArgTheme
	ArgIcons
	ArgState
	ArgComputer
	ArgPort
	ArgText    // free text, e.g. a filter
	ArgProject // a compose project
)

func (Arg) Noun

func (a Arg) Noun() string

Noun is how messages name an argument kind ("a server").

type Completion

type Completion struct {
	Start, End int
	Word       int
	Items      []string
}

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

type FuzzyMatch struct {
	Rank, Score int
	At          []int
}

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.

func (Names) For

func (n Names) For(a Arg) []string

For returns the names an argument kind takes.

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) Add

func (r *Registry) Add(a ...Action)

Add appends actions.

func (*Registry) All

func (r *Registry) All() []Action

All returns every action in table order.

func (*Registry) ByID

func (r *Registry) ByID(id string) (Action, bool)

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

func (r *Registry) Command(id string) (Action, error)

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) Commands

func (r *Registry) Commands() []string

Commands returns every command name once, sorted.

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.

func (*Registry) InScope

func (r *Registry) InScope(scopes ...Scope) []Action

InScope returns the actions of the scopes, the first scope's first.

func (*Registry) Lookup

func (r *Registry) Lookup(key string, scopes ...Scope) (Action, bool)

Lookup returns the action a key runs in the scopes, the first scope's first.

func (*Registry) Variants

func (r *Registry) Variants(id string) []Action

Variants returns every action with the id, in table order: "restart" is a server's, a group's and a container's.

type Scope

type Scope string

Scope is where an action applies; the root model passes the focused pane's scope, then ScopeGlobal.

const (
	ScopeGlobal     Scope = "global"
	ScopeServers    Scope = "servers"
	ScopeContainers Scope = "containers"
	ScopePorts      Scope = "ports"
	ScopeLogs       Scope = "logs"
	ScopeDetail     Scope = "detail" // the Details, Env and Metrics tabs
)

func Scopes

func Scopes() []Scope

Scopes lists every scope in the order the help overlay shows the ones after the focused pane's.

func (Scope) Title

func (s Scope) Title() string

Title is how the help overlay and the menus name a scope.

Jump to

Keyboard shortcuts

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