command

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package command provides a shadcn/ui-style Command: a palette that opens over the window to run a command by name, as ⌘K does. A field filters the commands by their labels and keywords as you type, the arrows move the choice down the list that remains, and Enter or a click runs the chosen one.

command.Command(c, command.Props{
	Open:  &open,
	Items: []command.Item{
		{Label: "New file", Keywords: []string{"create"}, OnSelect: app.newFile},
	},
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(c *ui.Context, p Props) ui.Element

Command draws the palette for props, or nothing while it is closed. It returns the panel, so a view can chain more calls on it. The backdrop dims the window; clicking it or pressing Escape closes the palette.

Types

type Item

type Item struct {
	// Label is the text of the command.
	Label string
	// Keywords are the extra words a search matches, such as synonyms
	// of the command.
	Keywords []string
	// Icon is the shape of the command, an SVG in currentColor; nil
	// for none.
	Icon *ui.SVG
	// OnSelect runs when the command is chosen.
	OnSelect func()
}

Item is one command of the palette.

type Props

type Props struct {
	// Open is the bool that shows and hides the palette; the backdrop
	// and Escape set it to false.
	Open *bool
	// State is where the palette is, for the app to keep.
	State *State
	// Items are the commands offered, in order.
	Items []Item
}

Props describes the palette to draw.

type State

type State struct {
	// Query is the text filtering the commands, cleared as the palette
	// closes.
	Query string
	// contains filtered or unexported fields
}

State is where the palette is, kept by the app.

Jump to

Keyboard shortcuts

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