commandpalette

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IconVM             = "■"
	IconDisk           = "●"
	IconImage          = "◉"
	IconMetadata       = "◐"
	IconBucket         = "▪"
	IconVPC            = "◆"
	IconFirewall       = "▲"
	IconSubnet         = "▫"
	IconSQLInstance    = "⬢"
	IconServiceAccount = "▲"
	IconIAMPolicy      = "▽"
	IconCustomRole     = "▼"
	IconCloudRun       = "▶"
	IconLogs           = "◆"
	IconRefresh        = "↻"
	IconSidebar        = "☰"
	IconHelp           = "?"
	IconRecent         = "⏱"
	IconProject        = "◎"
	IconQuit           = "✕"
	IconDemo           = "▦"
)

Icons for commands

Variables

This section is empty.

Functions

func Score

func Score(query, text string) int

Score calculates a relevance score for how well query matches text. Higher scores indicate better matches. Returns 0 if no match.

Types

type Command

type Command struct {
	ID       string // Unique identifier: "nav:vm-instances", "action:refresh"
	Label    string // Display: "Compute Engine: VM instances"
	Icon     string // Unicode icon
	Type     CommandType
	ViewType ViewType       // For navigation commands
	Action   func() tea.Cmd // For action commands
	Enabled  bool           // Whether command can be executed
}

Command represents an executable palette item

func ActionCommands

func ActionCommands() []Command

ActionCommands returns the action commands

func DefaultCommands

func DefaultCommands() []Command

DefaultCommands returns all default commands (navigation + actions)

func Filter

func Filter(commands []Command, query string) []Command

Filter returns commands that match the query, sorted by relevance. Empty query returns all commands.

func NavigationCommands() []Command

NavigationCommands returns the navigation commands from sidebar menu

type CommandCancelMsg

type CommandCancelMsg struct{}

CommandCancelMsg emitted when user cancels (Esc)

type CommandPalette

type CommandPalette struct {
	// contains filtered or unexported fields
}

CommandPalette is a fuzzy-searchable command selector

func New

func New() *CommandPalette

New creates a new command palette

func (*CommandPalette) CenterInScreen

func (p *CommandPalette) CenterInScreen(screenWidth, screenHeight int) string

CenterInScreen returns the styled palette centered on screen

func (*CommandPalette) HasTextInputFocused

func (p *CommandPalette) HasTextInputFocused() bool

HasTextInputFocused returns true when the text input is focused. Used to prevent global keys (like 'q' for quit) from being triggered while typing.

func (*CommandPalette) Init

func (p *CommandPalette) Init() tea.Cmd

Init initializes the command palette

func (*CommandPalette) Reset

func (p *CommandPalette) Reset()

Reset resets the palette to initial state

func (*CommandPalette) SetCommands

func (p *CommandPalette) SetCommands(commands []Command)

SetCommands sets the available commands

func (*CommandPalette) SetProjectSelected

func (p *CommandPalette) SetProjectSelected(selected bool)

SetProjectSelected sets whether a project is selected (enables navigation commands)

func (*CommandPalette) SetShowPrefix

func (p *CommandPalette) SetShowPrefix(show bool)

SetShowPrefix sets whether to show ":" prefix

func (*CommandPalette) SetSize

func (p *CommandPalette) SetSize(width, height int)

SetSize updates the palette dimensions

func (*CommandPalette) Update

func (p *CommandPalette) Update(msg tea.Msg) tea.Cmd

Update handles messages

func (*CommandPalette) View

func (p *CommandPalette) View() string

View renders the command palette

type CommandSelectedMsg

type CommandSelectedMsg struct {
	Command Command
}

CommandSelectedMsg emitted when user selects a command

type CommandType

type CommandType int

CommandType distinguishes different command behaviors

const (
	CommandTypeNavigation CommandType = iota // Navigate to a view
	CommandTypeAction                        // Execute an action (refresh, toggle)
	CommandTypeRecent                        // Recently accessed item
)

type RecentItem

type RecentItem struct {
	Type      RecentItemType
	ID        string    // Resource ID
	Label     string    // Display name
	Timestamp time.Time // When it was accessed
}

RecentItem represents a recently accessed resource

type RecentItemType

type RecentItemType string

RecentItemType identifies what kind of resource was accessed

const (
	RecentTypeProject  RecentItemType = "project"
	RecentTypeBucket   RecentItemType = "bucket"
	RecentTypeInstance RecentItemType = "instance"
	RecentTypeDisk     RecentItemType = "disk"
	RecentTypeSnapshot RecentItemType = "snapshot"
	RecentTypeImage    RecentItemType = "image"
)

type RecentTracker

type RecentTracker struct {
	// contains filtered or unexported fields
}

RecentTracker manages recently accessed items (in-memory)

func NewRecentTracker

func NewRecentTracker() *RecentTracker

NewRecentTracker creates a new recent items tracker

func (*RecentTracker) Clear

func (r *RecentTracker) Clear()

Clear removes all recent items

func (*RecentTracker) Commands

func (r *RecentTracker) Commands() []Command

Commands converts recent items to Command entries for the palette

func (*RecentTracker) Items

func (r *RecentTracker) Items() []RecentItem

Items returns a copy of the recent items (most recent first)

func (*RecentTracker) SetMaxItems

func (r *RecentTracker) SetMaxItems(maxItems int)

SetMaxItems sets the maximum number of recent items to track

func (*RecentTracker) Track

func (r *RecentTracker) Track(itemType RecentItemType, id, label string)

Track adds or updates a recent item. If the item already exists, it moves to the top.

type Styles

type Styles struct {
	Container     lipgloss.Style // Outer container with border
	Input         lipgloss.Style // Input line style
	InputPrefix   lipgloss.Style // The ":" prefix style
	Separator     lipgloss.Style // Line between input and results
	List          lipgloss.Style // Results list container
	Item          lipgloss.Style // Normal item
	ItemSelected  lipgloss.Style // Selected item
	ItemDisabled  lipgloss.Style // Disabled item (no project selected)
	Icon          lipgloss.Style // Icon style
	IconDisabled  lipgloss.Style // Disabled icon
	Cursor        lipgloss.Style // Selection cursor
	NoResults     lipgloss.Style // "No results" message
	CategoryLabel lipgloss.Style // Category label for grouping (future)
}

Styles holds all command palette styles

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns the default command palette styles

type ViewType

type ViewType int

ViewType mirrors ui.ViewType to avoid import cycle

const (
	ViewInstances ViewType = iota
	ViewDisks
	ViewSnapshots
	ViewImages
	ViewProjectMetadata
	ViewBuckets
	ViewNetworks
	ViewFirewall
	ViewSubnets
	ViewSQLInstances
	ViewServiceAccounts
	ViewIAMPolicy
	ViewCustomRoles
	ViewCloudRunServices
	ViewLogs
)

Jump to

Keyboard shortcuts

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