flatui

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 11 Imported by: ? 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

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var TabGlyphsPowerline = TabGlyphs{Left: "\ue0ba", Right: "\ue0bc"}
View Source
var TabGlyphsSafe = TabGlyphs{Left: "[", Right: "]"}

Functions

func Card

func Card(lines []string, maxWidth int) string

func CardBodyHeight

func CardBodyHeight(totalHeight, pinnedRows int) int

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

func CardBodyWidth(totalWidth int) int

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 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 CardWithStyle

func CardWithStyle(lines []string, maxWidth int, style CardStyle) string

func ContentWidth

func ContentWidth(totalWidth int) int

func FrameWidth

func FrameWidth(maxWidth int, lines []string) int

func Overlay

func Overlay(base string, layer string) string

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

func OverlayOrigin(base, layer string) (x, y int)

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.

func Subtle

func Subtle(text string) string

func SubtleWithStyle

func SubtleWithStyle(text string, style lipgloss.Style) string

func Title

func Title(text string) string

func TitleWithStyle

func TitleWithStyle(text string, style lipgloss.Style) string

Types

type CardStyle

type CardStyle struct {
	Container        lipgloss.Style
	BorderForeground color.Color
}

CardStyle customizes CardWithStyle. Zero fields use Card's defaults.

type Column

type Column struct {
	Title string
	Width int
}

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) Count

func (f FocusRing) Count() int

Count is the number of focusable regions.

func (FocusRing) Focused

func (f FocusRing) Focused(i int) bool

Focused reports whether i is the focused index.

func (FocusRing) Index

func (f FocusRing) Index() int

Index is the focused index, or 0 when the ring is empty.

func (*FocusRing) Next

func (f *FocusRing) Next()

Next moves focus forward, wrapping at the end.

func (*FocusRing) Prev

func (f *FocusRing) Prev()

Prev moves focus backward, wrapping at the beginning.

func (*FocusRing) Select

func (f *FocusRing) Select(i int)

Select focuses index i, clamped to the available region count.

func (*FocusRing) SetCount

func (f *FocusRing) SetCount(n int)

SetCount sets the number of focusable regions, clamping the focused index.

type KeyBinding

type KeyBinding struct {
	Keys     []string
	Help     string
	Disabled bool
}

KeyBinding is display metadata for a command binding. It is not input policy: apps still decide how terminal events map to behavior.

type KeyGroup

type KeyGroup struct {
	Title    string
	Bindings KeyMap
}

KeyGroup is a named group of command binding metadata.

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.

func (KeyMap) View

func (m KeyMap) View() string

View renders enabled bindings as "keys help" pairs separated by two spaces.

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. The selected row is always kept inside the visible window.

func (List) Count

func (l List) Count() int

Count is the number of items.

func (List) Cursor

func (l List) Cursor() int

Cursor is the selected index (0 when empty).

func (List) Height

func (l List) Height() int

Height returns the number of visible rows the list was sized to via SetHeight.

func (List) Layout

func (l List) Layout() layout.Node

Layout renders the visible rows via RenderRow as a single Text leaf. If RenderRow is unset, it renders nothing.

func (*List) MoveDown

func (l *List) MoveDown()

func (*List) MoveUp

func (l *List) MoveUp()

MoveUp / MoveDown move the selection by one, keeping it visible.

func (List) Offset

func (l List) Offset() int

Offset is the index of the first visible row (for tests and indicators).

func (*List) Select

func (l *List) Select(i int)

Select moves the selection to index i (clamped), keeping it visible.

func (*List) SetCount

func (l *List) SetCount(n int)

SetCount sets the number of selectable items, clamping the cursor and scroll.

func (*List) SetHeight

func (l *List) SetHeight(h int)

SetHeight sets the number of visible rows.

func (List) View

func (l List) View(render func(index int, selected bool) string) string

View renders the visible rows: render is called for each visible item index with whether it is the selected row, and the results are joined by newlines. The app decides each row's appearance (marker, styling, truncation).

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) Page

func (p Paginator) Page() int

Page is the selected zero-based page index, or 0 when there are no pages.

func (Paginator) PageSize

func (p Paginator) PageSize() int

PageSize is the number of items per page.

func (Paginator) Pages

func (p Paginator) Pages() int

Pages is the number of pages needed to display Total items at PageSize.

func (*Paginator) PrevPage

func (p *Paginator) PrevPage()

PrevPage moves to the previous page, clamped at the first page.

func (Paginator) Range

func (p Paginator) Range() (first, last int)

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

func (p *Paginator) SelectPage(page int)

SelectPage moves to page, clamped to the available page range.

func (*Paginator) SetPageSize

func (p *Paginator) SetPageSize(n int)

SetPageSize sets the number of items per page, clamping the selected page.

func (*Paginator) SetTotal

func (p *Paginator) SetTotal(n int)

SetTotal sets the total number of items, clamping the selected page.

func (Paginator) Total

func (p Paginator) Total() int

Total is the total number of items.

func (Paginator) View

func (p Paginator) View() string

View renders a compact page indicator for 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

func NewProgress(width int) Progress

NewProgress returns a progress bar with the given fill width in cells.

func (Progress) Layout

func (p Progress) Layout() layout.Node

Layout renders the bar as a single Text leaf for composition.

func (Progress) Percent

func (p Progress) Percent() float64

Percent returns the clamped percentage.

func (*Progress) SetPercent

func (p *Progress) SetPercent(percent float64)

SetPercent sets the fill percentage. Values outside 0..100 clamp.

func (*Progress) SetWidth

func (p *Progress) SetWidth(width int)

SetWidth sets the fill bar width in cells. Negative widths clamp to zero.

func (Progress) View

func (p Progress) View() string

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

func (Progress) Width

func (p Progress) Width() int

Width returns the bar width in cells.

type ProgressStyle

type ProgressStyle struct {
	Filled lipgloss.Style
	Empty  lipgloss.Style
	Label  lipgloss.Style
}

ProgressStyle customizes Progress.ViewWithStyle. Zero-value styles render the same text without additional styling.

type Rect

type Rect = layout.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 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

func NewSpinner(frames []string) Spinner

NewSpinner builds a Spinner over a copy of frames. With no frames, View returns "" and Tick is a no-op.

func (Spinner) Frame

func (s Spinner) Frame() int

Frame returns the current frame index (for tests and indicators).

func (*Spinner) Tick

func (s *Spinner) Tick()

Tick advances to the next frame, wrapping at the end.

func (Spinner) View

func (s Spinner) View() string

View returns the current frame ("" when there are no frames).

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) Elapsed

func (s Stopwatch) Elapsed() time.Duration

Elapsed returns elapsed stopwatch time.

func (*Stopwatch) Reset

func (s *Stopwatch) Reset()

Reset clears elapsed time and stops the stopwatch.

func (Stopwatch) Running

func (s Stopwatch) Running() bool

Running reports whether Tick currently advances elapsed time.

func (*Stopwatch) Start

func (s *Stopwatch) Start()

Start makes subsequent Tick calls advance elapsed time.

func (*Stopwatch) Stop

func (s *Stopwatch) Stop()

Stop pauses elapsed time.

func (*Stopwatch) Tick

func (s *Stopwatch) Tick(delta time.Duration)

Tick advances elapsed time only while the stopwatch is running. Negative deltas are ignored.

func (*Stopwatch) Toggle

func (s *Stopwatch) Toggle()

Toggle switches between running and stopped.

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 NewTabBar

func NewTabBar(items ...TabItem) *TabBar

func (*TabBar) Active

func (t *TabBar) Active() int

func (*TabBar) ActiveID

func (t *TabBar) ActiveID() string

func (*TabBar) HitTest

func (t *TabBar) HitTest(rects map[string]layout.Rect, x, y int) (int, bool)

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

func (t *TabBar) Layout() layout.Node

Layout builds the tab strip as a Row of styled Text leaves. 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.

func (*TabBar) Next

func (t *TabBar) Next()

func (*TabBar) Prev

func (t *TabBar) Prev()

func (*TabBar) SetActive

func (t *TabBar) SetActive(i int)

func (*TabBar) WithBorder

func (t *TabBar) WithBorder(b TabBarBorder) *TabBar

func (*TabBar) WithColors

func (t *TabBar) WithColors(f, i, bg color.Color) *TabBar

func (*TabBar) WithGlyphs

func (t *TabBar) WithGlyphs(g TabGlyphs) *TabBar

func (*TabBar) WithID

func (t *TabBar) WithID(id string) *TabBar

WithID gives the tab strip a layout ID. When set, Layout tags the strip node with id and each tab leaf with id+":"+item.ID, so a full-frame solve records per-tab rects that HitTest can look up. Leave unset for decorative strips.

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 TabGlyphs

type TabGlyphs struct{ Left, Right string }

type TabItem

type TabItem struct {
	ID    string
	Label string
}

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) Cursor

func (t Table) Cursor() int

Cursor is the selected row index.

func (Table) Header

func (t Table) Header() string

Header returns the aligned header row.

func (Table) HeaderWithStyle

func (t Table) HeaderWithStyle(style TableStyle) string

func (*Table) MoveDown

func (t *Table) MoveDown()

func (*Table) MoveUp

func (t *Table) MoveUp()

MoveUp / MoveDown / Select move the selected row, keeping it visible.

func (*Table) Select

func (t *Table) Select(i int)

func (Table) SelectedRow

func (t Table) SelectedRow() []string

SelectedRow returns the selected row's cells (nil when there are no rows).

func (*Table) SetColumns

func (t *Table) SetColumns(cols []Column)

SetColumns sets the column titles and widths.

func (*Table) SetHeight

func (t *Table) SetHeight(h int)

SetHeight sets the number of visible body rows (excluding the header).

func (*Table) SetRows

func (t *Table) SetRows(rows [][]string)

SetRows sets the row data and updates the selection bounds.

func (Table) View

func (t Table) View(renderRow func(text string, selected bool) string) string

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

type TableStyle struct {
	Header lipgloss.Style
	Row    lipgloss.Style
	Active lipgloss.Style
}

TableStyle customizes Table styled rendering. Zero-value styles render the same text without additional styling.

type TextField

type TextField struct {
	Value  string
	Cursor int
	// contains filtered or unexported fields
}

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. clampCursor additionally guards against a manually-set offset landing inside a UTF-8 rune.

func (*TextField) Backspace

func (f *TextField) Backspace()

func (*TextField) ClearSelection

func (f *TextField) ClearSelection()

func (TextField) CursorColumn

func (f TextField) CursorColumn() int

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) Delete

func (f *TextField) Delete()

func (*TextField) DeleteWordLeft

func (f *TextField) DeleteWordLeft()

func (*TextField) DeleteWordRight

func (f *TextField) DeleteWordRight()

func (*TextField) Insert

func (f *TextField) Insert(r rune)

func (*TextField) MoveLeft

func (f *TextField) MoveLeft()

func (*TextField) MoveLeftSelecting

func (f *TextField) MoveLeftSelecting()

func (*TextField) MoveRight

func (f *TextField) MoveRight()

func (*TextField) MoveRightSelecting

func (f *TextField) MoveRightSelecting()

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) SelectedText

func (f TextField) SelectedText() string

func (TextField) Selection

func (f TextField) Selection() (start, end int, ok bool)

Selection returns the selected byte range, normalized as [start,end). The range is false when no non-empty selection is active.

func (*TextField) SetCursor

func (f *TextField) SetCursor(cursor int)

type TextPosition

type TextPosition struct {
	Row int
	Col int
}

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) Backspace

func (t *Textarea) Backspace()

func (*Textarea) ClearSelection

func (t *Textarea) ClearSelection()

func (Textarea) Col

func (t Textarea) Col() int

func (Textarea) CursorCell

func (t Textarea) CursorCell() (x, y int)

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) Delete

func (t *Textarea) Delete()

func (*Textarea) DeleteWordLeft

func (t *Textarea) DeleteWordLeft()

func (*Textarea) DeleteWordRight

func (t *Textarea) DeleteWordRight()

func (*Textarea) Insert

func (t *Textarea) Insert(r rune)

func (*Textarea) InsertNewline

func (t *Textarea) InsertNewline()

InsertNewline splits the current line at the cursor.

func (*Textarea) MoveDown

func (t *Textarea) MoveDown()

func (*Textarea) MoveDownSelecting

func (t *Textarea) MoveDownSelecting()

func (*Textarea) MoveLeft

func (t *Textarea) MoveLeft()

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) MoveRight

func (t *Textarea) MoveRight()

func (*Textarea) MoveRightSelecting

func (t *Textarea) MoveRightSelecting()

func (*Textarea) MoveUp

func (t *Textarea) MoveUp()

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) Offset

func (t Textarea) Offset() int

Offset is the index of the first visible line.

func (Textarea) Row

func (t Textarea) Row() int

Row and Col expose the cursor position (line index, byte offset) for tests.

func (Textarea) SelectedText

func (t Textarea) SelectedText() string

func (Textarea) Selection

func (t Textarea) Selection() (TextRange, bool)

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

func (t *Textarea) SetSize(width, height int)

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

func (t *Textarea) SetSoftWrap(enabled bool)

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

func (t *Textarea) SetValue(s string)

SetValue replaces the content (split on newlines) and resets the cursor.

func (Textarea) SoftWrap

func (t Textarea) SoftWrap() bool

SoftWrap reports whether visual soft-wrapping is enabled.

func (Textarea) Value

func (t Textarea) Value() string

Value returns the content joined by newlines.

func (Textarea) View

func (t Textarea) View() string

View returns the visible lines joined by newlines (windowed to height).

func (Textarea) ViewWithSelection

func (t Textarea) ViewWithSelection(render func(text string, selected bool) string) string

ViewWithSelection renders the visible textarea window and calls render for selected and unselected runs. The callback owns style policy.

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

func NewTimer(duration time.Duration) Timer

NewTimer returns a countdown timer with the given duration. Non-positive durations are valid and start already done.

func (Timer) Done

func (t Timer) Done() bool

Done reports whether the countdown has reached its duration.

func (Timer) Duration

func (t Timer) Duration() time.Duration

Duration returns the configured countdown duration.

func (Timer) Elapsed

func (t Timer) Elapsed() time.Duration

Elapsed returns the elapsed countdown time, clamped to Duration.

func (Timer) Percent

func (t Timer) Percent() float64

Percent returns elapsed countdown progress from 0 to 100.

func (Timer) Remaining

func (t Timer) Remaining() time.Duration

Remaining returns the time left until Done.

func (*Timer) Reset

func (t *Timer) Reset()

Reset restarts the countdown with its existing duration.

func (*Timer) Tick

func (t *Timer) Tick(delta time.Duration)

Tick advances elapsed countdown time. Negative deltas are ignored.

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 NewTree

func NewTree(nodes []TreeNode) Tree

NewTree returns a tree with the given nodes.

func (Tree) CursorID

func (t Tree) CursorID() string

CursorID is the ID of the selected visible row, or "" when the tree is empty.

func (*Tree) MoveDown

func (t *Tree) MoveDown()

func (*Tree) MoveUp

func (t *Tree) MoveUp()

MoveUp / MoveDown move the cursor by one visible row, keeping it visible.

func (Tree) Offset

func (t Tree) Offset() int

Offset is the index of the first visible row.

func (*Tree) SelectVisible

func (t *Tree) SelectVisible(i int)

SelectVisible moves the cursor to the visible row index i.

func (*Tree) SetHeight

func (t *Tree) SetHeight(h int)

SetHeight sets the number of visible rows.

func (*Tree) SetNodes

func (t *Tree) SetNodes(nodes []TreeNode)

SetNodes replaces the tree data, preserving expansion for IDs that still exist and still have children.

func (*Tree) Toggle

func (t *Tree) Toggle(id string)

Toggle expands or collapses the node with id. Unknown and leaf IDs are no-op.

func (Tree) View

func (t Tree) View(render func(row TreeRow, selected bool) string) string

View renders the visible window of rows. The app decides each row's marker, indentation, and styling through render.

func (Tree) VisibleRows

func (t Tree) VisibleRows() []TreeRow

VisibleRows returns all rows visible under the current expansion state.

type TreeNode

type TreeNode struct {
	ID       string
	Label    string
	Children []TreeNode
}

TreeNode is one node in an app-owned tree.

type TreeRow

type TreeRow struct {
	ID         string
	Label      string
	Depth      int
	Expandable bool
	Expanded   bool
}

TreeRow is a visible tree row after expansion state has been applied.

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) AtBottom

func (v Viewport) AtBottom() bool

func (Viewport) AtTop

func (v Viewport) AtTop() bool

AtTop / AtBottom report whether the window is at an extreme.

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

func (v Viewport) Layout() layout.Node

Layout renders the visible slice as a single Text leaf for composition.

func (*Viewport) LineDown

func (v *Viewport) LineDown(n int)

LineDown scrolls down by n lines (clamped). LineUp scrolls up.

func (*Viewport) LineUp

func (v *Viewport) LineUp(n int)

func (Viewport) Offset

func (v Viewport) Offset() int

Offset is the current top-line index.

func (*Viewport) PageDown

func (v *Viewport) PageDown()

func (*Viewport) PageUp

func (v *Viewport) PageUp()

func (Viewport) ScrollPercent

func (v Viewport) ScrollPercent() float64

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

func (v *Viewport) ScrollToLine(i int)

ScrollToLine positions the window so line i is at the top (clamped).

func (*Viewport) SetContent

func (v *Viewport) SetContent(content string)

SetContent splits content on newlines and windows it without wrapping; long lines are clipped at the viewport width on render.

func (*Viewport) SetLines

func (v *Viewport) SetLines(lines []string)

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

func (v *Viewport) SetSize(width, height int)

SetSize sets the visible window dimensions. Width drives wrapping and clipping; height caps the number of rows View emits.

func (*Viewport) SetWrappedContent

func (v *Viewport) SetWrappedContent(content string)

SetWrappedContent splits content on newlines and soft-wraps each line to the viewport width — 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

func (v Viewport) TotalLines() int

TotalLines is the number of content lines after ingestion/wrapping.

func (Viewport) View

func (v Viewport) View() string

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

func (v Viewport) VisibleLines() int

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

func (z ZoneMap) At(x, y int) (string, bool)

At returns the topmost registered zone at x,y. Later Set calls take priority when rectangles overlap.

func (*ZoneMap) Clear

func (z *ZoneMap) Clear()

Clear removes every registered zone.

func (ZoneMap) In

func (z ZoneMap) In(id string, x, y int) bool

In reports whether x,y falls inside id's registered rectangle.

func (ZoneMap) Local

func (z ZoneMap) Local(id string, x, y int) (localX, localY int, ok bool)

Local converts absolute x,y to coordinates relative to id's registered rectangle.

func (ZoneMap) Rect

func (z ZoneMap) Rect(id string) (Rect, bool)

Rect returns the rectangle registered for id.

func (*ZoneMap) Set

func (z *ZoneMap) Set(id string, rect Rect)

Set registers or replaces a zone rectangle. Replacing an existing zone moves it to the front of hit priority.

type ZoneScanner

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.

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) In

func (z ZoneScanner) In(id string, x, y int) bool

func (ZoneScanner) Rect

func (z ZoneScanner) Rect(id string) (Rect, bool)

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.

Directories

Path Synopsis
Package layout is a flexbox-style layout engine for Flatte.
Package layout is a flexbox-style layout engine for Flatte.

Jump to

Keyboard shortcuts

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