Documentation
¶
Index ¶
- Variables
- func Card(lines []string, maxWidth int) string
- func CardBodyHeight(totalHeight, pinnedRows int) int
- func CardBodyWidth(totalWidth int) int
- func CardLayout(children ...layout.Node) layout.Col
- func CardOrigin() (x, y int)
- func CardWithStyle(lines []string, maxWidth int, style CardStyle) string
- func ContentWidth(totalWidth int) int
- func FrameWidth(maxWidth int, lines []string) int
- func Overlay(base string, layer string) string
- func OverlayOrigin(base, layer string) (x, y int)
- func Subtle(text string) string
- func SubtleWithStyle(text string, style lipgloss.Style) string
- func Title(text string) string
- func TitleWithStyle(text string, style lipgloss.Style) string
- type CardStyle
- type Column
- type FocusRing
- type KeyBinding
- type KeyGroup
- type KeyGroups
- type KeyMap
- type KeyMapMode
- type KeyMapOptions
- type List
- func (l *List) Adopt(event flatte.LayoutEvent, id string)
- func (l List) Count() int
- func (l List) Cursor() int
- func (l List) Height() int
- func (l List) Layout() layout.Node
- func (l *List) MoveDown()
- func (l *List) MoveUp()
- func (l List) Offset() int
- func (l List) Rows(id string, row func(index int, selected bool) layout.Node) layout.Col
- func (l *List) Scroll(rows int)
- func (l *List) ScrollTo(offset int)
- func (l *List) Select(i int)
- func (l *List) SetCount(n int)
- func (l *List) SetHeight(h int)
- func (l List) View(render func(index int, selected bool) string) string
- type Paginator
- func (p *Paginator) NextPage()
- func (p Paginator) Page() int
- func (p Paginator) PageSize() int
- func (p Paginator) Pages() int
- func (p *Paginator) PrevPage()
- func (p Paginator) Range() (first, last int)
- func (p *Paginator) SelectPage(page int)
- func (p *Paginator) SetPageSize(n int)
- func (p *Paginator) SetTotal(n int)
- func (p Paginator) Total() int
- func (p Paginator) View() string
- type Progress
- type ProgressStyle
- type Rect
- type Select
- func (s *Select) Click(target, id string) bool
- func (s *Select) Close()
- func (s *Select) Confirm()
- func (s Select) Highlighted() int
- func (s Select) IsOpen() bool
- func (s Select) Layout(id string, focused bool) layout.Node
- func (s Select) LayoutWithButton(button layout.Button) layout.Node
- func (s *Select) MoveDown()
- func (s *Select) MoveUp()
- func (s *Select) Open()
- func (s Select) Options() []string
- func (s *Select) Select(i int)
- func (s Select) Selected() int
- func (s *Select) SetOptions(options []string)
- func (s *Select) Toggle()
- func (s Select) Value() string
- type Spinner
- type Stopwatch
- type TabBar
- func (t *TabBar) Active() int
- func (t *TabBar) ActiveID() string
- func (t *TabBar) HitTest(rects map[string]layout.Rect, x, y int) (int, bool)
- func (t *TabBar) Layout() layout.Node
- func (t *TabBar) Next()
- func (t *TabBar) Prev()
- func (t *TabBar) SetActive(i int)
- func (t *TabBar) WithBorder(b TabBarBorder) *TabBar
- func (t *TabBar) WithColors(f, i, bg color.Color) *TabBar
- func (t *TabBar) WithGlyphs(g TabGlyphs) *TabBar
- func (t *TabBar) WithID(id string) *TabBar
- type TabBarBorder
- type TabGlyphs
- type TabItem
- type Table
- func (t Table) Cells(cells []string, style layout.TextStyle) layout.Row
- func (t Table) Cursor() int
- func (t Table) Header() string
- func (t Table) HeaderLayout(style layout.TextStyle) layout.Row
- func (t Table) HeaderWithStyle(style TableStyle) string
- func (t *Table) MoveDown()
- func (t *Table) MoveUp()
- func (t Table) Rows(id string, row func(cells []string, selected bool) layout.Node) layout.Col
- func (t *Table) Select(i int)
- func (t Table) SelectedRow() []string
- func (t *Table) SetColumns(cols []Column)
- func (t *Table) SetHeight(h int)
- func (t *Table) SetRows(rows [][]string)
- func (t Table) View(renderRow func(text string, selected bool) string) string
- func (t Table) ViewWithStyle(style TableStyle) string
- type TableStyle
- type TextField
- func (f *TextField) Backspace()
- func (f *TextField) ClearSelection()
- func (f TextField) CursorColumn() int
- func (f *TextField) Delete()
- func (f *TextField) DeleteToEnd()
- func (f *TextField) DeleteToStart()
- func (f *TextField) DeleteWordLeft()
- func (f *TextField) DeleteWordRight()
- func (f *TextField) Edit(key flatte.KeyEvent) bool
- func (f *TextField) HandleMouse(id string, e flatte.MouseEvent) bool
- func (f *TextField) Insert(r rune)
- func (f *TextField) InsertText(s string)
- func (f TextField) Layout(id string, focused bool) layout.Input
- func (f *TextField) MoveEnd()
- func (f *TextField) MoveEndSelecting()
- func (f *TextField) MoveLeft()
- func (f *TextField) MoveLeftSelecting()
- func (f *TextField) MoveRight()
- func (f *TextField) MoveRightSelecting()
- func (f *TextField) MoveStart()
- func (f *TextField) MoveStartSelecting()
- func (f *TextField) MoveWordLeft()
- func (f *TextField) MoveWordLeftSelecting()
- func (f *TextField) MoveWordRight()
- func (f *TextField) MoveWordRightSelecting()
- func (f *TextField) SelectAll()
- func (f TextField) SelectedText() string
- func (f TextField) Selection() (start, end int, ok bool)
- func (f *TextField) SetCursor(cursor int)
- type TextPosition
- type TextRange
- type Textarea
- func (t *Textarea) Backspace()
- func (t *Textarea) ClearSelection()
- func (t Textarea) Col() int
- func (t Textarea) CursorCell() (x, y int)
- func (t *Textarea) Delete()
- func (t *Textarea) DeleteWordLeft()
- func (t *Textarea) DeleteWordRight()
- func (t *Textarea) Edit(key flatte.KeyEvent) bool
- func (t *Textarea) Insert(r rune)
- func (t *Textarea) InsertNewline()
- func (t *Textarea) InsertText(s string)
- func (t Textarea) Layout(id string, focused bool) layout.Input
- func (t *Textarea) MoveDown()
- func (t *Textarea) MoveDownSelecting()
- func (t *Textarea) MoveLeft()
- func (t *Textarea) MoveLeftSelecting()
- func (t *Textarea) MoveLineEnd()
- func (t *Textarea) MoveLineEndSelecting()
- func (t *Textarea) MoveLineStart()
- func (t *Textarea) MoveLineStartSelecting()
- func (t *Textarea) MoveRight()
- func (t *Textarea) MoveRightSelecting()
- func (t *Textarea) MoveTo(offset int)
- func (t *Textarea) MoveToSelecting(offset int)
- func (t *Textarea) MoveUp()
- func (t *Textarea) MoveUpSelecting()
- func (t *Textarea) MoveWordLeft()
- func (t *Textarea) MoveWordLeftSelecting()
- func (t *Textarea) MoveWordRight()
- func (t *Textarea) MoveWordRightSelecting()
- func (t Textarea) Offset() int
- func (t Textarea) Row() int
- func (t *Textarea) SelectAll()
- func (t Textarea) SelectedText() string
- func (t Textarea) Selection() (TextRange, bool)
- func (t *Textarea) SetSize(width, height int)
- func (t *Textarea) SetSoftWrap(enabled bool)
- func (t *Textarea) SetValue(s string)
- func (t Textarea) SoftWrap() bool
- func (t Textarea) Value() string
- func (t Textarea) View() string
- func (t Textarea) ViewWithSelection(render func(text string, selected bool) string) string
- type Timer
- type Tree
- func (t Tree) CursorID() string
- func (t *Tree) MoveDown()
- func (t *Tree) MoveUp()
- func (t Tree) Offset() int
- func (t Tree) Rows(id string, row func(row TreeRow, selected bool) layout.Node) layout.Col
- func (t *Tree) SelectVisible(i int)
- func (t *Tree) SetHeight(h int)
- func (t *Tree) SetNodes(nodes []TreeNode)
- func (t *Tree) Toggle(id string)
- func (t Tree) View(render func(row TreeRow, selected bool) string) string
- func (t Tree) VisibleRows() []TreeRow
- type TreeNode
- type TreeRow
- type Viewport
- func (v *Viewport) Adopt(rects map[string]layout.Rect, id string)
- func (v Viewport) AtBottom() bool
- func (v Viewport) AtTop() bool
- func (v *Viewport) GotoBottom()
- func (v *Viewport) GotoTop()
- func (v *Viewport) HalfPageDown()
- func (v *Viewport) HalfPageUp()
- func (v Viewport) Layout() layout.Node
- func (v *Viewport) LineDown(n int)
- func (v *Viewport) LineUp(n int)
- func (v Viewport) Offset() int
- func (v *Viewport) PageDown()
- func (v *Viewport) PageUp()
- func (v Viewport) ScrollPercent() float64
- func (v *Viewport) ScrollToLine(i int)
- func (v *Viewport) SetContent(content string)
- func (v *Viewport) SetLines(lines []string)
- func (v *Viewport) SetSize(width, height int)
- func (v *Viewport) SetWrappedContent(content string)
- func (v Viewport) TotalLines() int
- func (v Viewport) View() string
- func (v Viewport) VisibleLines() int
- type ZoneMap
- type ZoneScannerdeprecated
Constants ¶
This section is empty.
Variables ¶
var ( // SpinnerDots is the braille "dots" animation (single display cell wide). SpinnerDots = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} // SpinnerLine is the ASCII bar animation. SpinnerLine = []string{"|", "/", "-", "\\"} )
Preset frame sets. Apps may also pass their own to NewSpinner.
var TabGlyphsPowerline = TabGlyphs{Left: "\ue0ba", Right: "\ue0bc"}
var TabGlyphsSafe = TabGlyphs{Left: "[", Right: "]"}
Functions ¶
func CardBodyHeight ¶
CardBodyHeight returns the rows available for a body inside a Card of the given total height, after the card's top and bottom border and the pinnedRows of non-body content (title, footer, etc.) the app stacks around the body. The app still declares its own pinnedRows — that count is app layout, not card chrome — but the card's border math lives here.
func CardBodyWidth ¶
CardBodyWidth returns the usable content width for a body placed inside a Card of the given total width — the total minus the card's border and horizontal padding. Size a body widget with this (in Handle, on ResizeEvent) so it tracks the card chrome instead of a hardcoded constant.
func CardLayout ¶ added in v0.2.0
CardLayout returns Card's look as a layout node: a Col with a plain border in a muted grey and two columns of padding each side, holding children. As a Frame.Root it fills the frame. It is an ordinary Col, so the app can set its ID, sizes, or border colour.
func CardOrigin ¶
func CardOrigin() (x, y int)
CardOrigin is the cell offset of a Card's first content cell relative to the card's top-left corner: one border column plus two padding columns across, one border row down.
func ContentWidth ¶
func FrameWidth ¶
func Overlay ¶
Overlay draws layer centered over base as a cell-buffer composite. It delegates to the layout engine's compositor so there is a single ANSI-aware overlay implementation (see flatui/layout/overlay.go).
func OverlayOrigin ¶
OverlayOrigin returns where Overlay places layer's top-left cell inside the composed frame. Delegates to the layout engine so it stays in lockstep with Overlay's centering.
Types ¶
type Column ¶
Column is a table column: a header title and a fixed display width. Cells are padded to the width and truncated when wider.
type FocusRing ¶
type FocusRing struct {
// contains filtered or unexported fields
}
FocusRing is app-owned focus index state for cycling among focusable regions. It owns no key policy; apps decide whether Tab, Shift-Tab, mouse, or another command calls Next, Prev, or Select.
func (*FocusRing) Prev ¶
func (f *FocusRing) Prev()
Prev moves focus backward, wrapping at the beginning.
type KeyBinding ¶
KeyBinding is display metadata for a command binding. It is not input policy: apps still decide how terminal events map to behavior.
type KeyGroups ¶
type KeyGroups []KeyGroup
KeyGroups renders context-sensitive help across named groups.
func (KeyGroups) ViewWithOptions ¶
func (groups KeyGroups) ViewWithOptions(opts KeyMapOptions) string
ViewWithOptions renders grouped key metadata. It owns no key matching or input policy; apps still decide how events map to commands.
type KeyMap ¶
type KeyMap []KeyBinding
KeyMap is a small help-line renderer for key binding metadata.
type KeyMapMode ¶
type KeyMapMode int
KeyMapMode selects how grouped key bindings are rendered.
const ( // KeyMapShort renders the first enabled binding per group. KeyMapShort KeyMapMode = iota // KeyMapFull renders every enabled binding per group. KeyMapFull )
type KeyMapOptions ¶
type KeyMapOptions struct {
Width int
Mode KeyMapMode
}
KeyMapOptions configures grouped key map rendering.
type List ¶
type List struct {
// RenderRow renders one row for Layout(); set by the app. It receives the
// item index and whether it is the selected row.
RenderRow func(index int, selected bool) string
// contains filtered or unexported fields
}
List is selection-and-scroll state over a flat sequence of items. The app owns it (like TextField and Viewport): no goroutines, no key policy. It holds no item data and imposes no appearance — the app supplies the item count, drives the cursor, and renders each visible row through a callback, so the selection marker and styling stay app policy, never the framework's. Moving the selection keeps it inside the visible window; Scroll (a wheel) moves the window alone, and may leave the selection out of view until it next moves.
func (*List) Adopt ¶ added in v0.2.0
func (l *List) Adopt(event flatte.LayoutEvent, id string)
Adopt sizes the visible page from a LayoutEvent for the uniform-height rows returned by Rows. Native point geometry is used before cell rounding; terminal geometry is measured in cells. A partially clipped trailing row does not change the measured row height. A positive viewport always keeps at least one row, even when only part of it fits.
Call Adopt on every LayoutEvent. With no rows measured yet, it asks for one row so the next layout can measure it; normal layout settling adopts the full page before painting. A missing viewport leaves paging unchanged; a zero-height viewport adopts zero rows. Adopt changes no item data or selection policy beyond SetHeight's normal visible-selection preservation.
func (List) Layout ¶
Layout renders the visible rows via RenderRow as a single Text leaf. If RenderRow is unset, it renders nothing.
func (*List) MoveUp ¶
func (l *List) MoveUp()
MoveUp / MoveDown move the selection by one, keeping it visible.
func (List) Rows ¶ added in v0.2.0
Rows returns the visible rows as nodes, for a Frame.Root: row is called for each visible item index with whether it is the selected row, and each result is wrapped in a Row with ID "id:index" (so MouseEvent.Target names the clicked row) whose Box is marked Selected for the selected one (a GUI highlights it; the terminal shows only what row draws). The Col is the app's: give it an ID or a size (usually H: layout.Grow(1), sizing the list from its solved height) as needed. Adopt uses the ID of the list's viewport; the app must assign that ID to this Col or a containing viewport.
func (*List) Scroll ¶ added in v0.2.0
Scroll moves the visible window by rows (negative: up), clamped, leaving the selection where it is — for a mouse wheel.
func (*List) ScrollTo ¶ added in v0.2.0
ScrollTo shows the window starting at row offset (clamped), keeping the cursor inside it: a cursor scrolled out moves to the nearest visible row. For a scroll bar press or drag (layout.ScrollBar.OffsetAt).
func (*List) SetCount ¶
SetCount sets the number of selectable items, clamping the cursor and scroll; a visible selection stays visible.
func (*List) SetHeight ¶
SetHeight sets the number of visible rows, clamped to the supported widget dimension range; a visible selection stays visible.
type Paginator ¶
type Paginator struct {
// contains filtered or unexported fields
}
Paginator is app-owned page/range state. It owns no key policy; apps choose whether to bind arrows, h/l, PgUp/PgDn, or buttons.
func (*Paginator) NextPage ¶
func (p *Paginator) NextPage()
NextPage moves to the next page, clamped at the last page.
func (*Paginator) PrevPage ¶
func (p *Paginator) PrevPage()
PrevPage moves to the previous page, clamped at the first page.
func (Paginator) Range ¶
Range returns the half-open item index range [first, last) for the selected page. It returns 0, 0 when no page can be formed.
func (*Paginator) SelectPage ¶
SelectPage moves to page, clamped to the available page range.
func (*Paginator) SetPageSize ¶
SetPageSize sets the number of items per page, clamping the selected page.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress is a horizontal percentage indicator. The app owns the percentage and width; the widget only clamps values and renders a deterministic bar.
func NewProgress ¶
NewProgress returns a progress bar with the given fill width in cells.
func (Progress) Layout ¶
Layout returns the bar as a layout.Meter of the bar's width followed by the percentage label: View's text in the terminal, a native bar in a window. A zero-width bar is only the label, as in View.
func (*Progress) SetPercent ¶
SetPercent sets the fill percentage. Finite values outside 0..100 clamp; NaN normalizes to zero and infinities clamp to the corresponding endpoint.
func (*Progress) SetWidth ¶
SetWidth sets the fill bar width in cells. Values outside the supported 0..65,536 cell range clamp to the nearest endpoint.
func (Progress) View ¶
View renders the progress bar and a rounded percentage label. A zero-width bar still returns the label so compact layouts can show progress.
func (Progress) ViewWithStyle ¶
func (p Progress) ViewWithStyle(style ProgressStyle) string
type ProgressStyle ¶
ProgressStyle customizes Progress.ViewWithStyle. Zero-value styles render the same text without additional styling.
type Rect ¶
Rect is a cell-space rectangle: the same type the layout engine solves, so hit regions and solved geometry share one representation. X/Y are zero-based absolute frame coordinates; W/H must be positive to contain points.
type Select ¶ added in v0.2.0
type Select struct {
// contains filtered or unexported fields
}
Select is a dropdown: a choice among options, shown as a button, whose list opens under it. The app owns it (like List): it holds the options, the selected one, whether the list is open, and the highlighted option while it is; the app decides which keys open, move, choose, and close.
func (*Select) Click ¶ added in v0.2.0
Click handles a click whose target is the select laid out with id: on the button it toggles the list, on an option it chooses it. It reports whether the target was the select's.
func (*Select) Confirm ¶ added in v0.2.0
func (s *Select) Confirm()
Confirm chooses the highlighted option and closes the list.
func (Select) Highlighted ¶ added in v0.2.0
func (Select) IsOpen ¶ added in v0.2.0
IsOpen reports whether the list is open; Highlighted is the option highlighted in it.
func (Select) Layout ¶ added in v0.2.0
Layout returns the select as a Button with ID id showing the value and a disclosure mark ("[ English ▾ ]" in the terminal), and — while open — its list as a bordered overlay anchored under the button, whose rows have IDs "id:option:i" (the highlighted one marked "> " and Selected, the chosen one bold). Click maps clicks on either.
func (Select) LayoutWithButton ¶ added in v0.2.0
LayoutWithButton renders the dropdown using button's geometry, style, focus and other presentation fields. Its ID identifies both the trigger and the anchored popup (and is the id passed to Click). An empty Label uses the current value and disclosure mark. The supplied button is copied.
func (*Select) MoveUp ¶ added in v0.2.0
func (s *Select) MoveUp()
MoveUp and MoveDown move the highlight while the list is open.
func (*Select) Open ¶ added in v0.2.0
func (s *Select) Open()
Open shows the list with the selected option highlighted; Close hides it without choosing; Toggle does whichever applies.
func (Select) Selected ¶ added in v0.2.0
Selected is the selected option's index; Value its text ("" with none).
func (*Select) SetOptions ¶ added in v0.2.0
SetOptions sets the choices, keeping the selection in range.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner is a frame-cycling activity indicator. The app advances it — via flatte.Every or any other tick source on the loop goroutine — so the widget owns no goroutine and no timer, consistent with the rest of flatui. View returns the current frame.
func NewSpinner ¶
NewSpinner builds a Spinner over a copy of frames. With no frames, View returns "" and Tick is a no-op.
type Stopwatch ¶
type Stopwatch struct {
// contains filtered or unexported fields
}
Stopwatch is app-owned elapsed-time state. It owns no goroutine and no key policy; apps decide how ticks are produced and which keys start or stop it.
func NewStopwatch ¶
func NewStopwatch() Stopwatch
NewStopwatch returns a stopped stopwatch at zero elapsed time.
func (*Stopwatch) Reset ¶
func (s *Stopwatch) Reset()
Reset clears elapsed time and stops the stopwatch.
func (*Stopwatch) Start ¶
func (s *Stopwatch) Start()
Start makes subsequent Tick calls advance elapsed time.
type TabBar ¶
type TabBar struct {
Items []TabItem
// contains filtered or unexported fields
}
TabBar is a tab-strip component. Set colors once via WithColors, then compose it into a layout tree via Layout().
func (*TabBar) HitTest ¶
HitTest maps an absolute frame point to a tab index using solved geometry. In the normal (unbordered) mode it looks up each tab's own rect (recorded by a full-frame solve when WithID was set). When those per-tab rects are absent — the bordered mode renders one pre-composed leaf, and some callers only register the strip rect — it falls back to the strip rect plus the widget's private per-label width math. It does not mutate the bar; callers apply the returned index.
func (*TabBar) Layout ¶
Layout builds the tab strip as a Row of tabs. Each tab is a Row of its glyph caps — blank Icons, so the terminal draws them and a GUI leaves them out — around its label on the tab's fill with two columns of padding: the string render's cells in the terminal, flat filled segments in a window. The engine positions and sizes it; the widget computes no coordinates. When WithID was set, the strip and each tab carry IDs so a solve records their rects. A bordered strip is one Text leaf.
func (*TabBar) WithBorder ¶
func (t *TabBar) WithBorder(b TabBarBorder) *TabBar
func (*TabBar) WithGlyphs ¶
type TabBarBorder ¶
type TabBarBorder struct {
Style lipgloss.Border
Color color.Color
Top bool
Right bool
Bottom bool
Left bool
}
TabBarBorder customizes the border around a TabBar. Set any side to true to enable that side; Style defaults to lipgloss.InnerHalfBlockBorder().
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a columnar, row-selectable, vertically-scrolling grid. The app owns it (like the other flatui widgets): no goroutines, no key policy. Row selection and keep-visible scrolling are delegated to an embedded List; Table adds column alignment. Header and body are rendered separately so the app controls placement and styling; row appearance (selection marker/style) is the app's callback, so there is no policy in core.
func (Table) Cells ¶ added in v0.2.0
Cells returns a row's cells as Labels in style, each exactly its column's width (truncated or padded) and one column apart, so they line up in a proportional font too; it composes to the aligned text View renders. Missing cells are blank.
func (Table) HeaderLayout ¶ added in v0.2.0
HeaderLayout returns the column titles as a row of column-width Labels in style; it composes to Header's text.
func (Table) HeaderWithStyle ¶
func (t Table) HeaderWithStyle(style TableStyle) string
func (*Table) MoveUp ¶
func (t *Table) MoveUp()
MoveUp / MoveDown / Select move the selected row, keeping it visible.
func (Table) Rows ¶ added in v0.2.0
Rows returns the visible body rows as nodes, like List.Rows: row receives each visible row's cells (usually passed to Cells) and whether it is selected, and the result is wrapped in a Row with ID "id:index" whose Box is marked Selected for the selected row.
func (Table) SelectedRow ¶
SelectedRow returns the selected row's cells (nil when there are no rows).
func (*Table) SetColumns ¶
SetColumns sets the column titles and widths.
func (Table) View ¶
View returns the visible body rows, each aligned to the columns and passed through renderRow with whether it is the selected row. renderRow may be nil to render the aligned rows verbatim.
func (Table) ViewWithStyle ¶
func (t Table) ViewWithStyle(style TableStyle) string
type TableStyle ¶
TableStyle customizes Table styled rendering. Zero-value styles render the same text without additional styling.
type TextField ¶
TextField is a single-line editable string. Cursor is a byte offset into Value; the movement and edit methods keep it on a grapheme-cluster boundary so multi-rune clusters (combining marks, ZWJ emoji, regional-indicator flags) are treated as indivisible units and never split. SetCursor and the edit methods preserve the byte-offset API while normalizing offsets to grapheme boundaries; clampCursor additionally guards against a manually-set offset landing inside a UTF-8 rune.
func (*TextField) ClearSelection ¶
func (f *TextField) ClearSelection()
func (TextField) CursorColumn ¶
CursorColumn returns the cursor offset in display cells within the rendered value (wide runes count their terminal width, not their byte or rune count).
func (*TextField) DeleteToEnd ¶ added in v0.2.0
func (f *TextField) DeleteToEnd()
func (*TextField) DeleteToStart ¶ added in v0.2.0
func (f *TextField) DeleteToStart()
DeleteToStart and DeleteToEnd delete from the cursor to the start or end (or the selection, when there is one).
func (*TextField) DeleteWordLeft ¶
func (f *TextField) DeleteWordLeft()
func (*TextField) DeleteWordRight ¶
func (f *TextField) DeleteWordRight()
func (*TextField) Edit ¶ added in v0.2.0
Edit applies key as a native one-line text field does, and reports whether it was an editing key. It handles typing (replacing the selection), ←/→ (Shift selects, ⌥ or Ctrl by word, ⌘ to the start or end), Home/End (a window's ⌘←/⌘→), ⌫ and ⌦ (⌥ or Ctrl a word, ⌘ to the start or end), ⌘A, and the terminal's Ctrl+A/E/U/K/W and Alt+B/F/D. Everything else is the app's — Enter, Esc, Tab, ↑/↓, and copy, cut, and paste, which need the clipboard (SelectedText gives what to copy).
func (*TextField) HandleMouse ¶ added in v0.2.0
func (f *TextField) HandleMouse(id string, e flatte.MouseEvent) bool
HandleMouse applies pointer editing for the input laid out with id. It handles normal/Shift placement and drag, double-click word selection, triple-click SelectAll, and the native clear affordance. It reports whether the event belonged to this field. Apps still own focus policy.
func (*TextField) InsertText ¶ added in v0.2.0
InsertText inserts s at the cursor, replacing the selection. Newlines and carriage returns are dropped because TextField is single-line.
func (TextField) Layout ¶ added in v0.2.0
Layout returns the field as a layout.Input node with the given ID, showing the value, caret, and selection. focused is the app's focus decision: the focused Input's caret places the frame cursor.
func (*TextField) MoveEndSelecting ¶ added in v0.2.0
func (f *TextField) MoveEndSelecting()
func (*TextField) MoveLeftSelecting ¶
func (f *TextField) MoveLeftSelecting()
func (*TextField) MoveRightSelecting ¶
func (f *TextField) MoveRightSelecting()
func (*TextField) MoveStart ¶ added in v0.2.0
func (f *TextField) MoveStart()
MoveStart and MoveEnd put the cursor at the start or end of the value; the Selecting forms extend the selection there.
func (*TextField) MoveStartSelecting ¶ added in v0.2.0
func (f *TextField) MoveStartSelecting()
func (*TextField) MoveWordLeft ¶
func (f *TextField) MoveWordLeft()
func (*TextField) MoveWordLeftSelecting ¶
func (f *TextField) MoveWordLeftSelecting()
func (*TextField) MoveWordRight ¶
func (f *TextField) MoveWordRight()
func (*TextField) MoveWordRightSelecting ¶
func (f *TextField) MoveWordRightSelecting()
func (*TextField) SelectAll ¶ added in v0.2.0
func (f *TextField) SelectAll()
SelectAll selects the whole value, the cursor at its end.
func (TextField) SelectedText ¶
type TextPosition ¶
type TextRange ¶
type TextRange struct {
Start TextPosition
End TextPosition
}
type Textarea ¶
type Textarea struct {
// contains filtered or unexported fields
}
Textarea is a multi-line editable text buffer. The app owns it (like TextField): no goroutines, no key policy. Content is kept as logical lines; the cursor is a (row, byte-col) pair that the movement and edit methods keep on a grapheme-cluster boundary, so multi-rune clusters are never split. Vertical movement preserves a display "goal column"; the visible window scrolls to keep the cursor row in view. Width, when positive, horizontally scrolls long lines to keep the cursor cell visible unless soft-wrap is enabled.
func (*Textarea) ClearSelection ¶
func (t *Textarea) ClearSelection()
func (Textarea) CursorCell ¶
CursorCell is the cursor's display position relative to the visible window: x in display cells from the left of its line, y in rows from the top of the window. Pair with a frame origin to place Frame.Cursor.
func (*Textarea) DeleteWordLeft ¶
func (t *Textarea) DeleteWordLeft()
func (*Textarea) DeleteWordRight ¶
func (t *Textarea) DeleteWordRight()
func (*Textarea) Edit ¶ added in v0.2.0
Edit applies key as a native multi-line text area does, and reports whether it was an editing key. It handles typing (replacing the selection), arrows (Shift selects, Alt or Ctrl moves by word, Super moves to the line boundary), Home/End, Backspace/Delete (word or line with modifiers), Super+A, and the terminal's Ctrl+A/E/U/K/W. Enter, Escape, Tab, Up/Down, and clipboard chords remain app-owned.
func (*Textarea) InsertNewline ¶
func (t *Textarea) InsertNewline()
InsertNewline splits the current line at the cursor.
func (*Textarea) InsertText ¶ added in v0.2.0
InsertText inserts s at the cursor, replacing the selection: "\n" (and "\r\n" or "\r") break lines, so a paste lands as typed. The cursor ends after the inserted text.
func (Textarea) Layout ¶ added in v0.2.0
Layout returns the textarea as a multi-line layout.Input with the given ID: its value, cursor, selection, soft-wrap, and scroll. In the terminal it draws exactly what ViewWithSelection draws when the node is the textarea's size (set SelectionStyle for the look of the selection; zero is reverse video); a GUI draws a native text area. Size the textarea from the node's rect (LayoutEvent) so cursor movement and the node agree.
func (*Textarea) MoveDownSelecting ¶
func (t *Textarea) MoveDownSelecting()
func (*Textarea) MoveLeftSelecting ¶
func (t *Textarea) MoveLeftSelecting()
func (*Textarea) MoveLineEnd ¶
func (t *Textarea) MoveLineEnd()
func (*Textarea) MoveLineEndSelecting ¶
func (t *Textarea) MoveLineEndSelecting()
func (*Textarea) MoveLineStart ¶
func (t *Textarea) MoveLineStart()
func (*Textarea) MoveLineStartSelecting ¶
func (t *Textarea) MoveLineStartSelecting()
func (*Textarea) MoveRightSelecting ¶
func (t *Textarea) MoveRightSelecting()
func (*Textarea) MoveTo ¶ added in v0.2.0
MoveTo puts the cursor at byte offset into Value — clamped, and backed off to a grapheme boundary — and clears the selection: for a click (a MouseEvent's Caret) or a host's row move (a KeyEvent's Caret).
func (*Textarea) MoveToSelecting ¶ added in v0.2.0
MoveToSelecting is MoveTo extending the selection, for a drag or a selecting row move.
func (*Textarea) MoveUpSelecting ¶
func (t *Textarea) MoveUpSelecting()
func (*Textarea) MoveWordLeft ¶
func (t *Textarea) MoveWordLeft()
func (*Textarea) MoveWordLeftSelecting ¶
func (t *Textarea) MoveWordLeftSelecting()
func (*Textarea) MoveWordRight ¶
func (t *Textarea) MoveWordRight()
func (*Textarea) MoveWordRightSelecting ¶
func (t *Textarea) MoveWordRightSelecting()
func (*Textarea) SelectAll ¶ added in v0.2.0
func (t *Textarea) SelectAll()
SelectAll selects the whole value, with the cursor at its end.
func (Textarea) SelectedText ¶
func (Textarea) Selection ¶
Selection returns the selected logical range, normalized as [Start,End). Col values are byte offsets into their rows. The range is false when no non-empty selection is active.
func (*Textarea) SetSize ¶
SetSize sets the visible window. Width caps the columns View emits and drives horizontal scrolling; height caps the rows View emits and drives vertical scrolling.
func (*Textarea) SetSoftWrap ¶
SetSoftWrap controls whether View wraps long logical lines to the textarea width. Soft-wrap is opt-in; the default keeps long lines horizontally windowed.
func (*Textarea) SetValue ¶
SetValue replaces the content (split on newlines) and resets the cursor.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is app-owned countdown state. It owns no goroutine and no key policy; apps advance it from flatte.Every, tests, or any other loop-owned tick source.
func NewTimer ¶
NewTimer returns a countdown timer with the given duration. Non-positive durations are valid and start already done.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is expandable tree state. The app owns it and decides key policy, styling, and node data; Tree only tracks expansion, cursor, and scroll.
func (Tree) CursorID ¶
CursorID is the ID of the selected visible row, or "" when the tree is empty.
func (*Tree) MoveUp ¶
func (t *Tree) MoveUp()
MoveUp / MoveDown move the cursor by one visible row, keeping it visible.
func (Tree) Rows ¶ added in v0.2.0
Rows returns the visible window of rows as nodes, for a Frame.Root: row is called for each visible row with whether it is the cursor row, and each result is wrapped in a Row with ID "id:<node ID>" (stable as the tree expands, so MouseEvent.Target names the clicked node) whose Box is marked Selected for the cursor row. The Col is the app's to name and size.
func (*Tree) SelectVisible ¶
SelectVisible moves the cursor to the visible row index i.
func (*Tree) SetHeight ¶
SetHeight sets the number of visible rows, clamped to the supported widget dimension range.
func (*Tree) SetNodes ¶
SetNodes replaces the tree data, preserving expansion for IDs that still exist and still have children.
func (Tree) View ¶
View renders the visible window of rows. The app decides each row's marker, indentation, and styling through render.
func (Tree) VisibleRows ¶
VisibleRows returns all rows visible under the current expansion state.
type Viewport ¶
type Viewport struct {
// contains filtered or unexported fields
}
Viewport is a scrollable window over content. The app owns it (like TextField): no goroutines, no key policy. Feed it content with one of the Set* methods, size it with SetSize, scroll it with the movement methods (see below), and render the visible slice with View. View returns a plain string, so the widget works under alt-screen or inline rendering alike — the scroll model does not assume alt-screen.
func (*Viewport) Adopt ¶ added in v0.2.0
Adopt sizes the viewport from rects[id] — the space the app gave it, an ID'd node holding Layout() — and scrolls over as many lines as the host laid the content out in, which a window that wraps in its font can make more or fewer than the viewport's own: the offset range, TotalLines, AtBottom, and ScrollPercent follow the host. Call it with every LayoutEvent's rects instead of SetSize. A viewport sent to the bottom (GotoBottom, or scrolled there) stays at the bottom as lines come and go.
func (*Viewport) GotoBottom ¶
func (v *Viewport) GotoBottom()
func (*Viewport) GotoTop ¶
func (v *Viewport) GotoTop()
GotoTop/GotoBottom jump to the first/last window.
func (*Viewport) HalfPageDown ¶
func (v *Viewport) HalfPageDown()
HalfPageDown/Up and PageDown/Up scroll by half / a full visible window.
func (*Viewport) HalfPageUp ¶
func (v *Viewport) HalfPageUp()
func (Viewport) Layout ¶
Layout returns the viewport as a layout.Scroll over all its lines, offset to the current top line and as tall as the visible slice (and as wide as the viewport's width, when set): View's text in the terminal, scrolled in points in a window. Plain lines are a Label, drawn natively in a window — for wrapped content, a wrapping Label of the raw text, so a window wraps it in its font; lines with escape sequences are a Text of cells.
func (Viewport) ScrollPercent ¶
ScrollPercent is the fraction scrolled, 0.0 at top to 1.0 at bottom. When all content fits (nothing to scroll), it reports 1.0.
func (*Viewport) ScrollToLine ¶
ScrollToLine positions the window so line i is at the top (clamped).
func (*Viewport) SetContent ¶
SetContent splits content on newlines and windows it without wrapping; long lines are clipped at the viewport width on render.
func (*Viewport) SetLines ¶
SetLines sets pre-laid-out lines verbatim: no splitting, no wrapping. Lines wider than the viewport are clipped at its width on render.
func (*Viewport) SetSize ¶
SetSize sets the visible window dimensions. Width drives wrapping and clipping; height caps the number of rows View emits.
func (*Viewport) SetWrappedContent ¶
SetWrappedContent splits content on newlines and wraps each line by words to the viewport width (a word wider than the width breaks) — ANSI- and display-width-aware, so SGR styles and wide runes are never split. Re-wraps automatically when the width changes via SetSize. If the width is not yet known, the wrap is deferred until SetSize provides one.
func (Viewport) TotalLines ¶
TotalLines is the number of content lines after ingestion/wrapping — as the host laid them out, once adopted (see Adopt).
func (Viewport) View ¶
View returns the visible slice joined by newlines. Lines wider than the width are clipped (a no-op for already-wrapped content). Lines are not padded to the width or the height — the caller owns the surrounding frame.
func (Viewport) VisibleLines ¶
VisibleLines is how many content rows View currently emits.
type ZoneMap ¶
type ZoneMap struct {
// contains filtered or unexported fields
}
ZoneMap stores app-measured hit regions. It does not scan rendered output or own input policy; apps register rectangles from their layout calculations.
func (ZoneMap) At ¶
At returns the topmost registered zone at x,y. Later Set calls take priority when rectangles overlap.
func (ZoneMap) Local ¶
Local converts absolute x,y to coordinates relative to id's registered rectangle.
type ZoneScanner
deprecated
type ZoneScanner struct {
// contains filtered or unexported fields
}
ZoneScanner maps named rectangles to hit regions. Rects are fed from solved layout geometry via Set — the blessed render path composites through a cell buffer, which drops any inline string markers, so zones are always derived from coordinates rather than scanned out of rendered output.
Deprecated: use ZoneMap for new code.
func NewZoneScanner ¶
func NewZoneScanner() *ZoneScanner
func (ZoneScanner) At ¶
func (z ZoneScanner) At(x, y int) (string, bool)
At returns the last-inserted zone containing x,y. Later Set calls for new ids take priority when rectangles overlap.
func (*ZoneScanner) Reset ¶
func (z *ZoneScanner) Reset()
Reset clears all zones. Use before repopulating from geometry each frame.
func (*ZoneScanner) Set ¶
func (z *ZoneScanner) Set(id string, r Rect)
Set registers id at rect r, replacing any existing rect for id. A re-Set does not change hit priority; the original insertion order is preserved so At stays stable across frames.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
textedit
Package textedit lays out editable text in terminal cells: soft wrapping by grapheme clusters, horizontal windows, selection runs, and the scroll that keeps a cursor visible.
|
Package textedit lays out editable text in terminal cells: soft wrapping by grapheme clusters, horizontal windows, selection runs, and the scroll that keeps a cursor visible. |
|
Package layout is a flexbox-style layout and composition engine for Flatte.
|
Package layout is a flexbox-style layout and composition engine for Flatte. |