choicebar

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package choicebar is a small question asked on the context line and answered with a key, the way terminal programs confirm things, e.g. "You have unsaved changes. Enter Save and quit D Discard Esc Cancel". It takes the keyboard like an overlay but draws no box, and knows the UI only through Host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	Msg     string
	Warn    bool   // the message is a warning, e.g. about losing work
	Desc    string // more on the status line, when the question needs it
	Choices []Choice
	// contains filtered or unexported fields
}

Bar is the question and its choices.

func New

func New(h Host, msg string, warn bool, desc string, choices []Choice) *Bar

New returns a bar asking msg.

func (*Bar) Choose

func (b *Bar) Choose(i int) tea.Cmd

Choose closes the bar and runs choice i.

func (*Bar) ContextLine

func (b *Bar) ContextLine() (string, string)

ContextLine renders the bar for the context line.

func (*Bar) Find

func (b *Bar) Find(answer string) int

Find is the index of the choice with key or label answer, ignoring case, or -1.

func (*Bar) Indicator

func (b *Bar) Indicator() string

func (*Bar) Key

func (b *Bar) Key(k tea.KeyPressMsg) tea.Cmd

func (*Bar) Layout

func (b *Bar) Layout() []overlay.Box

func (*Bar) Mouse

func (b *Bar) Mouse(e overlay.MouseEvent) tea.Cmd

Mouse runs a choice when its key chip or label is clicked. A click anywhere else cancels, like Esc.

func (*Bar) Status

func (b *Bar) Status() (string, string)

type Choice

type Choice struct {
	Key   string
	Label string
	Run   func() tea.Cmd
}

Choice is one answer: a key as tea reports it ("enter", "d"), its label, and what choosing it does, after the bar has closed.

type Host

type Host interface {
	Theme() *theme.Theme
	// Close closes the open overlay.
	Close()
	// RecordAnswer tells a macro recording the key chosen, for the
	// command that asked; Esc cancels it.
	RecordAnswer(answer string, cancelled bool)
}

Host is what a choice bar needs of the UI.

Jump to

Keyboard shortcuts

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