TermUI.Widgets.CommandPalette (TermUI v0.2.0)
View SourceSimple command dropdown for filtering and selecting commands.
Shows a list of commands filtered by prefix as the user types.
Similar to typing / in Claude Code to see available slash commands.
Usage
# Define commands
commands = [
%{id: :help, label: "/help", action: fn -> :ok end},
%{id: :save, label: "/save", action: fn -> :ok end},
%{id: :quit, label: "/quit", action: fn -> :ok end}
]
# Create and show palette
props = CommandPalette.new(commands: commands)
{:ok, palette} = CommandPalette.init(props)
# Render dropdown when visible
if CommandPalette.visible?(palette) do
CommandPalette.render(palette, area)
endKeyboard Navigation
- Type to filter by prefix
- Up/Down: Navigate through results
- Enter: Execute selected command
- Escape: Close dropdown
- Backspace: Delete character
Summary
Functions
Gets the current query.
Gets the currently selected command.
Hides the command palette.
Creates new CommandPalette widget props.
Shows the command palette.
Toggles the command palette visibility.
Checks if the palette is visible.
Functions
Gets the current query.
Gets the currently selected command.
Hides the command palette.
Creates new CommandPalette widget props.
Options
:commands- List of command maps (required). Each command has::id- Unique identifier (atom):label- Display text (string):action- Function to execute (fn -> ... end)
:max_visible- Maximum visible results (default: 8)
Shows the command palette.
Toggles the command palette visibility.
Checks if the palette is visible.