command

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 7 Imported by: ? 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 command builds a searchable command palette on ui's public API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Palette

func Palette(c *ui.Context, s *State, items []Item) (string, bool)

Palette shows a modal palette while s.Open is true. Typing searches titles and keywords by case-insensitive subsequences, with exact/prefix and word-boundary matches ranked first; whitespace separates search terms. Up/Down and Page Up/Down move past disabled results, Enter chooses, and Escape or a click outside closes. Only visible result rows are built. The input keeps focus, with the chosen option its active descendant.

The ID returned by a choice is reported once, and the palette closes before it is returned. Dispatch it after Palette; actions belong to the app. Invalid (empty or duplicate) IDs panic when items change.

Types

type Item

type Item struct {
	ID, Title, Detail, Keywords string
	Shortcut                    Shortcut
	Disabled                    bool
}

Item is an app command. ID must be nonempty and unique in a palette; Title is its name, Detail optional secondary text, and Keywords search aliases. Shortcut is the key that runs the item, drawn as a menu draws one: the app owns the binding itself. A disabled item remains visible but cannot be chosen.

type Shortcut

type Shortcut struct {
	Mods ui.Modifiers
	Key  ui.Key
}

Shortcut is a key with modifiers, drawn as a menu draws one: Cmd and K read "⌘K" on a Mac and "Ctrl+K" elsewhere. The zero value draws nothing.

type State

type State struct {
	Open  bool
	Query string
	// Label names the dialog and input; Placeholder and EmptyText override
	// their text. Empty strings use MyGo's localized Search and No results.
	Label, Placeholder, EmptyText string
	// Width and Height are DIPs: 560 and 320 by default, capped by the
	// window. Height is the results list's height, not the whole dialog.
	Width, Height float32
	// contains filtered or unexported fields
}

State is a palette's state, kept by the app for one view in one window. Set Open to show it, and call Palette every frame, including while closed. Closing clears Query, so an app can fill one in before opening the palette. Items can change while it is open; the keyboard choice follows its ID unless the query changes or the item disappears. As with other UI state, use it on the UI thread.

Jump to

Keyboard shortcuts

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