tui

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tui provides a reusable list picker for CLI list subcommands.

It wraps bubbletea/bubbles/list to render a scrollable/filterable list of items with arrow-key navigation, `/` filter (built-in), `c` to copy the selected item's ID to the system clipboard, `enter` to return the selection to the caller, and `q`/`ctrl+c` to quit without selecting.

The caller is responsible for rendering the detail view after the TUI exits — this package does not show details itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Active

func Active(forceTUI, noTUI, jsonOutput bool) (bool, error)

Active returns true when a TUI should be launched given the flag state. Rules:

  • jsonOutput=true → false (JSON always wins)
  • noTUI=true → false
  • tui=true → true (but returns an error if stdout is not a TTY)
  • otherwise → false (default off; user must opt in)

func AddFlags

func AddFlags(cmd *cobra.Command, tui, noTUI *bool)

AddFlags registers the standard --tui and --no-tui flags on a command. Both flags default to false. Pass pointers to command-local bool vars.

Types

type Item

type Item struct {
	ID         string
	TitleText  string
	DescText   string
	FilterText string
}

Item is a selectable row. ID is what `c` copies and what is returned to the caller when the user selects the row. TitleText and DescText are shown in the list; FilterText (optional) is matched by `/`.

func (Item) Description

func (i Item) Description() string

Description implements list.DefaultItem.

func (Item) FilterValue

func (i Item) FilterValue() string

FilterValue implements list.Item.

func (Item) Title

func (i Item) Title() string

Title implements list.DefaultItem.

type ListConfig

type ListConfig struct {
	Title string
	Items []Item
}

ListConfig configures a list session.

type Result

type Result struct {
	// SelectedID is set to the chosen item's ID if the user pressed enter.
	// Empty when the user quit without selecting.
	SelectedID string
}

Result carries the outcome of a list session.

func RunList

func RunList(cfg ListConfig) (Result, error)

RunList displays the list picker and blocks until the user quits or selects an item. On selection, returns the chosen ID. On quit, returns an empty ID.

Jump to

Keyboard shortcuts

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