Documentation
¶
Overview ¶
Package form is the TUI's dialog kit: text fields, text areas, selects, checkboxes, pick lists, read-only notes and buttons. Tab / shift+Tab move between them, ctrl+s or Enter on a button submits, Esc cancels. Every field, list item and button is a hit rectangle, so the root model routes clicks to it through its pure layout.
A form never runs anything: Key and Click return an Event, and the dialog that owns the form builds the CLI arguments from its values.
Index ¶
- type Button
- type Editor
- func (e *Editor) Click(x, y, w int)
- func (e *Editor) Height(w int) int
- func (e *Editor) Insert(s string)
- func (e *Editor) Key(k tea.KeyPressMsg, w int) bool
- func (e *Editor) Scroll(n, w, h int)
- func (e *Editor) Set(s string)
- func (e *Editor) String() string
- func (e *Editor) View(w, h int, cursor func(string) string, placeholder string, ...) []string
- type Event
- type Field
- type Form
- func (f *Form) Click(h Hit, x, y int, double bool, width int) (Event, string)
- func (f *Form) Field(id string) *Field
- func (f *Form) FocusButton(id string)
- func (f *Form) FocusField(id string)
- func (f *Form) Get(id string) string
- func (f *Form) Key(k tea.KeyPressMsg, width int) (Event, string)
- func (f *Form) Paste(s string)
- func (f *Form) View(width int, th style.Theme) ([]string, []Hit)
- func (f *Form) Wheel(h Hit, n, width int)
- type Hit
- type Kind
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Editor ¶
type Editor struct {
Value []rune
Pos int // cursor: an index into Value
Off int // first visual row shown
Multi bool // newlines allowed (Insert keeps them)
}
Editor is a small text editor: runes and a cursor, soft-wrapped at the width it is drawn with. A single-line editor shows the visual row that holds the cursor.
func (*Editor) Insert ¶
Insert inserts s at the cursor. A single-line editor turns newlines into spaces; other control characters are dropped.
func (*Editor) Key ¶
func (e *Editor) Key(k tea.KeyPressMsg, w int) bool
Key edits with a key press and reports whether it used it. Newlines are the caller's choice (Insert("\n")); up and down move between visual rows of width w.
func (*Editor) View ¶
func (e *Editor) View(w, h int, cursor func(string) string, placeholder string, dim func(...string) string) []string
View renders h rows of w cells, scrolled so the cursor shows; cursor draws the cell under it (nil: no cursor). placeholder shows, through dim, when the text is empty.
type Field ¶
type Field struct {
Kind Kind
ID string
Label string
Required bool
Ed Editor // Text, Area
Height int // Area, List, Note: rows shown
Opts []Option
Sel int // Select, List
On bool // Check
Text string // Note
Off int // List, Note: first row shown
Keep bool // List: keep a disabled preselection (submitting it says why)
// Placeholder shows, dim, in an empty Text or Area ("" = a blank line).
Placeholder string
}
Field is one row (or block of rows) of a form.
type Form ¶
type Form struct {
Title string
Fields []*Field
Buttons []Button
Focus int // index into the focusables: the fields that can focus, then the buttons
Err string // a failed check or the CLI's error, shown above the buttons
Status string // "working…" while the action runs
}
Form is a dialog's content.
func (*Form) Click ¶
Click handles a left click on hit h at the cell (x, y) relative to the form; double is a second click on the same spot.
func (*Form) FocusButton ¶
FocusButton moves the focus to button id.
func (*Form) FocusField ¶
FocusField moves the focus to field id.
func (*Form) Key ¶
Key handles a key press. Width is the form's content width (Area rows wrap there).
type Hit ¶
type Hit struct {
X, Y, W, H int
Field int // field index, -1 for a button
Button int // button index, -1 for a field
Opt int // List: option index; -1 otherwise
}
Hit is a clickable rectangle of the form's view, relative to its top-left cell.