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 ¶
- type Card
- type Confirm
- func (c *Confirm) Default(v bool) *Confirm
- func (b *Confirm) Err() error
- func (c *Confirm) Get() bool
- func (b *Confirm) Key() string
- func (c *Confirm) Labels(yes, no string) *Confirm
- func (c *Confirm) NaturalSize() (cols, rows int)
- func (c *Confirm) OnChange(fn func(value any) tea.Cmd) *Confirm
- func (c *Confirm) Value() any
- type Dialog
- func (d *Dialog) Init() tea.Cmd
- func (d *Dialog) NaturalSize() (cols, rows int)
- func (d *Dialog) OnFirstPaint(fn func()) *Dialog
- func (d *Dialog) SetBody(lines []string)
- func (d *Dialog) SetHint(s string)
- func (d *Dialog) Theme() theme.Theme
- func (d *Dialog) Update(msg tea.Msg) tea.Cmd
- func (d *Dialog) View() string
- func (d *Dialog) WithHint(s string) *Dialog
- func (d *Dialog) WithThemeFunc(fn func(color.Color) theme.Theme) *Dialog
- type Field
- type Form
- func (f *Form) Focused() int
- func (f *Form) Init() tea.Cmd
- func (f *Form) NaturalSize() (cols, rows int)
- func (f *Form) OnFirstPaint(fn func()) *Form
- func (f *Form) Render() string
- func (f *Form) Status() FormStatus
- func (f *Form) Theme() theme.Theme
- func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (f *Form) Values() Values
- func (f *Form) View() tea.View
- func (f *Form) WithHint(s string) *Form
- func (f *Form) WithSubtitle(s string) *Form
- func (f *Form) WithThemeFunc(fn func(color.Color) theme.Theme) *Form
- type FormCancelledMsg
- type FormStatus
- type FormSubmittedMsg
- type InfoClosedMsg
- type InfoPanel
- func (p *InfoPanel) Init() tea.Cmd
- func (p *InfoPanel) NaturalSize() (cols, rows int)
- func (p *InfoPanel) OnFirstPaint(fn func()) *InfoPanel
- func (p *InfoPanel) Rebuild()
- func (p *InfoPanel) Theme() theme.Theme
- func (p *InfoPanel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (p *InfoPanel) View() tea.View
- func (p *InfoPanel) WithHint(s string) *InfoPanel
- func (p *InfoPanel) WithRefresh(d time.Duration) *InfoPanel
- func (p *InfoPanel) WithThemeFunc(fn func(color.Color) theme.Theme) *InfoPanel
- type List
- func (l *List) Init() tea.Cmd
- func (l *List) NaturalSize() (cols, rows int)
- func (l *List) OnFirstPaint(fn func()) *List
- func (l *List) Query() string
- func (l *List) Selected() (Row, bool)
- func (l *List) Theme() theme.Theme
- func (l *List) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (l *List) View() tea.View
- func (l *List) WithThemeFunc(fn func(color.Color) theme.Theme) *List
- func (l *List) WithTitle(s string) *List
- type ListCancelledMsg
- type ListSelectedMsg
- type Loader
- type Option
- type OptionsMsg
- type Row
- type Select
- func (s *Select) Default(v string) *Select
- func (s *Select) Err() error
- func (s *Select) Filterable() *Select
- func (s *Select) Get() string
- func (b *Select) Key() string
- func (s *Select) Loader(fn Loader) *Select
- func (s *Select) NaturalSize() (cols, rows int)
- func (s *Select) OnChange(fn func(value any) tea.Cmd) *Select
- func (s *Select) Options(opts ...Option) *Select
- func (s *Select) Pending() *Select
- func (s *Select) Rows(n int) *Select
- func (s *Select) Selected() (Option, bool)
- func (s *Select) SetOptions(opts ...Option)
- func (s *Select) Value() any
- type Text
- func (f *Text) CharLimit(n int) *Text
- func (f *Text) Default(s string) *Text
- func (b *Text) Err() error
- func (f *Text) Get() string
- func (b *Text) Key() string
- func (f *Text) NaturalSize() (cols, rows int)
- func (f *Text) OnChange(fn func(value any) tea.Cmd) *Text
- func (f *Text) Placeholder(s string) *Text
- func (f *Text) Validator(fn func(string) error) *Text
- func (f *Text) Value() any
- type TextArea
- func (f *TextArea) CharLimit(n int) *TextArea
- func (f *TextArea) Default(s string) *TextArea
- func (b *TextArea) Err() error
- func (f *TextArea) Get() string
- func (b *TextArea) Key() string
- func (f *TextArea) Lines(n int) *TextArea
- func (f *TextArea) NaturalSize() (cols, rows int)
- func (f *TextArea) OnChange(fn func(value any) tea.Cmd) *TextArea
- func (f *TextArea) Placeholder(s string) *TextArea
- func (f *TextArea) Validator(fn func(string) error) *TextArea
- func (f *TextArea) Value() any
- type Values
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 ¶
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 ¶
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 ¶
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 ¶
WithHint sets the bottom hint bar's text, such as "enter submit · esc cancel".
func (Card) WithSubtitle ¶
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 ¶
NewConfirm returns a yes/no choice that starts on No.
func (*Confirm) NaturalSize ¶
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 ¶
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 ¶
Init asks the terminal for its background colour; bubbletea sends BackgroundColorMsg only on request.
func (*Dialog) NaturalSize ¶
NaturalSize is the smallest frame showing the title, body and hint uncut.
func (*Dialog) OnFirstPaint ¶
OnFirstPaint sets a hook run once, after the first non-empty View.
func (*Dialog) SetBody ¶
SetBody replaces the body lines, for a dialog whose text changes between stages of the caller's key machine.
func (*Dialog) Update ¶
Update applies window size, background colour and colour profile messages and ignores everything else, keys included.
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 ¶
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) Init ¶
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 ¶
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 ¶
OnFirstPaint sets a hook run once, after the first non-empty View.
func (*Form) Render ¶
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) Update ¶
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) WithHint ¶
WithHint replaces the default hint bar, which names enter as "next" or "submit" depending on the focused field.
func (*Form) WithSubtitle ¶
WithSubtitle sets the card's in-content subtitle.
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 ¶
Init asks the terminal for its background colour (bubbletea sends BackgroundColorMsg only on request) and starts the refresh tick.
func (*InfoPanel) NaturalSize ¶
NaturalSize is the smallest frame that shows the title, up to twenty body lines and the hint without truncation.
func (*InfoPanel) OnFirstPaint ¶
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) Update ¶
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) WithHint ¶
WithHint replaces the hint line. The scroll position is appended to it when the body is taller than the window.
func (*InfoPanel) WithRefresh ¶
WithRefresh makes the panel call Body again every d. Zero or less disables the tick.
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 ¶
NewList returns a picker over rows in theme t. profile is the terminal's colour profile (see NewCard).
func (*List) Init ¶
Init asks the terminal for its background colour; bubbletea sends BackgroundColorMsg only on request.
func (*List) NaturalSize ¶
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 ¶
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) Update ¶
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) WithThemeFunc ¶
WithThemeFunc replaces theme.FromBackground as the way a BackgroundColorMsg picks the theme, as Form.WithThemeFunc.
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 ¶
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 ¶
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 OptionsMsg ¶
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 ¶
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 (*Select) Err ¶
Err implements Field. A loader error outlives edits: it stays until the form is cancelled.
func (*Select) Filterable ¶
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) Loader ¶
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 (*Select) OnChange ¶
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) Pending ¶
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 ¶
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) SetOptions ¶
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.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
func NewText ¶
NewText returns a one-line input whose value is stored under key in the form's Values, titled label.
func (*Text) NaturalSize ¶
func (*Text) OnChange ¶
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 ¶
Placeholder sets the Muted text shown while the input is empty.
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 ¶
NewTextArea returns a multi-line input showing three lines.
func (*TextArea) NaturalSize ¶
func (*TextArea) Placeholder ¶
Placeholder sets the Muted text shown while the input is empty.