palette

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitNormal    = 0  // Normal selection
	ExitCancelled = 1  // User cancelled (Escape)
	ExitCustom1   = 10 // kb-custom-1 (Alt+Return by default)
	ExitCustom2   = 11 // kb-custom-2 (Alt+d by default)
	ExitCustom3   = 12 // kb-custom-3
)

Exit codes for rofi kb-custom keybindings

Variables

View Source
var ErrCancelled = errors.New("palette cancelled")

ErrCancelled is returned when the user closes the palette without selecting an item.

Functions

func DetectBackend

func DetectBackend() (string, error)

DetectBackend returns the first available palette backend found in PATH, in priority order: rofi, fuzzel, wofi, dmenu.

Types

type Backend

type Backend interface {
	// Show displays the palette and returns the selected item.
	// prompt: the prompt text shown to the user
	// items: the list of items to display
	// message: optional context message (shown in rofi message bar)
	// Returns: selected item result with exit code, or error
	Show(prompt string, items []Item, message string) (SelectResult, error)

	// Capabilities returns the features supported by this backend.
	Capabilities() Capabilities
}

Backend shows a palette to the user and returns the selected item.

func AutoDetect

func AutoDetect() (Backend, error)

AutoDetect selects the first available backend in priority order.

func NewBackend

func NewBackend(name string) (Backend, error)

NewBackend creates a backend by name.

Supported names: auto, rofi, fuzzel, wofi, dmenu.

func NewDmenuBackend

func NewDmenuBackend() Backend

func NewFuzzelBackend

func NewFuzzelBackend() Backend

func NewRofiBackend

func NewRofiBackend() Backend

func NewWofiBackend

func NewWofiBackend() Backend

type Capabilities

type Capabilities struct {
	Icons         bool // Supports icon display
	Markup        bool // Supports pango markup in labels
	NonSelectable bool // Supports non-selectable rows (headers)
	CustomKeys    bool // Supports kb-custom-N keybindings
	IndexOutput   bool // Can output selection index (not just text)
	MessageBar    bool // Supports message/prompt bar
	RowStates     bool // Supports active/urgent row highlighting
}

Capabilities describes what features a backend supports.

type Item

type Item struct {
	Label     string // Display text
	Action    string // Action identifier returned on selection
	Icon      string // Icon name (e.g., "firefox", "folder") for rofi -show-icons
	Info      string // Hidden data returned on selection (for action IDs)
	Meta      string // Hidden search keywords (rofi meta field)
	IsHeader  bool   // Non-selectable section header (bold)
	IsDivider bool   // Non-selectable divider line (dim)
	IsActive  bool   // Highlighted as current/active (rofi active row)
	IsUrgent  bool   // Highlighted as urgent (rofi urgent row)
}

Item is a single selectable entry in a palette menu.

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

Menu handles hierarchical menu navigation using a palette backend.

func NewMenu

func NewMenu(backend Backend, items []MenuItem) *Menu

NewMenu creates a new hierarchical menu with the given backend and root items.

func (m *Menu) SetMessage(msg string)

SetMessage sets a context message to display in the palette (rofi message bar).

func (m *Menu) Show() (MenuResult, error)

Show displays the menu and handles navigation through submenus. Returns the action string of the selected leaf item, or ErrCancelled if user exits.

type MenuItem struct {
	Label     string     // Display label (can include emoji prefix)
	Action    string     // Action identifier (empty for parent items)
	Icon      string     // Icon name for display
	Meta      string     // Hidden search keywords
	IsHeader  bool       // Non-selectable section header (bold)
	IsDivider bool       // Non-selectable divider line (dim)
	IsActive  bool       // Highlight as current/active
	Submenu   []MenuItem // Child items (empty for leaf items)
}

MenuItem represents an item in the menu hierarchy.

func (m MenuItem) IsParent() bool

IsParent returns true if this item has a submenu.

type MenuResult struct {
	Action   string // The action identifier of the selected item
	ExitCode int    // Exit code (0=normal, 10=Alt+Return, 11=Alt+d)
}

MenuResult contains the result of a menu selection.

type SelectResult

type SelectResult struct {
	Item     Item
	ExitCode int // 0=normal, 10=kb-custom-1 (Alt+Return), 11=kb-custom-2 (Alt+d)
}

SelectResult contains the result of a palette selection.

Jump to

Keyboard shortcuts

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