ui

package
v0.3.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 Hint added in v0.3.0

type Hint struct {
	Key  string
	Desc string
}

Hint is one key and what it does, as drawn in a HintBar.

type HintBar added in v0.3.0

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

HintBar is a one-row strip of key/description pairs on the theme's Well, with optional status text on its left. It is a pure render value: Render returns a string and the bar starts no timer and returns no tea.Cmd.

Every cell of the row, padding and separators included, is drawn through Theme.On with Well as the background, so the row has no see-through cells inside a Rex layer and needs no fill pass.

func NewHintBar added in v0.3.0

func NewHintBar(t theme.Theme) HintBar

NewHintBar returns a hint bar in theme t.

func (HintBar) Render added in v0.3.0

func (b HintBar) Render(hints []Hint, width int) string

Render returns the bar exactly width cells wide. Hints are kept from the first, and the trailing ones that do not fit are dropped whole: a hint is never cut in half. width below one yields an empty string.

func (HintBar) WithStatus added in v0.3.0

func (b HintBar) WithStatus(status string) HintBar

WithStatus returns the bar with status shown at its left edge. Status outranks hints when space runs short: hints are dropped first, and only a status wider than the bar itself is truncated.

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 MultiSelect added in v0.3.0

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

MultiSelect is a vertical checklist: space toggles the row under the cursor, up/down (and j/k unless the list is filterable) move it, enter goes through the form like every other field, and an optional filter narrows the rows as the user types.

The cursor, filter and scroll behaviour is a Select's: a MultiSelect drives one for its movement, so the two cannot drift apart. A choice belongs to an option value, not to a row, so it survives the filter hiding the row and a SetOptions that still has the value.

func NewMultiSelect added in v0.3.0

func NewMultiSelect(key, label string) *MultiSelect

NewMultiSelect returns a checklist whose chosen values are stored under key in the form's Values, titled label.

func (*MultiSelect) Default added in v0.3.0

func (m *MultiSelect) Default(values ...string) *MultiSelect

Default chooses the options with these values, replacing any earlier choice. A value no option has is ignored by Get.

func (*MultiSelect) Err added in v0.3.0

func (b *MultiSelect) Err() error

func (*MultiSelect) Filterable added in v0.3.0

func (m *MultiSelect) Filterable() *MultiSelect

Filterable adds a filter line, as Select.Filterable does. Space still toggles, so a filter cannot contain a space.

func (*MultiSelect) Get added in v0.3.0

func (m *MultiSelect) Get() []string

Get is the chosen options' values, in option order. It is never nil.

func (*MultiSelect) Key added in v0.3.0

func (b *MultiSelect) Key() string

func (*MultiSelect) Min added in v0.3.0

func (m *MultiSelect) Min(n int) *MultiSelect

Min requires at least n chosen options before the field validates; 0 (the default) allows none.

func (*MultiSelect) NaturalSize added in v0.3.0

func (m *MultiSelect) NaturalSize() (cols, rows int)

func (*MultiSelect) OnChange added in v0.3.0

func (m *MultiSelect) OnChange(fn func(value any) tea.Cmd) *MultiSelect

OnChange works as Text.OnChange. It runs when a toggle changes the chosen set.

func (*MultiSelect) Options added in v0.3.0

func (m *MultiSelect) Options(opts ...Option) *MultiSelect

Options sets the options. Values chosen by Default stay chosen.

func (*MultiSelect) Rows added in v0.3.0

func (m *MultiSelect) Rows(n int) *MultiSelect

Rows fixes the number of visible option rows, as Select.Rows does.

func (*MultiSelect) SetOptions added in v0.3.0

func (m *MultiSelect) SetOptions(opts ...Option)

SetOptions replaces the options, as Select.SetOptions does. Chosen values the new options lack drop out of Get. It does not run OnChange.

func (*MultiSelect) Value added in v0.3.0

func (m *MultiSelect) Value() any

Value is the chosen values joined by an unprintable separator, in option order: a string, because the form compares values with ==, which a slice would panic. Read the typed result with Get, or Values.Strings from a submitted form.

type Notice added in v0.3.0

type Notice struct {
	Kind NoticeKind
	Text string
	// Spinner, when non-empty, replaces the kind glyph. The caller supplies
	// the current frame (for example from a bubbles spinner) and re-renders;
	// the Notice never animates itself.
	Spinner string
}

Notice is a one-line toast or banner. It is a pure render value: it owns no timer and returns no tea.Cmd, so dismissal (a timeout, a keypress) stays with the caller, who simply stops rendering it.

func (Notice) Render added in v0.3.0

func (n Notice) Render(t theme.Theme, width int) string

Render returns the notice as one row exactly width cells wide on the theme's Panel, which every status colour clears WCAG AA on. Text that does not fit is cut with an ellipsis; embedded newlines are flattened to spaces so the notice never grows past one row. width below one yields an empty string.

type NoticeKind added in v0.3.0

type NoticeKind int

NoticeKind picks a Notice's colour and glyph.

const (
	// Info is neutral news, drawn in Accent.
	Info NoticeKind = iota
	// Success is a finished action, drawn in Done.
	Success
	// Warning is something that needs the user's attention, drawn in Need.
	Warning
	// Error is a failure, drawn in Danger.
	Error
)

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 Pane added in v0.3.0

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

Pane is a titled, bordered box drawn at an exact size: the building block of a multi-pane dashboard. Unlike Card, which sits inside Rex's own frame, a Pane always draws its border, because a dashboard lays several of them side by side inside one surface.

The title sits in the top edge with an optional right-aligned context string (a count, a branch). The border is Accent when the pane has focus and Border otherwise. An optional scroll readout ("↑N ↓M") sits in the bottom edge. Body lines are clipped to the inner width and height, or padded up to them, and every cell is drawn on the pane's background (Panel by default), so the frame has no bare cells.

Pane is a pure render value like Card: no Init, no state. Its With* methods return modified copies.

func NewPane added in v0.3.0

func NewPane(t theme.Theme, profile colorprofile.Profile) Pane

NewPane returns an unfocused pane in theme t on the Panel background. profile is the terminal's colour profile; on ANSI16 or lower the solid fill is skipped (paint.Fill).

func (Pane) OnSurface added in v0.3.0

func (p Pane) OnSurface() Pane

OnSurface draws the pane on the theme's Surface instead of Panel, for a pane that sits directly on the page rather than on a raised area.

func (Pane) Render added in v0.3.0

func (p Pane) Render(body string, w, h int) string

Render draws body in a w×h box, border included, so lipgloss.Width of the result is w and lipgloss.Height is h. A box smaller than 2×2 cannot hold a border and is returned as plain filled cells of that size. Body lines wider than the inner width are cut (ANSI-aware, no ellipsis, no reflow); lines beyond the inner height are dropped from the bottom.

func (Pane) WithContext added in v0.3.0

func (p Pane) WithContext(s string) Pane

WithContext sets the string right-aligned in the top edge. It is dropped, whole, when it does not fit beside the title.

func (Pane) WithFocus added in v0.3.0

func (p Pane) WithFocus(focused bool) Pane

WithFocus sets whether the pane has focus (Accent border) or not (Border).

func (Pane) WithScroll added in v0.3.0

func (p Pane) WithScroll(above, below int) Pane

WithScroll sets the scroll readout: how many body lines lie above and below the visible window. Both zero hides the readout.

func (Pane) WithTitle added in v0.3.0

func (p Pane) WithTitle(s string) Pane

WithTitle sets the title drawn at the left of the top edge.

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 Tabs added in v0.3.0

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

Tabs is a one-row tab strip: each label is padded by a space either side, the active one is drawn bold on Selection and the others Muted on the strip's background (Surface by default). Like Pane it is a pure render value with no Init; the caller owns which tab is active.

func NewTabs added in v0.3.0

func NewTabs(t theme.Theme, profile colorprofile.Profile, labels []string, active int) Tabs

NewTabs returns a strip of labels in theme t with index active selected. An out-of-range active selects nothing.

func (Tabs) OnPanel added in v0.3.0

func (s Tabs) OnPanel() Tabs

OnPanel draws the strip on the theme's Panel instead of Surface, for a strip that sits inside a Pane.

func (Tabs) Render added in v0.3.0

func (s Tabs) Render(w int) string

Render draws the strip in exactly w cells and one row. When the labels do not fit, leading tabs are replaced by a "…" so the active tab stays visible, and what still overflows is cut at the right edge. A w of zero or less returns "".

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 "".

func (Values) Strings added in v0.3.0

func (v Values) Strings(key string) []string

Strings is the chosen values of a MultiSelect field, or nil.

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