ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ui is rexuikit's native content kit. Every component renders cells that all carry an explicit background, so a Rex floating layer never shows the terminal through them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

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

Card is the frame a form or panel is drawn in.

The default Card has no border and no title of its own. Inside a Rex layer, Rex's border and title bar are the frame and the surface's label is the title, so the card fills its whole w×h frame edge to edge with the surface colour and draws only padding, an optional subtitle, the content and a hint bar on the bottom row. Bordered opts into a drawn border and title for a host that has no Rex chrome (a plain terminal, a golden test).

Card is a value; its With* and Bordered methods return modified copies.

func NewCard

func NewCard(t theme.Theme, profile colorprofile.Profile) Card

NewCard returns a borderless card in theme t. profile is the terminal's colour profile; on ANSI16 or lower the solid fill is skipped (paint.Fill).

func (Card) Bordered

func (c Card) Bordered(title string) Card

Bordered returns the card with a rounded border in the Border colour and title set into the top edge. Use it only where Rex draws no chrome of its own.

func (Card) NaturalSize

func (c Card) NaturalSize(content string) (cols, rows int)

NaturalSize is the card's size in cells for content: the smallest frame that shows the content, subtitle and hint without truncation. Surfaces use it to size the Rex layer to the form.

func (Card) Render

func (c Card) Render(content string, w, h int) string

Render draws content in a w×h frame. A w or h of zero or less means the natural size on that axis. Content wider or taller than the frame is cut (columns by ANSI-aware truncation, rows from the bottom) rather than reflowed, and the hint bar always keeps the last row.

func (Card) WithHint

func (c Card) WithHint(s string) Card

WithHint sets the bottom hint bar's text, such as "enter submit · esc cancel".

func (Card) WithSubtitle

func (c Card) WithSubtitle(s string) Card

WithSubtitle sets a one-line subtitle drawn inside the content area, above the content, in the Muted colour.

type Confirm

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

Confirm is a yes/no choice: left/right (h/l) toggle, y and n choose.

func NewConfirm

func NewConfirm(key, label string) *Confirm

NewConfirm returns a yes/no choice that starts on No.

func (*Confirm) Default

func (c *Confirm) Default(v bool) *Confirm

func (*Confirm) Err

func (b *Confirm) Err() error

func (*Confirm) Get

func (c *Confirm) Get() bool

func (*Confirm) Key

func (b *Confirm) Key() string

func (*Confirm) Labels

func (c *Confirm) Labels(yes, no string) *Confirm

func (*Confirm) NaturalSize

func (c *Confirm) NaturalSize() (cols, rows int)

func (*Confirm) OnChange

func (c *Confirm) OnChange(fn func(value any) tea.Cmd) *Confirm

OnChange works as Text.OnChange.

func (*Confirm) Value

func (c *Confirm) Value() any

type Dialog

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

Dialog is a solid card holding a title, pre-rendered body lines and a hint bar, for confirmations whose keys are not form keys (a staged `d d`, a mode-registry key). It routes no keys: the caller's model reads them and decides, and passes every other message to Update for size and theme.

func NewDialog

func NewDialog(t theme.Theme, profile colorprofile.Profile, title string, body []string) *Dialog

NewDialog returns a dialog in theme t; profile is the terminal's colour profile (see NewCard). body lines may carry their own styling; spans that set no background get the Surface colour from the card's fill.

func (*Dialog) Init

func (d *Dialog) Init() tea.Cmd

Init asks the terminal for its background colour; bubbletea sends BackgroundColorMsg only on request.

func (*Dialog) NaturalSize

func (d *Dialog) NaturalSize() (cols, rows int)

NaturalSize is the smallest frame showing the title, body and hint uncut.

func (*Dialog) OnFirstPaint

func (d *Dialog) OnFirstPaint(fn func()) *Dialog

OnFirstPaint sets a hook run once, after the first non-empty View.

func (*Dialog) SetBody

func (d *Dialog) SetBody(lines []string)

SetBody replaces the body lines, for a dialog whose text changes between stages of the caller's key machine.

func (*Dialog) SetHint

func (d *Dialog) SetHint(s string)

func (*Dialog) Theme

func (d *Dialog) Theme() theme.Theme

Theme is the dialog's current theme, for rendering body lines to match.

func (*Dialog) Update

func (d *Dialog) Update(msg tea.Msg) tea.Cmd

Update applies window size, background colour and colour profile messages and ignores everything else, keys included.

func (*Dialog) View

func (d *Dialog) View() string

View draws the dialog at the window size, or at NaturalSize before the first WindowSizeMsg.

func (*Dialog) WithHint

func (d *Dialog) WithHint(s string) *Dialog

func (*Dialog) WithThemeFunc

func (d *Dialog) WithThemeFunc(fn func(color.Color) theme.Theme) *Dialog

WithThemeFunc works as Form.WithThemeFunc.

type Field

type Field interface {
	// Key names the field's value in the form's Values.
	Key() string
	// Value is the field's current value: a string for Text, TextArea and
	// Select, a bool for Confirm.
	Value() any
	// Err is the error the field currently shows, or nil.
	Err() error
	// NaturalSize is the field's size in cells at its natural width:
	// label, well rows and the status row.
	NaturalSize() (cols, rows int)
	// contains filtered or unexported methods
}

Field is one input of a Form: Text, TextArea, Select or Confirm. The set is closed (the unexported methods are the rendering and focus contract the Form drives), so a Form can rely on every field drawing a label, a well and a status row.

type Form

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

Form hosts fields on one Card: every field visible at once, enter or tab validates the focused field and moves on, shift+tab goes back, enter on the last field validates everything and submits, esc cancels.

It is a bubbletea model. Its size comes from tea.WindowSizeMsg; before one arrives it draws at NaturalSize, which is also what a surface should size the Rex layer to.

func NewForm

func NewForm(t theme.Theme, profile colorprofile.Profile, fields ...Field) *Form

NewForm returns a form over fields in theme t, which is the first-frame theme until a BackgroundColorMsg re-themes it. profile is the terminal's colour profile (see NewCard). Field keys must be unique.

func (*Form) Focused

func (f *Form) Focused() int

func (*Form) Init

func (f *Form) Init() tea.Cmd

Init asks the terminal for its background colour (bubbletea sends BackgroundColorMsg only on request), focuses the first field and starts every Select's loader.

func (*Form) NaturalSize

func (f *Form) NaturalSize() (cols, rows int)

NaturalSize is the form's size in cells with every field at its natural width and the wider of the two default hints, so the size does not change as the focus moves.

func (*Form) OnFirstPaint

func (f *Form) OnFirstPaint(fn func()) *Form

OnFirstPaint sets a hook run once, after the first non-empty View.

func (*Form) Render

func (f *Form) Render() string

Render draws the form at the window size, or at NaturalSize before the first WindowSizeMsg.

func (*Form) Status

func (f *Form) Status() FormStatus

Status reports whether the form is still open, submitted or cancelled.

func (*Form) Theme

func (f *Form) Theme() theme.Theme

func (*Form) Update

func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model. Keys and pastes go to the focused field; any other message goes to every field, which is how an OptionsMsg reaches its Select wherever the focus is.

func (*Form) Values

func (f *Form) Values() Values

func (*Form) View

func (f *Form) View() tea.View

func (*Form) WithHint

func (f *Form) WithHint(s string) *Form

WithHint replaces the default hint bar, which names enter as "next" or "submit" depending on the focused field.

func (*Form) WithSubtitle

func (f *Form) WithSubtitle(s string) *Form

WithSubtitle sets the card's in-content subtitle.

func (*Form) WithThemeFunc

func (f *Form) WithThemeFunc(fn func(color.Color) theme.Theme) *Form

WithThemeFunc replaces theme.FromBackground as the way a BackgroundColorMsg picks the theme, for callers mapping their own palette onto the tokens.

type FormCancelledMsg

type FormCancelledMsg struct{}

FormCancelledMsg is sent when the user presses esc or ctrl+c. As with ListCancelledMsg the host decides what that means; a Form never quits the program itself, so it can be embedded in a larger model.

type FormStatus

type FormStatus int

FormStatus is where a Form is in its life.

const (
	FormPending FormStatus = iota
	FormSubmitted
	FormCancelled
)

type FormSubmittedMsg

type FormSubmittedMsg struct {
	Values Values
}

type InfoClosedMsg

type InfoClosedMsg struct{}

InfoClosedMsg is sent when the user presses esc or q. As with ListCancelledMsg the host decides what closing means.

type InfoPanel

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

InfoPanel is a scrollable, painted viewer over caller-rendered lines.

Body receives the usable column count and returns pre-rendered lines; the panel never styles or wraps them, so a caller (forge's quick info) keeps its own panel colours. Cells the lines leave without a background are closed by the Card's fill pass. With a refresh interval set the panel calls Body again on every tick and keeps the scroll position, clamped when the new body is shorter.

func NewInfoPanel

func NewInfoPanel(t theme.Theme, profile colorprofile.Profile, title string, body func(width int) []string) *InfoPanel

NewInfoPanel returns a viewer in theme t showing body's lines under title. An empty title omits the title row.

func (*InfoPanel) Init

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

Init asks the terminal for its background colour (bubbletea sends BackgroundColorMsg only on request) and starts the refresh tick.

func (*InfoPanel) NaturalSize

func (p *InfoPanel) NaturalSize() (cols, rows int)

NaturalSize is the smallest frame that shows the title, up to twenty body lines and the hint without truncation.

func (*InfoPanel) OnFirstPaint

func (p *InfoPanel) OnFirstPaint(fn func()) *InfoPanel

OnFirstPaint registers fn to run once, right after the first View that produced a frame (see List.OnFirstPaint).

func (*InfoPanel) Rebuild

func (p *InfoPanel) Rebuild()

Rebuild calls Body again at the current width and keeps the scroll position, clamped when the new body is shorter: what the refresh tick does, for a host that learns of new data on its own schedule.

func (*InfoPanel) Theme

func (p *InfoPanel) Theme() theme.Theme

Theme is the panel's current theme.

func (*InfoPanel) Update

func (p *InfoPanel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model. A BackgroundColorMsg re-themes the panel's surface, title and hint and a ColorProfileMsg sets the profile its fill uses, as Form and Dialog do. The body's lines are the caller's and keep their own colours.

func (*InfoPanel) View

func (p *InfoPanel) View() tea.View

View implements tea.Model.

func (*InfoPanel) WithHint

func (p *InfoPanel) WithHint(s string) *InfoPanel

WithHint replaces the hint line. The scroll position is appended to it when the body is taller than the window.

func (*InfoPanel) WithRefresh

func (p *InfoPanel) WithRefresh(d time.Duration) *InfoPanel

WithRefresh makes the panel call Body again every d. Zero or less disables the tick.

func (*InfoPanel) WithThemeFunc

func (p *InfoPanel) WithThemeFunc(fn func(color.Color) theme.Theme) *InfoPanel

WithThemeFunc replaces theme.FromBackground as the way a BackgroundColorMsg picks the theme, as Form.WithThemeFunc.

type List

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

List is a filterable picker: typing narrows the rows by case-insensitive substring, up/down move the cursor, enter selects and esc cancels.

It is a bubbletea model that fills its whole frame through a borderless Card, so it is solid inside a Rex layer. Its natural size is computed from all rows and never from the current filter, so the layer a surface opens does not need to resize while the user types.

func NewList

func NewList(t theme.Theme, profile colorprofile.Profile, rows []Row) *List

NewList returns a picker over rows in theme t. profile is the terminal's colour profile (see NewCard).

func (*List) Init

func (l *List) Init() tea.Cmd

Init asks the terminal for its background colour; bubbletea sends BackgroundColorMsg only on request.

func (*List) NaturalSize

func (l *List) NaturalSize() (cols, rows int)

NaturalSize is the smallest frame that shows the filter line, up to ten rows, the optional title and the hint bar without truncation. It does not change as the filter narrows.

func (*List) OnFirstPaint

func (l *List) OnFirstPaint(fn func()) *List

OnFirstPaint registers fn to run once, right after the first View that produced a frame. It is how a host learns the picker is on screen (to record time to first paint or start deferred work) without owning the frame loop.

func (*List) Query

func (l *List) Query() string

Query is the current filter text.

func (*List) Selected

func (l *List) Selected() (Row, bool)

Selected reports the row under the cursor, if any row passes the filter.

func (*List) Theme

func (l *List) Theme() theme.Theme

Theme is the picker's current theme.

func (*List) Update

func (l *List) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model. A BackgroundColorMsg re-themes the picker and a ColorProfileMsg sets the profile its fill uses, as Form and Dialog do.

func (*List) View

func (l *List) View() tea.View

View implements tea.Model.

func (*List) WithThemeFunc

func (l *List) WithThemeFunc(fn func(color.Color) theme.Theme) *List

WithThemeFunc replaces theme.FromBackground as the way a BackgroundColorMsg picks the theme, as Form.WithThemeFunc.

func (*List) WithTitle

func (l *List) WithTitle(s string) *List

WithTitle sets a Muted line above the filter, such as "Base branch".

type ListCancelledMsg

type ListCancelledMsg struct{}

ListCancelledMsg is sent when the user presses esc. The host decides what to do about it (close the surface, quit the program): a component that called tea.Quit itself could not be embedded in a larger model.

type ListSelectedMsg

type ListSelectedMsg struct {
	Index int
	Row   Row
}

ListSelectedMsg is sent when the user presses enter on a row. Index is the row's position in the slice given to NewList, not in the filtered view.

type Loader

type Loader func() (options []Option, def string, err error)

Loader produces a Select's options after the first paint: the options, the value to preselect (ignored when no option has it), and an error that is shown in the field and blocks submit.

type Option

type Option struct {
	Label string
	Value string
}

Option is one choice of a Select: Label is shown, Value is returned.

type OptionsMsg

type OptionsMsg struct {
	Select  *Select
	Options []Option
	Default string
	Err     error
}

OptionsMsg delivers a Select's options. A Select with a Loader produces it from its Init command; a caller that marked a Select Pending sends it itself. A Select ignores an OptionsMsg addressed to another Select.

type Row

type Row struct {
	Label  string
	Detail string
}

Row is one choice in a List. Detail is optional secondary text drawn after the label in the Muted colour.

type Select

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

Select is a vertical option list: `›` marks the chosen option, up/down (and j/k unless the list is filterable) move it, and an optional filter narrows the options as the user types.

func NewSelect

func NewSelect(key, label string) *Select

func (*Select) Default

func (s *Select) Default(v string) *Select

Default preselects the option with value v.

func (*Select) Err

func (s *Select) Err() error

Err implements Field. A loader error outlives edits: it stays until the form is cancelled.

func (*Select) Filterable

func (s *Select) Filterable() *Select

Filterable adds a filter line: typed characters narrow the options by case-insensitive substring, backspace and ctrl+u edit the filter. j and k then type into the filter, so only up/down (and ctrl+p/ctrl+n) move.

func (*Select) Get

func (s *Select) Get() string

Get is the typed value: the chosen option's Value, or "".

func (*Select) Key

func (b *Select) Key() string

func (*Select) Loader

func (s *Select) Loader(fn Loader) *Select

Loader loads the options asynchronously: the field shows a loading row until the loader's OptionsMsg arrives, then preselects its default. The loader runs as a command from the form's Init, off the update loop, so a slow loader never delays the first frame.

func (*Select) NaturalSize

func (s *Select) NaturalSize() (cols, rows int)

func (*Select) OnChange

func (s *Select) OnChange(fn func(value any) tea.Cmd) *Select

OnChange works as Text.OnChange. It also runs when an OptionsMsg changes the value, so a field derived from this one follows the loaded default.

func (*Select) Options

func (s *Select) Options(opts ...Option) *Select

Options sets the options; the Default value, if any, is preselected.

func (*Select) Pending

func (s *Select) Pending() *Select

Pending shows the loading row until the caller sends an OptionsMsg for this Select, for callers that start loading on their own schedule.

func (*Select) Rows

func (s *Select) Rows(n int) *Select

Rows fixes the number of visible option rows: more options scroll, fewer leave blank rows. Without it the field shows every option, or reserves four rows while a Loader runs.

func (*Select) Selected

func (s *Select) Selected() (Option, bool)

Selected is the chosen option; false when none is visible.

func (*Select) SetOptions

func (s *Select) SetOptions(opts ...Option)

SetOptions replaces the options, typically from another field's OnChange. The chosen value is kept when the new options still have it; otherwise the cursor is clamped into the new list. It does not run OnChange, so two fields deriving each other's options cannot loop.

func (*Select) Value

func (s *Select) Value() any

type Text

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

func NewText

func NewText(key, label string) *Text

NewText returns a one-line input whose value is stored under key in the form's Values, titled label.

func (*Text) CharLimit

func (f *Text) CharLimit(n int) *Text

CharLimit caps the value's length in runes; 0 means no limit.

func (*Text) Default

func (f *Text) Default(s string) *Text

func (*Text) Err

func (b *Text) Err() error

func (*Text) Get

func (f *Text) Get() string

func (*Text) Key

func (b *Text) Key() string

func (*Text) NaturalSize

func (f *Text) NaturalSize() (cols, rows int)

func (*Text) OnChange

func (f *Text) OnChange(fn func(value any) tea.Cmd) *Text

OnChange sets a hook run whenever the value changes through user input. The returned command, if any, is run by the form.

func (*Text) Placeholder

func (f *Text) Placeholder(s string) *Text

Placeholder sets the Muted text shown while the input is empty.

func (*Text) Validator

func (f *Text) Validator(fn func(string) error) *Text

Validator sets the check run when the user leaves the field (enter or tab) and on submit. A non-nil error keeps focus on the field and shows the error in the status row until the value changes.

func (*Text) Value

func (f *Text) Value() any

type TextArea

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

TextArea is a multi-line input on bubbles' textarea. Enter moves to the next field like every other field does, so a newline is alt+enter or ctrl+j, the keys huh's text field uses.

func NewTextArea

func NewTextArea(name, label string) *TextArea

NewTextArea returns a multi-line input showing three lines.

func (*TextArea) CharLimit

func (f *TextArea) CharLimit(n int) *TextArea

CharLimit caps the value's length in runes; 0 means no limit.

func (*TextArea) Default

func (f *TextArea) Default(s string) *TextArea

func (*TextArea) Err

func (b *TextArea) Err() error

func (*TextArea) Get

func (f *TextArea) Get() string

Get is the typed value, lines joined by "\n".

func (*TextArea) Key

func (b *TextArea) Key() string

func (*TextArea) Lines

func (f *TextArea) Lines(n int) *TextArea

Lines sets the number of visible lines (at least 1). Longer text scrolls.

func (*TextArea) NaturalSize

func (f *TextArea) NaturalSize() (cols, rows int)

func (*TextArea) OnChange

func (f *TextArea) OnChange(fn func(value any) tea.Cmd) *TextArea

OnChange works as Text.OnChange.

func (*TextArea) Placeholder

func (f *TextArea) Placeholder(s string) *TextArea

Placeholder sets the Muted text shown while the input is empty.

func (*TextArea) Validator

func (f *TextArea) Validator(fn func(string) error) *TextArea

Validator works as Text.Validator.

func (*TextArea) Value

func (f *TextArea) Value() any

type Values

type Values map[string]any

func (Values) Bool

func (v Values) Bool(key string) bool

Bool is the value of a Confirm field, or false.

func (Values) String

func (v Values) String(key string) string

String is the value of a Text, TextArea or Select field, or "".

Directories

Path Synopsis
Package paint makes a rendered frame opaque.
Package paint makes a rendered frame opaque.
Package theme holds rexuikit's semantic colour tokens.
Package theme holds rexuikit's semantic colour tokens.

Jump to

Keyboard shortcuts

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