Documentation
¶
Overview ¶
Package tui draws the small interactive menus of `agentguard setup`: a list you move through with the arrow keys and pick from with Enter. It draws in place in the normal terminal (no full-screen mode) and leaves a one-line record of each answer, so the scrollback reads like a log of what was chosen.
The menu logic (Menu, ParseKeys, Run) works on plain readers and writers so tests drive it with scripted key presses; Terminal adds the real terminal: raw mode for the duration of a menu, and colour when the terminal supports it.
Index ¶
Constants ¶
const Back = -1
Back is the choice Run returns when the user presses Esc or q.
Variables ¶
var ErrNotTerminal = errors.New("not an interactive terminal")
ErrNotTerminal means stdin or stdout isn't an interactive terminal (a pipe, a file, CI), so no menu can be shown.
var ErrQuit = errors.New("quit")
ErrQuit is returned when the user presses Ctrl-C (or Ctrl-D) in a menu.
Functions ¶
func ColorWanted ¶
func ColorWanted() bool
ColorWanted reports whether colour output is welcome: NO_COLOR unset (https://no-color.org) and not a dumb terminal.
Types ¶
type Key ¶
type Key int
Key is a key press that means something to a menu.
The keys a menu understands. Everything else is ignored.
type Menu ¶
Menu is one selectable list and where the cursor is in it.
func NewMenu ¶
NewMenu starts the cursor on def: on the next selectable option when def is a separator, on the first one when def is out of range.
type Option ¶
type Option struct {
Label string
Hint string // shown dimmed after the label
// Separator makes this line a divider: drawn, never selectable.
Separator bool
}
Option is one line of a menu.
type Style ¶
type Style struct{ Color bool }
Style decides whether output carries ANSI colour.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is the user's terminal, ready for menus.
func Open ¶
Open checks that stdin and stdout are a terminal and prepares it: on Windows that switches the console to understand ANSI escape codes. Close undoes it.