Documentation
¶
Index ¶
- Constants
- Variables
- func AcceptInteger(r rune) bool
- func AcceptNumber(r rune) bool
- func AdjustScroll(cursor, scroll, visible, total int) int
- func BreakpointH(w int, breakpoints ...int) int
- func BreakpointV(h int, breakpoints ...int) int
- func CalculateColumnWidths(availableW int, headers []string, rows [][]string, opts TableOpts) []int
- func ClampCursor(cursor, total int) int
- func ClampScroll(scroll, visible, total int) int
- func Columns(availableW, itemW, gap int) int
- func DividerPositions(regionW, n, gap int) []int
- func ExpandIconRune(expanded bool) rune
- func FindFirstChildIndex(nodes []TreeNode, idx int) int
- func FindNextSiblingIndex(nodes []TreeNode, idx int) int
- func FindParentIndex(nodes []TreeNode, idx int) int
- func FindPrevSiblingIndex(nodes []TreeNode, idx int) int
- func FitOrScroll(contentH, availableH int) bool
- func FormatCoverageSuffix(count, total int) string
- func HDividerPositions(regionH, n, gap int) []int
- func PadCenter(s string, width int) string
- func PadLeft(s string, width int) string
- func PadRight(s string, width int) string
- func PageDelta(visible int) int
- func RepeatRune(r rune, n int) string
- func RuneLen(s string) int
- func ScrollPercent(scroll, visible, total int) int
- func StepChoice(key terminal.Key, r rune, chosen, n int) (int, bool)
- func Truncate(s string, maxLen int) string
- func TruncateLeft(s string, maxLen int) string
- func TruncateMiddle(s string, maxLen int) string
- func WrapText(s string, width int) []string
- type AlertOpts
- type Align
- type BarAlign
- type BarOpts
- type BarSection
- type BarStyle
- type Button
- type ButtonBarOpts
- type ButtonStyle
- type CheckState
- type ConfirmOpts
- type ConfirmResult
- type ConfirmState
- type ConfirmStyle
- type Coverage
- type DocBlock
- type DocKind
- type DocOpts
- type DocState
- type EditorOpts
- type EditorState
- func (e *EditorState) AdjustScroll(viewportW, viewportH int)
- func (e *EditorState) Clear()
- func (e *EditorState) CurrentLine() string
- func (e *EditorState) DeleteBackward() bool
- func (e *EditorState) DeleteForward() bool
- func (e *EditorState) DeleteLine() bool
- func (e *EditorState) DeleteToEndOfLine() bool
- func (e *EditorState) DeleteToStartOfLine() bool
- func (e *EditorState) DeleteWordBackward() bool
- func (e *EditorState) DeleteWordForward() bool
- func (e *EditorState) HandleKey(key terminal.Key, r rune, mod terminal.Modifier) bool
- func (e *EditorState) Insert(r rune)
- func (e *EditorState) InsertNewline()
- func (e *EditorState) InsertString(s string)
- func (e *EditorState) LineCount() int
- func (e *EditorState) MoveDown()
- func (e *EditorState) MoveLeft()
- func (e *EditorState) MoveRight()
- func (e *EditorState) MoveToEnd()
- func (e *EditorState) MoveToLineEnd()
- func (e *EditorState) MoveToLineStart()
- func (e *EditorState) MoveToStart()
- func (e *EditorState) MoveUp()
- func (e *EditorState) MoveWordLeft()
- func (e *EditorState) MoveWordRight()
- func (e *EditorState) PageDown()
- func (e *EditorState) PageUp()
- func (e *EditorState) SetValue(s string)
- func (e *EditorState) Value() string
- type EditorStyle
- type Field
- type Focus
- type FormField
- type FormOpts
- type FormState
- func (f *FormState) Clear()
- func (f *FormState) CurrentField() *TextFieldState
- func (f *FormState) FocusNext()
- func (f *FormState) FocusPrev()
- func (f *FormState) HandleKey(key terminal.Key, r rune, mod terminal.Modifier) bool
- func (f *FormState) SetValue(idx int, val string)
- func (f *FormState) Value(idx int) string
- type FormStyle
- type Glyphs
- type InputOpts
- type LineType
- type ListItem
- type ListOpts
- type MasonryItem
- type MasonryLayout
- type MasonryOpts
- type MasonryRenderFunc
- type MasonryState
- type ModalOpts
- type Option
- type OptionListState
- type OverlayOpts
- type OverlayResult
- type OverlayState
- type OverlayStyle
- type PaneOpts
- type ProgressOverlayOpts
- type ProgressState
- type ProgressStyle
- type ProgressType
- type Region
- func Center(outer Region, w, h int) Region
- func GridLayout(r Region, cols, rows, gapX, gapY int) []Region
- func NewRegion(cells []terminal.Cell, totalW, x, y, w, h int) Region
- func SplitH(r Region, ratios ...float64) []Region
- func SplitHEqual(r Region, n, gap int) []Region
- func SplitHFixed(r Region, leftW int) (left, right Region)
- func SplitV(r Region, ratios ...float64) []Region
- func SplitVEqual(r Region, n, gap int) []Region
- func SplitVFixed(r Region, topH int) (top, bottom Region)
- func (r Region) AlertDialog(opts AlertOpts) Region
- func (r Region) Bounds() (x, y, w, h int)
- func (r Region) Box(line LineType, fg color.RGB)
- func (r Region) BoxClipped(line LineType, fg color.RGB, totalH, off int)
- func (r Region) BoxFilled(line LineType, fg, bg color.RGB)
- func (r Region) ButtonBar(y int, buttons []Button, opts ButtonBarOpts)
- func (r Region) Card(title string, line LineType, fg color.RGB) Region
- func (r Region) Cell(x, y int, ch rune, fg, bg color.RGB, attr terminal.Attr)
- func (r Region) CellOpaque(x, y int, ch rune, fg, bg color.RGB, attr terminal.Attr)
- func (r Region) Checkbox(x, y int, state CheckState, fg color.RGB)
- func (r Region) Choice(x, y int, options []string, chosen int, th Theme) int
- func (r Region) Clear()
- func (r Region) ConfirmDialog(state *ConfirmState, opts ConfirmOpts) Region
- func (r Region) Divider(y int, label string, line LineType, fg color.RGB)
- func (r Region) Doc(d *DocState, opts DocOpts)
- func (r Region) Editor(state *EditorState, opts EditorOpts) int
- func (r Region) Field(y, labelW int, f Field, focused bool, th Theme) (Region, int)
- func (r Region) Fill(bg color.RGB)
- func (r Region) FillStyle(s Style)
- func (r Region) Form(state *FormState, opts FormOpts) int
- func (r Region) Gauge(x, y, w int, value, max int, fg, bg color.RGB)
- func (r Region) Group(y int, title, summary string, open, focused bool, th Theme)
- func (r Region) HLine(y int, line LineType, fg color.RGB)
- func (r Region) Height() int
- func (r Region) Input(y int, opts InputOpts)
- func (r Region) Inset(n int) Region
- func (r Region) KeyValue(y int, key, value string, keyStyle, valStyle Style, sep rune)
- func (r Region) KeyValueColumn(y, keyW int, key, value string, keyStyle, valStyle Style, sep rune)
- func (r Region) KeyValueWrap(y int, key, value string, keyStyle, valStyle Style, sep rune) int
- func (r Region) List(items []ListItem, cursor, scroll int, opts ListOpts) int
- func (r Region) Masonry(state *MasonryState, render MasonryRenderFunc)
- func (r Region) MeasureKeyValueWrap(key, value string) int
- func (r Region) Modal(opts ModalOpts) Region
- func (r Region) OptionList(s *OptionListState, th Theme)
- func (r Region) Overlay(opts OverlayOpts) OverlayResult
- func (r Region) Pane(opts PaneOpts) Region
- func (r Region) Progress(x, y, w int, pct float64, fg, bg color.RGB)
- func (r Region) ProgressOverlay(opts ProgressOverlayOpts) Region
- func (r Region) ProgressV(x, y, h int, pct float64, fg, bg color.RGB)
- func (r Region) QuickStatusBar(y int, pairs [][2]string, labelFg, valueFg, bg color.RGB)
- func (r Region) ScrollBar(x int, offset, visible, total int, fg color.RGB)
- func (r Region) ScrollBarStyled(x int, offset, visible, total int, opts ScrollBarOpts)
- func (r Region) ScrollIndicator(y int, offset, visible, total int, fg color.RGB)
- func (r Region) Sparkline(x, y, width int, values []float64, opts SparklineOpts)
- func (r Region) SparklineV(x, y, height int, values []float64, opts SparklineOpts)
- func (r Region) Spinner(x, y int, frame int, fg color.RGB)
- func (r Region) StatusBar(y int, sections []BarSection, opts BarOpts)
- func (r Region) Sub(x, y, w, h int) Region
- func (r Region) TabBar(y int, titles []string, active int, opts TabBarOpts) []TabBounds
- func (r Region) TabBarCentered(y int, titles []string, active int, opts TabBarOpts) []TabBounds
- func (r Region) Table(headers []string, rows [][]string, opts TableOpts)
- func (r Region) Text(x, y int, s string, fg, bg color.RGB, attr terminal.Attr)
- func (r Region) TextBlock(x, y int, text string, fg, bg color.RGB, attr terminal.Attr) int
- func (r Region) TextBlockStyled(x, y int, text string, style Style) int
- func (r Region) TextCenter(y int, s string, fg, bg color.RGB, attr terminal.Attr)
- func (r Region) TextField(state *TextFieldState, opts TextFieldOpts) int
- func (r Region) TextInput(state *TextFieldState, placeholder string, focused bool, th Theme)
- func (r Region) TextRight(y int, s string, fg, bg color.RGB, attr terminal.Attr)
- func (r Region) TextStyled(x, y int, s string, style Style)
- func (r Region) TitledPane(title string, titleFg, bg color.RGB) Region
- func (r Region) TitledPaneFocused(title string, titleFg, bg, focusBg color.RGB, focused bool) Region
- func (r Region) Toast(opts ToastOpts) Region
- func (r Region) Toggle(x, y int, on bool, th Theme) int
- func (r Region) Tree(nodes []TreeNode, cursor, scroll int, opts TreeOpts) int
- func (r Region) VLine(x int, line LineType, fg color.RGB)
- func (r Region) Width() int
- type ScrollBarOpts
- type ScrollState
- func (s *ScrollState) AtBottom() bool
- func (s *ScrollState) AtTop() bool
- func (s *ScrollState) Clamp()
- func (s *ScrollState) EnsureVisible(pos int)
- func (s *ScrollState) PageDown()
- func (s *ScrollState) PageUp()
- func (s *ScrollState) ScrollBy(delta int)
- func (s *ScrollState) ScrollTo(pos int)
- func (s *ScrollState) Select(idx int)
- func (s *ScrollState) SelectNext()
- func (s *ScrollState) SelectPrev()
- func (s *ScrollState) SetTotal(total int)
- func (s *ScrollState) SetVisible(visible int)
- type SparklineOpts
- type SpinnerStyle
- type Style
- type TabBarOpts
- type TabBounds
- type TableOpts
- type TextFieldOpts
- type TextFieldState
- func (t *TextFieldState) AdjustScroll(viewportW int)
- func (t *TextFieldState) Clear()
- func (t *TextFieldState) DeleteBackward() bool
- func (t *TextFieldState) DeleteForward() bool
- func (t *TextFieldState) DeleteToEnd() bool
- func (t *TextFieldState) DeleteToStart() bool
- func (t *TextFieldState) DeleteWordBackward() bool
- func (t *TextFieldState) DeleteWordForward() bool
- func (t *TextFieldState) HandleKey(key terminal.Key, r rune, mod terminal.Modifier) bool
- func (t *TextFieldState) Insert(r rune)
- func (t *TextFieldState) InsertString(s string)
- func (t *TextFieldState) MoveLeft()
- func (t *TextFieldState) MoveRight()
- func (t *TextFieldState) MoveToEnd()
- func (t *TextFieldState) MoveToStart()
- func (t *TextFieldState) MoveWordLeft()
- func (t *TextFieldState) MoveWordRight()
- func (t *TextFieldState) Paste(s string) bool
- func (t *TextFieldState) SetValue(s string)
- func (t *TextFieldState) Value() string
- type TextFieldStyle
- type Theme
- type ToastOpts
- type ToastPosition
- type ToastSeverity
- type ToastState
- type ToastStyle
- type TreeBuilder
- type TreeExpansion
- func (e *TreeExpansion) Clear()
- func (e *TreeExpansion) Collapse(key string)
- func (e *TreeExpansion) CollapseAll()
- func (e *TreeExpansion) Expand(key string)
- func (e *TreeExpansion) ExpandAll(keys []string)
- func (e *TreeExpansion) IsExpanded(key string) bool
- func (e *TreeExpansion) SetExpanded(key string, expanded bool)
- func (e *TreeExpansion) Toggle(key string) bool
- type TreeLineMode
- type TreeNode
- type TreeOpts
- type TreeState
- type ViewportScroll
- func (v *ViewportScroll) CanScroll() bool
- func (v *ViewportScroll) ClipToViewport(y, h int) (viewY, viewH, contentOffset int, visible bool)
- func (v *ViewportScroll) End()
- func (v *ViewportScroll) EnsureRange(y, h int)
- func (v *ViewportScroll) Home()
- func (v *ViewportScroll) IsVisible(y, h int) bool
- func (v *ViewportScroll) MaxOffset() int
- func (v *ViewportScroll) PageDown()
- func (v *ViewportScroll) PageUp()
- func (v *ViewportScroll) ScrollBy(delta int)
- func (v *ViewportScroll) ScrollTo(pos int)
- func (v *ViewportScroll) SetDimensions(contentH, viewportH int)
Constants ¶
const ( IconExpanded = '▼' IconCollapsed = '▶' IconBullet = '•' )
ExpandIcon chars
Variables ¶
var ( GlyphsUnicode = Glyphs{Focus: '▌', Pointer: '▸', Folded: '▸', Unfolded: '▾', On: '●', Off: '○', Required: '*'} GlyphsCP437 = Glyphs{Focus: '▌', Pointer: '►', Folded: '►', Unfolded: '▼', On: '•', Off: '○', Required: '*'} GlyphsASCII = Glyphs{Focus: '>', Pointer: '>', Folded: '+', Unfolded: '-', On: '*', Off: '-', Required: '*'} )
var DefaultTheme = Theme{ Text: Style{Fg: color.RGB{R: 200, G: 200, B: 200}, Bg: color.RGB{R: 20, G: 20, B: 30}}, Muted: Style{Fg: color.RGB{R: 120, G: 125, B: 140}}, Accent: Style{Fg: color.RGB{R: 80, G: 160, B: 220}, Attr: terminal.AttrBold}, Selected: Style{Bg: color.RGB{R: 40, G: 45, B: 65}}, Input: Style{Bg: color.RGB{R: 30, G: 30, B: 50}}, Cursor: Style{Fg: color.RGB{R: 20, G: 20, B: 30}, Bg: color.RGB{R: 200, G: 200, B: 200}}, Error: Style{Fg: color.RGB{R: 255, G: 80, B: 80}}, Border: Style{Fg: color.RGB{R: 60, G: 80, B: 100}}, Glyphs: GlyphsUnicode, }
DefaultTheme is a dark theme for true color and 256-color terminals
var MonoTheme = Theme{ Text: Style{Attr: own | terminal.AttrBgDefault}, Muted: Style{Attr: own | terminal.AttrDim}, Accent: Style{Attr: own | terminal.AttrBold}, Selected: Style{Attr: own | terminal.AttrReverse}, Input: Style{Attr: own | terminal.AttrUnderline}, Cursor: Style{Attr: own | terminal.AttrReverse}, Error: Style{Attr: own | terminal.AttrBold | terminal.AttrUnderline}, Border: Style{Attr: own}, Glyphs: GlyphsUnicode, }
MonoTheme draws with attributes alone in the terminal's own colors: the theme for ColorModeNone, and one that reads on any terminal
var SparklineChars = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}
SparklineChars provides 8-level vertical resolution
var Theme16 = Theme{ Text: Style{Attr: own | terminal.AttrBgDefault}, Muted: ansi(color.ANSIBrightBlack, 0), Accent: ansi(color.ANSICyan, terminal.AttrBold), Selected: Style{Attr: own | terminal.AttrReverse}, Input: Style{Attr: own | terminal.AttrUnderline}, Cursor: Style{Attr: own | terminal.AttrReverse}, Error: ansi(color.ANSIRed, terminal.AttrBold), Border: Style{Attr: own}, Glyphs: GlyphsUnicode, }
Theme16 uses the ANSI 16 colors alone, in the terminal's own shades, on its own background: the theme for ColorMode16, a text console's
var ToastColors = map[ToastSeverity]struct{ Fg, Bg, Icon color.RGB }{ ToastInfo: { Fg: color.RGB{R: 200, G: 200, B: 200}, Bg: color.RGB{R: 40, G: 40, B: 50}, Icon: color.RGB{R: 100, G: 150, B: 255}, }, ToastSuccess: { Fg: color.RGB{R: 220, G: 255, B: 220}, Bg: color.RGB{R: 30, G: 60, B: 30}, Icon: color.RGB{R: 80, G: 220, B: 80}, }, ToastWarning: { Fg: color.RGB{R: 255, G: 240, B: 200}, Bg: color.RGB{R: 60, G: 50, B: 20}, Icon: color.RGB{R: 255, G: 200, B: 60}, }, ToastError: { Fg: color.RGB{R: 255, G: 220, B: 220}, Bg: color.RGB{R: 60, G: 25, B: 25}, Icon: color.RGB{R: 255, G: 80, B: 80}, }, }
ToastColors default colors per severity
var ToastIcons = map[ToastSeverity]rune{ ToastInfo: 'ℹ', ToastSuccess: '✓', ToastWarning: '⚠', ToastError: '✗', }
ToastIcons for severity levels
Functions ¶
func AcceptInteger ¶ added in v0.2.0
AcceptInteger takes the runes of a decimal integer
func AcceptNumber ¶ added in v0.2.0
AcceptNumber takes the runes of a decimal number, exponent included
func AdjustScroll ¶
AdjustScroll returns new scroll offset keeping cursor visible
func BreakpointH ¶
BreakpointH returns index of first breakpoint <= w, returns len(breakpoints) if w is less than all breakpoints
func BreakpointV ¶
BreakpointV returns index of first breakpoint <= h
func CalculateColumnWidths ¶
CalculateColumnWidths computes optimal column widths for given data Returns widths that fit within availableW, respecting fixed widths in opts
func ClampCursor ¶
ClampCursor ensures cursor is within valid range
func ClampScroll ¶
ClampScroll ensures scroll offset is within valid range
func DividerPositions ¶
DividerPositions returns X coordinates for vertical dividers between equal columns Use with VLine to draw dividers in gaps created by SplitHEqual
func ExpandIconRune ¶
ExpandIconRune returns appropriate expand/collapse indicator
func FindFirstChildIndex ¶
FindFirstChildIndex returns index of first child for node at idx, or -1 if none
func FindNextSiblingIndex ¶
FindNextSiblingIndex returns index of next sibling at same depth, or -1
func FindParentIndex ¶
FindParentIndex returns index of parent node for node at idx, or -1 if root
func FindPrevSiblingIndex ¶
FindPrevSiblingIndex returns index of previous sibling at same depth, or -1
func FitOrScroll ¶
FitOrScroll returns true if content exceeds available height
func FormatCoverageSuffix ¶
FormatCoverageSuffix returns a suffix string for TreeNode.Suffix
func HDividerPositions ¶
HDividerPositions returns Y coordinates for horizontal dividers between equal rows
func RepeatRune ¶
RepeatRune returns a string of n repeated runes, for string repeat use strings.Repeat
func RuneLen ¶
RuneLen returns rune count, used as display width under the package-wide assumption of 1 cell per rune Wide (CJK), emoji, and combining characters are not handled
func ScrollPercent ¶
ScrollPercent returns scroll position as 0-100 percentage
func StepChoice ¶ added in v0.2.0
StepChoice moves a choice among n options on Left or Right (h, l), stopping at either end, and reports whether it moved
func TruncateLeft ¶
TruncateLeft truncates with … prefix, keeps end of string
func TruncateMiddle ¶
TruncateMiddle keeps start and end, … in middle
Types ¶
type AlertOpts ¶
type AlertOpts struct {
Title string
Message string
Button string // Default "OK"
Style ConfirmStyle
}
AlertOpts configures single-button alert dialog
type BarOpts ¶
type BarOpts struct {
Separator string // Between sections, default " │ "
SepStyle Style // Separator styling
Bg color.RGB
Align BarAlign
Padding int // Left/right padding, default 1
}
BarOpts configures status bar rendering
type BarSection ¶
type BarSection struct {
Label string
Value string
LabelStyle Style
ValueStyle Style
Priority int // Higher = survives truncation
}
BarSection represents one segment of a status bar
type ButtonBarOpts ¶
type ButtonBarOpts struct {
Align BarAlign
Gap int
Style ButtonStyle
}
ButtonBarOpts configures button bar rendering
type ButtonStyle ¶
type ButtonStyle struct {
LabelFg color.RGB
LabelBg color.RGB
KeyFg color.RGB
FocusFg color.RGB
FocusBg color.RGB
Bg color.RGB
}
ButtonStyle defines button bar colors
func DefaultButtonStyle ¶
func DefaultButtonStyle() ButtonStyle
DefaultButtonStyle returns default button colors with dark background
func DefaultButtonStyleFrom ¶
func DefaultButtonStyleFrom(bg color.RGB) ButtonStyle
DefaultButtonStyleFrom returns default button colors using the given background
type CheckState ¶
type CheckState uint8
CheckState represents checkbox visual state
const ( CheckNone CheckState = iota // [ ] CheckPartial // [o] CheckFull // [x] CheckPlus // [+] )
type ConfirmOpts ¶
type ConfirmOpts struct {
Title string
Message string
YesLabel string // Default "Yes"
NoLabel string // Default "No"
Destructive bool // Style Yes as warning
Style ConfirmStyle
}
ConfirmOpts configures confirmation dialog
type ConfirmResult ¶
type ConfirmResult uint8
ConfirmResult represents dialog outcome
const ( ConfirmPending ConfirmResult = iota ConfirmYes ConfirmNo ConfirmCancel )
type ConfirmState ¶
type ConfirmState struct {
FocusYes bool // true = Yes focused, false = No focused
Result ConfirmResult
}
ConfirmState holds confirmation dialog state
func NewConfirmState ¶
func NewConfirmState(defaultYes bool) *ConfirmState
NewConfirmState creates dialog state with default selection
func (*ConfirmState) Confirm ¶
func (c *ConfirmState) Confirm()
Confirm selects currently focused button
func (*ConfirmState) HandleKey ¶
func (c *ConfirmState) HandleKey(key terminal.Key, r rune) bool
HandleKey processes input, returns true if dialog should close
func (*ConfirmState) Toggle ¶
func (c *ConfirmState) Toggle()
Toggle switches focus between Yes and No
type ConfirmStyle ¶
type ConfirmStyle struct {
BorderFg color.RGB
TitleFg color.RGB
MessageFg color.RGB
Bg color.RGB
ButtonFg color.RGB
ButtonBg color.RGB
ButtonFocusFg color.RGB
ButtonFocusBg color.RGB
DestructiveFg color.RGB
DestructiveBg color.RGB
}
ConfirmStyle defines dialog colors
func DefaultConfirmStyle ¶
func DefaultConfirmStyle() ConfirmStyle
DefaultConfirmStyle returns default dialog colors
type Coverage ¶
Coverage represents count/total for display in tree nodes
func (Coverage) String ¶
String returns coverage as "count/total", "[ALL]", or empty string if total is zero
type DocOpts ¶
type DocOpts struct {
HeaderStyle Style
KeyStyle Style
TextStyle Style
RuleStyle Style
Rule LineType // Header rule; LineNone draws the header alone
KeyWidth int // Fixed key column, 0 = measured from the entries
KeyMaxW int // Cap for the measured key column, 0 = 40% of width
MinTextW int // Text column narrower than this stacks every entry
Gap int // Columns between key and text, minimum 1
Indent int // Left indent of section content
StackIndent int // Indent of a stacked description
SectionGap int // Blank rows before a section header
MaxWidth int // Document width cap, 0 = region width
Center bool // Center the document when the cap applies
}
DocOpts configures document layout and rendering Layout-affecting fields must not change between Layout and Doc
type DocState ¶
type DocState struct {
Viewport *ViewportScroll
// contains filtered or unexported fields
}
DocState holds a laid-out document and its scroll position
func (*DocState) Layout ¶
Layout flattens blocks into rows for the given width; the row count becomes the viewport content height. Entries stack when the text column is too narrow, and an over-long key stacks on its own rather than truncating.
func (*DocState) SetViewport ¶
SetViewport updates viewport height
type EditorOpts ¶
type EditorOpts struct {
LineNumbers bool
LineNumWidth int // 0 = auto-size
WrapLines bool
Border LineType
Focused bool
Style EditorStyle
}
EditorOpts configures editor rendering
type EditorState ¶
type EditorState struct {
Lines []string
CursorLine int
CursorCol int
ScrollX int
ScrollY int
ViewportW int // Updated during render
ViewportH int // Updated during render
}
EditorState holds multi-line text editor state
func NewEditorState ¶
func NewEditorState(initial string) *EditorState
NewEditorState creates initialized editor state
func (*EditorState) AdjustScroll ¶
func (e *EditorState) AdjustScroll(viewportW, viewportH int)
AdjustScroll updates scroll to keep cursor visible
func (*EditorState) CurrentLine ¶
func (e *EditorState) CurrentLine() string
CurrentLine returns current line text
func (*EditorState) DeleteBackward ¶
func (e *EditorState) DeleteBackward() bool
DeleteBackward deletes character before cursor or merges lines
func (*EditorState) DeleteForward ¶
func (e *EditorState) DeleteForward() bool
DeleteForward deletes character at cursor or merges with next line
func (*EditorState) DeleteLine ¶
func (e *EditorState) DeleteLine() bool
DeleteLine removes current line
func (*EditorState) DeleteToEndOfLine ¶
func (e *EditorState) DeleteToEndOfLine() bool
DeleteToEndOfLine deletes from cursor to end of line
func (*EditorState) DeleteToStartOfLine ¶
func (e *EditorState) DeleteToStartOfLine() bool
DeleteToStartOfLine deletes from start to cursor
func (*EditorState) DeleteWordBackward ¶
func (e *EditorState) DeleteWordBackward() bool
DeleteWordBackward deletes word before cursor
func (*EditorState) DeleteWordForward ¶
func (e *EditorState) DeleteWordForward() bool
DeleteWordForward deletes word after cursor
func (*EditorState) Insert ¶
func (e *EditorState) Insert(r rune)
Insert adds a rune at cursor position
func (*EditorState) InsertNewline ¶
func (e *EditorState) InsertNewline()
InsertNewline splits current line at cursor
func (*EditorState) InsertString ¶
func (e *EditorState) InsertString(s string)
InsertString adds string at cursor, handling newlines
func (*EditorState) LineCount ¶
func (e *EditorState) LineCount() int
LineCount returns number of lines
func (*EditorState) MoveLeft ¶
func (e *EditorState) MoveLeft()
MoveLeft moves cursor left, wrapping to previous line
func (*EditorState) MoveRight ¶
func (e *EditorState) MoveRight()
MoveRight moves cursor right, wrapping to next line
func (*EditorState) MoveToEnd ¶
func (e *EditorState) MoveToEnd()
MoveToEnd moves cursor to end of document
func (*EditorState) MoveToLineEnd ¶
func (e *EditorState) MoveToLineEnd()
MoveToLineEnd moves cursor to end of line
func (*EditorState) MoveToLineStart ¶
func (e *EditorState) MoveToLineStart()
MoveToLineStart moves cursor to start of line
func (*EditorState) MoveToStart ¶
func (e *EditorState) MoveToStart()
MoveToStart moves cursor to start of document
func (*EditorState) MoveWordLeft ¶
func (e *EditorState) MoveWordLeft()
MoveWordLeft moves cursor to previous word boundary
func (*EditorState) MoveWordRight ¶
func (e *EditorState) MoveWordRight()
MoveWordRight moves cursor to next word boundary
func (*EditorState) PageDown ¶
func (e *EditorState) PageDown()
PageDown moves cursor down by half viewport
func (*EditorState) SetValue ¶
func (e *EditorState) SetValue(s string)
SetValue replaces all content and resets cursor
func (*EditorState) Value ¶
func (e *EditorState) Value() string
Value returns all lines joined with newlines
type EditorStyle ¶
type EditorStyle struct {
TextFg color.RGB
TextBg color.RGB
CursorFg color.RGB
CursorBg color.RGB
LineNumFg color.RGB
LineNumBg color.RGB
CurrentLineBg color.RGB
BorderFg color.RGB
}
EditorStyle defines editor colors
func DefaultEditorStyle ¶
func DefaultEditorStyle() EditorStyle
DefaultEditorStyle returns default colors
type Field ¶ added in v0.2.0
type Field struct {
Label string
Required bool
Help string // shown under the field while it has focus
Error string // shown under the field, in place of Help
}
Field labels one form row
type Focus ¶ added in v0.2.0
type Focus struct {
Index, Len int
}
Focus is a focus ring over a form's controls, numbered 0 to Len-1
type FormField ¶
type FormField struct {
Label string
State *TextFieldState
}
FormField pairs a label with an editable text field
type FormState ¶
FormState holds state for a multi-field form with focus tracking
func NewFormState ¶
NewFormState creates a form with labeled fields initialized to empty values
func (*FormState) CurrentField ¶
func (f *FormState) CurrentField() *TextFieldState
CurrentField returns the TextFieldState of the focused field, or nil
func (*FormState) FocusNext ¶
func (f *FormState) FocusNext()
FocusNext moves focus to the next field, wrapping around
func (*FormState) FocusPrev ¶
func (f *FormState) FocusPrev()
FocusPrev moves focus to the previous field, wrapping around
func (*FormState) HandleKey ¶
HandleKey processes keyboard input for form navigation and field editing, returns true if state changed
type FormStyle ¶
type FormStyle struct {
LabelFg color.RGB
FieldFg color.RGB
FieldBg color.RGB
FocusBg color.RGB
CursorFg color.RGB
CursorBg color.RGB
Bg color.RGB
}
FormStyle defines form colors
func DefaultFormStyle ¶
func DefaultFormStyle() FormStyle
DefaultFormStyle returns default form colors
type Glyphs ¶ added in v0.2.0
type Glyphs struct {
Focus rune // beside the focused control
Pointer rune // the cursor row of a list
Folded rune // a closed group
Unfolded rune // an open group
On, Off rune // a toggle
Required rune // after a required field's label
}
Glyphs are the marks widgets draw; a selection always changes a glyph, so it reads without color. A text console's font takes GlyphsCP437, a terminal outside UTF-8 GlyphsASCII.
type InputOpts ¶
type InputOpts struct {
Label string
LabelFg color.RGB
Text string
Cursor int // Cursor position in text (rune index)
CursorBg color.RGB
TextFg color.RGB
Bg color.RGB
}
InputOpts configures single-line input field
type ListItem ¶
type ListItem struct {
Indent int // Left padding in cells
Icon rune // Expand indicator or bullet, 0 = none
IconFg color.RGB
Check CheckState // CheckNone to skip checkbox
CheckFg color.RGB
Text string
TextStyle Style
}
ListItem represents a single row in a scrollable list
type ListOpts ¶
type ListOpts struct {
CursorBg color.RGB
DefaultBg color.RGB
IconWidth int // Width reserved for icon, default 2
}
ListOpts configures list rendering
type MasonryItem ¶
MasonryItem represents a single item in masonry layout
type MasonryLayout ¶
type MasonryLayout struct {
X, Y, W, H int
Item MasonryItem
}
MasonryLayout holds calculated position for an item
type MasonryOpts ¶
type MasonryOpts struct {
Columns int
GapX int // Columns between masonry columns
GapY int // Rows between stacked items
MinColW int
Breakpoints map[int]int
}
MasonryOpts configures masonry layout
func DefaultMasonryOpts ¶
func DefaultMasonryOpts() MasonryOpts
DefaultMasonryOpts returns sensible defaults
type MasonryRenderFunc ¶
type MasonryRenderFunc func(region Region, layout MasonryLayout, contentOffset int)
MasonryRenderFunc renders a single item
type MasonryState ¶
type MasonryState struct {
Viewport *ViewportScroll
Layouts []MasonryLayout
}
MasonryState manages masonry layout with viewport scroll
func (*MasonryState) CalculateLayout ¶
func (m *MasonryState) CalculateLayout(items []MasonryItem, width int, opts MasonryOpts)
CalculateLayout computes item positions
func (*MasonryState) ScrollIndicator ¶
func (m *MasonryState) ScrollIndicator() string
ScrollIndicator renders scroll position indicator for masonry
func (*MasonryState) SetViewport ¶
func (m *MasonryState) SetViewport(h int)
SetViewport updates viewport height
type ModalOpts ¶
type ModalOpts struct {
Title string
Hint string // Right-aligned hint text
Border LineType
BorderFg color.RGB
TitleFg color.RGB
HintFg color.RGB
Bg color.RGB
}
ModalOpts configures modal overlay rendering
type OptionListState ¶ added in v0.2.0
type OptionListState struct {
Options []Option
Filter TextFieldState
Cursor int // index into Matches
Scroll int // first match shown
}
OptionListState filters options by the text typed into it, matching name or hint regardless of case, and keeps a cursor on the matches
func NewOptionListState ¶ added in v0.2.0
func NewOptionListState(options []Option) *OptionListState
NewOptionListState creates a list showing every option
func (*OptionListState) Chosen ¶ added in v0.2.0
func (s *OptionListState) Chosen() (int, bool)
Chosen returns the index in Options of the option under the cursor, and false when nothing matches
func (*OptionListState) HandleKey ¶ added in v0.2.0
HandleKey moves the cursor on Up and Down, or edits the filter, and reports whether anything changed
func (*OptionListState) Matches ¶ added in v0.2.0
func (s *OptionListState) Matches() []int
Matches returns the indices of the options the filter matches, in order, keeping the cursor on one of them
func (*OptionListState) Paste ¶ added in v0.2.0
func (s *OptionListState) Paste(text string) bool
Paste adds pasted text to the filter
type OverlayOpts ¶
type OverlayOpts struct {
Style OverlayStyle
Title string
Border LineType
Bg color.RGB
Fg color.RGB // Border and title color
TitleBg color.RGB // Title bar background, zero = same as Fg
TitleFg color.RGB // Title text color, zero = same as Bg
// Modal/Floating positioning (ignored for Fullscreen)
Width int // 0 = 80% of region
Height int // 0 = 80% of region
X, Y int // Offset from center, 0 = centered
// Shadow for Floating style
ShadowColor color.RGB
}
OverlayOpts configures overlay rendering
func DefaultOverlayOpts ¶
func DefaultOverlayOpts(title string) OverlayOpts
DefaultOverlayOpts returns sensible defaults for modal overlay
func FullscreenOverlayOpts ¶
func FullscreenOverlayOpts(title string) OverlayOpts
FullscreenOverlayOpts returns opts for fullscreen overlay with title bar
type OverlayResult ¶
type OverlayResult struct {
Outer Region // Full overlay bounds (including border/title)
Content Region // Inner content area
TitleY int // Y position of title bar in Outer, -1 if no title
}
OverlayResult contains regions returned by Overlay rendering
type OverlayState ¶
type OverlayState struct {
Visible bool
Opts OverlayOpts
Data any // Application-specific state
}
OverlayState manages overlay visibility and content state
func NewOverlayState ¶
func NewOverlayState(opts OverlayOpts) *OverlayState
NewOverlayState creates hidden overlay state
type OverlayStyle ¶
type OverlayStyle uint8
OverlayStyle specifies overlay appearance
const ( OverlayFullscreen OverlayStyle = iota // No border, fills region OverlayModal // Centered box with border OverlayFloating // Positioned box with shadow OverlayBorderTitle // Title embedded in top border line )
type PaneOpts ¶
type PaneOpts struct {
Title string
Border LineType
BorderFg color.RGB
Bg color.RGB
TitleFg color.RGB
}
PaneOpts configures pane rendering
type ProgressOverlayOpts ¶
type ProgressOverlayOpts struct {
Title string
Message string
Type ProgressType
Style ProgressStyle
SpinnerStyle SpinnerStyle
BarStyle BarStyle
Progress float64 // 0.0-1.0 for determinate
Frame int // Animation frame counter
ShowPercent bool // Show percentage text
ShowETA string // Optional ETA string
Width int // Overlay width, 0 = auto
Cancelable bool // Show cancel hint
CancelKey string // e.g., "Esc"
Fg color.RGB
Bg color.RGB
BarFg color.RGB
BarBg color.RGB
AccentFg color.RGB // Spinner/highlight color
}
ProgressOverlayOpts configures progress overlay
func DefaultProgressOpts ¶
func DefaultProgressOpts(title, message string, ptype ProgressType) ProgressOverlayOpts
DefaultProgressOpts returns sensible defaults
type ProgressState ¶
type ProgressState struct {
Visible bool
Opts ProgressOverlayOpts
Frame int
Progress float64
}
ProgressState manages progress overlay state
func NewProgressState ¶
func NewProgressState(opts ProgressOverlayOpts) *ProgressState
NewProgressState creates progress overlay state
func (*ProgressState) Dismiss ¶
func (p *ProgressState) Dismiss()
Dismiss hides the progress overlay
func (*ProgressState) SetMessage ¶
func (p *ProgressState) SetMessage(msg string)
SetMessage updates message text
func (*ProgressState) SetProgress ¶
func (p *ProgressState) SetProgress(pct float64)
SetProgress updates progress value (0.0-1.0)
type ProgressStyle ¶
type ProgressStyle uint8
ProgressStyle defines visual appearance
const ( ProgressStyleMinimal ProgressStyle = iota // Text only ProgressStyleBox // Single border ProgressStyleDouble // Double border ProgressStyleRounded // Rounded border ProgressStyleShadow // Box with shadow ProgressStyleNeon // Bright colors ProgressStyleRetro // Block characters )
type ProgressType ¶
type ProgressType uint8
ProgressType specifies progress indicator variant
const ( ProgressSpinner ProgressType = iota // Animated spinner ProgressDeterminate // Bar with percentage ProgressIndeterminate // Marquee animation ProgressPulse // Pulsing bar ProgressDots // Animated dots )
type Region ¶
type Region struct {
Cells []terminal.Cell
TotalW int // Total width of the underlying cell buffer
X, Y int // Absolute position in cell buffer
W, H int // Region dimensions
}
Region represents a rectangular area within a cell buffer All coordinates are relative to the region's origin
func GridLayout ¶
GridLayout returns a grid of equally sized regions
func SplitHEqual ¶
SplitHEqual splits region into n equal-width columns gap specifies spacing between columns (e.g., 1 for divider lines) Returns n regions positioned with gaps between them
func SplitHFixed ¶
SplitHFixed splits with fixed left width, rest to right
func SplitVEqual ¶
SplitVEqual splits region into n equal-height rows gap specifies spacing between rows
func SplitVFixed ¶
SplitVFixed splits with fixed top height, rest to bottom
func (Region) AlertDialog ¶
AlertDialog renders single-button alert, returns true when dismissed
func (Region) BoxClipped ¶
BoxClipped draws the visible slice of a box whose logical height is totalH, with off rows scrolled past its top edge. Rows outside the box are skipped, so a partially visible box keeps its sides and grows no false edges.
func (Region) ButtonBar ¶
func (r Region) ButtonBar(y int, buttons []Button, opts ButtonBarOpts)
ButtonBar renders a row of buttons with labels and keyboard hints at row y
func (Region) Cell ¶
Cell sets a single cell with bounds checking. A zero-value bg (color.RGB{}) with no Bg color bits in attr is transparent: the existing cell's background is preserved, bits and all. Establish a base background first (Fill, or pre-initialized cell buffer). For a literal black background use CellOpaque or Fill(color.RGB{}).
func (Region) CellOpaque ¶
CellOpaque sets a single cell writing bg verbatim, including zero (black). Used by base-layer operations (Fill) that must be able to write any color.
func (Region) Checkbox ¶
func (r Region) Checkbox(x, y int, state CheckState, fg color.RGB)
Checkbox draws a checkbox indicator
func (Region) Choice ¶ added in v0.2.0
Choice draws options in a row at (x, y), the chosen one bracketed in the accent style and the rest muted ("raw [txt] json"), and returns the columns it drew
func (Region) ConfirmDialog ¶
func (r Region) ConfirmDialog(state *ConfirmState, opts ConfirmOpts) Region
ConfirmDialog renders confirmation dialog centered in region Returns content region for additional content if needed
func (Region) Editor ¶
func (r Region) Editor(state *EditorState, opts EditorOpts) int
Editor renders multi-line editor and returns content height used
func (Region) Field ¶ added in v0.2.0
Field draws a form row at y: the focus mark, the label in a column labelW wide with the required mark, and below, the error, or the help while focused. It returns the region for the value beside the label, where the caller draws a TextInput, Choice or Toggle, and the rows it used.
func (Region) Fill ¶
Fill fills entire region with background color. Opaque by definition: Fill establishes the base layer, so bg is written verbatim (including zero/black) rather than treated as transparent.
func (Region) FillStyle ¶ added in v0.2.0
FillStyle fills the region with spaces in s, opaque as Fill is; a theme's Text fills the panel its widgets draw on
func (Region) Form ¶
Form renders a multi-field form with labels and editable text fields, returns height used
func (Region) Group ¶ added in v0.2.0
Group draws a foldable group's header at y: the focus mark, the Folded or Unfolded glyph and the title, and while folded, a muted summary of what it holds
func (Region) Input ¶
Input renders labeled text input field on row y, handling cursor display and horizontal scrolling
func (Region) KeyValue ¶
KeyValue renders right-aligned key, separator and left-aligned value on row y, sizing the key column to this row alone
func (Region) KeyValueColumn ¶
KeyValueColumn renders a key-value row against an explicit key column, so a set of rows aligns on the separator; keyW <= 0 sizes the column to this row
func (Region) KeyValueWrap ¶
KeyValueWrap renders a key with its value wrapped into the value column, returning the number of lines used
key: value text that is
long and wraps to
next line
func (Region) List ¶
List renders scrollable list items within region, returns number of rows rendered
func (Region) Masonry ¶
func (r Region) Masonry(state *MasonryState, render MasonryRenderFunc)
Masonry renders visible items via callback
func (Region) MeasureKeyValueWrap ¶
MeasureKeyValueWrap returns the line count KeyValueWrap needs, for layout pre-calculation. Shares the column split with the renderer, so the two agree.
func (Region) Modal ¶
Modal fills region with background, draws border with title/hint, returns content region
func (Region) OptionList ¶ added in v0.2.0
func (r Region) OptionList(s *OptionListState, th Theme)
OptionList draws the filter on the first row and the matches below it, the cursor row marked with the pointer on the Selected background, each hint muted in a column after the names
func (Region) Overlay ¶
func (r Region) Overlay(opts OverlayOpts) OverlayResult
Overlay renders an overlay and returns content region for caller to populate Caller should render content into result.Content after this call
func (Region) Pane ¶
Pane draws bordered pane with optional title, returns content region Content region is inside border, below title row if present
func (Region) ProgressOverlay ¶
func (r Region) ProgressOverlay(opts ProgressOverlayOpts) Region
ProgressOverlay renders centered progress overlay
func (Region) QuickStatusBar ¶
QuickStatusBar renders simple label:value pairs right-aligned
func (Region) ScrollBarStyled ¶
func (r Region) ScrollBarStyled(x int, offset, visible, total int, opts ScrollBarOpts)
ScrollBarStyled draws a vertical scrollbar at column x with explicit styling
func (Region) ScrollIndicator ¶
ScrollIndicator draws compact indicator text (Top/Bot/XX%)
func (Region) Sparkline ¶
func (r Region) Sparkline(x, y, width int, values []float64, opts SparklineOpts)
Sparkline renders an inline graph of values, values are mapped to 8-level block characters
func (Region) SparklineV ¶
func (r Region) SparklineV(x, y, height int, values []float64, opts SparklineOpts)
SparklineV renders vertical sparkline (bottom to top)
func (Region) StatusBar ¶
func (r Region) StatusBar(y int, sections []BarSection, opts BarOpts)
StatusBar renders horizontal status bar on row y
func (Region) Sub ¶
Sub returns a nested region with coordinates relative to parent, result is clipped to parent bounds
func (Region) TabBar ¶
TabBar renders horizontal tab strip at row y Returns bounds of each tab for hit testing / navigation
func (Region) TabBarCentered ¶
TabBarCentered renders tab bar centered horizontally
func (Region) TextBlock ¶
TextBlock renders wrapped text within region bounds, returns number of lines rendered
func (Region) TextBlockStyled ¶
TextBlockStyled renders wrapped text using Style struct, returns number of lines rendered
func (Region) TextCenter ¶
TextCenter renders text centered on row
func (Region) TextField ¶
func (r Region) TextField(state *TextFieldState, opts TextFieldOpts) int
TextField renders text field and returns content height used
func (Region) TextInput ¶ added in v0.2.0
func (r Region) TextInput(state *TextFieldState, placeholder string, focused bool, th Theme)
TextInput draws state's text on r's first row, or, empty, the placeholder muted: a default shows what an empty value means. Focused, it draws on the Input background with the cursor, scrolling to keep the cursor in view.
func (Region) TextStyled ¶
TextStyled renders text using Style struct
func (Region) TitledPane ¶
TitledPane fills region with background, draws centered title at top, returns content region Content region starts at row 1 with full width
func (Region) TitledPaneFocused ¶
func (r Region) TitledPaneFocused(title string, titleFg, bg, focusBg color.RGB, focused bool) Region
TitledPaneFocused is TitledPane with focus-dependent background
func (Region) Toast ¶
Toast renders a toast message overlay Returns the region occupied by the toast for hit testing
func (Region) Toggle ¶ added in v0.2.0
Toggle draws a switch at (x, y): the On glyph and "on" in the accent style, or the Off glyph and "off" muted, and returns the columns it drew
func (Region) Tree ¶
Tree renders hierarchical tree nodes within region, returns number of rows rendered Nodes must be pre-flattened (only visible/expanded nodes included)
type ScrollBarOpts ¶
type ScrollBarOpts struct {
ThumbFg color.RGB
TrackFg color.RGB
Bg color.RGB // Zero inherits the existing cell background
Thumb rune // 0 = '█'
Track rune // 0 = '░'
HideIdle bool // Draw nothing when content fits the viewport
}
ScrollBarOpts configures scrollbar rendering
type ScrollState ¶
type ScrollState struct {
Offset int // First visible item index
Total int // Total item count
Visible int // Visible item count (viewport height)
Selection int // Currently selected item, -1 if none
}
ScrollState tracks scroll position for a scrollable container
func NewScrollState ¶
func NewScrollState(total, visible int) *ScrollState
NewScrollState creates initialized scroll state
func (*ScrollState) AtBottom ¶
func (s *ScrollState) AtBottom() bool
AtBottom returns true if scrolled to bottom
func (*ScrollState) AtTop ¶
func (s *ScrollState) AtTop() bool
AtTop returns true if scrolled to top
func (*ScrollState) Clamp ¶
func (s *ScrollState) Clamp()
Clamp ensures offset is within valid range
func (*ScrollState) EnsureVisible ¶
func (s *ScrollState) EnsureVisible(pos int)
EnsureVisible adjusts offset to make item at pos visible
func (*ScrollState) PageDown ¶
func (s *ScrollState) PageDown()
PageDown scrolls down by half visible height
func (*ScrollState) PageUp ¶
func (s *ScrollState) PageUp()
PageUp scrolls up by half visible height
func (*ScrollState) ScrollBy ¶
func (s *ScrollState) ScrollBy(delta int)
ScrollBy adjusts offset by delta, clamping to valid range
func (*ScrollState) ScrollTo ¶
func (s *ScrollState) ScrollTo(pos int)
ScrollTo sets offset to specific position
func (*ScrollState) Select ¶
func (s *ScrollState) Select(idx int)
Select sets selection and ensures it's visible
func (*ScrollState) SetTotal ¶
func (s *ScrollState) SetTotal(total int)
SetTotal updates total count and reclamps
func (*ScrollState) SetVisible ¶
func (s *ScrollState) SetVisible(visible int)
SetVisible updates visible count and reclamps
type SparklineOpts ¶
SparklineOpts configures sparkline rendering
type SpinnerStyle ¶
type SpinnerStyle uint8
SpinnerStyle defines spinner animation type
const ( SpinnerBraille SpinnerStyle = iota // ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ SpinnerDots // ⣾⣽⣻⢿⡿⣟⣯⣷ SpinnerLine // |/-\ SpinnerBlock // ▖▘▝▗ SpinnerCircle // ◐◓◑◒ SpinnerArc // ◜◠◝◞◡◟ SpinnerBounce // ⠁⠂⠄⠂ SpinnerGrow // ▁▃▄▅▆▇█▇▆▅▄▃ )
type Style ¶
Style bundles foreground, background, and attributes for text rendering. Attr's color bits say how to read Fg and Bg: terminal.AttrFg256 a palette index in R, terminal.AttrFgDefault the terminal's own color.
func DefaultStyle ¶
DefaultStyle returns style with zero values (transparent bg)
type TabBarOpts ¶
type TabBarOpts struct {
ActiveStyle Style
InactiveStyle Style
Separator string // Between tabs, default " │ "
Padding int // Horizontal padding inside each tab, default 1
}
TabBarOpts configures tab bar rendering
func DefaultTabBarOpts ¶
func DefaultTabBarOpts() TabBarOpts
DefaultTabBarOpts returns sensible defaults
type TabBounds ¶
type TabBounds struct {
X, W int
}
TabBounds stores position and size of a rendered tab
type TableOpts ¶
type TableOpts struct {
ColWidths []int // Fixed widths per column, 0 = auto
ColAligns []Align // Alignment per column, default AlignLeft
HeaderStyle Style
RowStyle Style
AltRowStyle Style // Alternating row style, zero = same as RowStyle
ColSeparator rune // Between columns, 0 = space
RowSeparator LineType // Between rows, LineNone = no separator
}
TableOpts configures table rendering
func DefaultTableOpts ¶
func DefaultTableOpts() TableOpts
DefaultTableOpts returns sensible defaults
type TextFieldOpts ¶
type TextFieldOpts struct {
Placeholder string // Shown when empty
Prefix string // Left prompt (e.g., "> ")
Mask rune // Password mask, 0 = none
MaxLen int // Max runes, 0 = unlimited
Border LineType // Border style, LineNone = no border
Focused bool // Show cursor and accept input
Style TextFieldStyle
}
TextFieldOpts configures text field rendering
type TextFieldState ¶
type TextFieldState struct {
Text []rune
Cursor int // Positions before which cursor sits (0 = before first char)
Scroll int // First visible rune index
// Accept, when set, filters the runes typed or pasted: AcceptInteger
// and AcceptNumber make a typed field
Accept func(rune) bool
}
TextFieldState holds editable text field state
func NewTextFieldState ¶
func NewTextFieldState(initial string) *TextFieldState
NewTextFieldState creates initialized text field state
func (*TextFieldState) AdjustScroll ¶
func (t *TextFieldState) AdjustScroll(viewportW int)
AdjustScroll updates scroll to keep cursor visible within viewport width
func (*TextFieldState) DeleteBackward ¶
func (t *TextFieldState) DeleteBackward() bool
DeleteBackward removes rune before cursor
func (*TextFieldState) DeleteForward ¶
func (t *TextFieldState) DeleteForward() bool
DeleteForward removes rune at cursor
func (*TextFieldState) DeleteToEnd ¶
func (t *TextFieldState) DeleteToEnd() bool
DeleteToEnd removes from cursor to end
func (*TextFieldState) DeleteToStart ¶
func (t *TextFieldState) DeleteToStart() bool
DeleteToStart removes from start to cursor
func (*TextFieldState) DeleteWordBackward ¶
func (t *TextFieldState) DeleteWordBackward() bool
DeleteWordBackward removes word before cursor
func (*TextFieldState) DeleteWordForward ¶
func (t *TextFieldState) DeleteWordForward() bool
DeleteWordForward removes word after cursor
func (*TextFieldState) HandleKey ¶
HandleKey processes keyboard input, returns true if state changed
func (*TextFieldState) Insert ¶
func (t *TextFieldState) Insert(r rune)
Insert adds rune at cursor position
func (*TextFieldState) InsertString ¶
func (t *TextFieldState) InsertString(s string)
InsertString adds string at cursor position
func (*TextFieldState) MoveRight ¶
func (t *TextFieldState) MoveRight()
MoveRight moves cursor right
func (*TextFieldState) MoveToEnd ¶
func (t *TextFieldState) MoveToEnd()
MoveToEnd moves cursor to end
func (*TextFieldState) MoveToStart ¶
func (t *TextFieldState) MoveToStart()
MoveToStart moves cursor to beginning
func (*TextFieldState) MoveWordLeft ¶
func (t *TextFieldState) MoveWordLeft()
MoveWordLeft moves cursor to previous word boundary
func (*TextFieldState) MoveWordRight ¶
func (t *TextFieldState) MoveWordRight()
MoveWordRight moves cursor to next word boundary
func (*TextFieldState) Paste ¶ added in v0.2.0
func (t *TextFieldState) Paste(s string) bool
Paste inserts pasted text at the cursor: a line break or tab becomes a space, and other control characters and runes Accept refuses are dropped. It reports whether anything was inserted.
func (*TextFieldState) SetValue ¶
func (t *TextFieldState) SetValue(s string)
SetValue replaces text and moves cursor to end
func (*TextFieldState) Value ¶
func (t *TextFieldState) Value() string
Value returns current text as string
type TextFieldStyle ¶
type TextFieldStyle struct {
TextFg color.RGB
TextBg color.RGB
CursorFg color.RGB
CursorBg color.RGB
PlaceholderFg color.RGB
PrefixFg color.RGB
BorderFg color.RGB
}
TextFieldStyle defines text field colors
func DefaultTextFieldStyle ¶
func DefaultTextFieldStyle() TextFieldStyle
DefaultTextFieldStyle returns default colors
type Theme ¶
type Theme struct {
Text Style // values and body text; its Bg is the panel's
Muted Style // labels, hints, placeholders and defaults, help lines
Accent Style // marks: focus, the chosen option, a required field
Selected Style // the cursor row of a list
Input Style // the background of the field being edited
Cursor Style // the text cursor
Error Style // errors
Border Style // boxes and rules
Glyphs Glyphs
}
Theme styles the widgets that take one. Each role is a Style whose Attr may carry color bits (a palette index, the terminal's own color), so one theme per color tier, mono included, draws every widget alike. A role with a zero Bg and no Bg bits draws on whatever is beneath it.
type ToastOpts ¶
type ToastOpts struct {
Message string
Severity ToastSeverity
Position ToastPosition
Style ToastStyle
ShowIcon bool
MinWidth int // Minimum width for floating toasts, 0 = auto
MaxWidth int // Maximum width, 0 = region width
Padding int // Horizontal padding, default 1
MarginX int // Margin from edge for floating positions
MarginY int // Margin from edge for floating positions
CustomFg color.RGB
CustomBg color.RGB
CustomIcon color.RGB
}
ToastOpts configures toast rendering
func DefaultToastOpts ¶
func DefaultToastOpts(message string, severity ToastSeverity) ToastOpts
DefaultToastOpts returns sensible defaults
type ToastPosition ¶
type ToastPosition uint8
ToastPosition specifies where toast renders
const ( ToastBottom ToastPosition = iota // Full-width bar at bottom ToastTop // Full-width bar at top ToastBottomRight // Floating box bottom-right ToastBottomLeft // Floating box bottom-left ToastTopRight // Floating box top-right ToastTopLeft // Floating box top-left ToastCenter // Centered floating box )
type ToastSeverity ¶
type ToastSeverity uint8
ToastSeverity defines message type for styling
const ( ToastInfo ToastSeverity = iota // Default, neutral ToastSuccess // Green, positive ToastWarning // Yellow, caution ToastError // Red, failure )
type ToastState ¶
type ToastState struct {
Visible bool
Opts ToastOpts
FramesLeft int // Countdown to auto-dismiss, -1 = persistent
}
ToastState manages toast lifecycle
func NewToastState ¶
func NewToastState(opts ToastOpts, frames int) *ToastState
NewToastState creates a toast that auto-dismisses after frames Use frames=-1 for persistent toast
func (*ToastState) Show ¶
func (t *ToastState) Show(opts ToastOpts, frames int)
Show displays a new toast
func (*ToastState) Tick ¶
func (t *ToastState) Tick() bool
Tick decrements frame counter, returns true if toast should dismiss
type ToastStyle ¶
type ToastStyle uint8
ToastStyle defines visual appearance
const ( ToastStyleMinimal ToastStyle = iota // No border, just text ToastStyleBar // Full-width background bar ToastStyleBox // Bordered box ToastStyleRounded // Rounded border box ToastStyleDouble // Double-line border ToastStyleShadow // Box with shadow effect )
type TreeBuilder ¶
type TreeBuilder struct {
// contains filtered or unexported fields
}
TreeBuilder helps construct flattened visible node list from hierarchical data
func NewTreeBuilder ¶
func NewTreeBuilder(expansion *TreeExpansion) *TreeBuilder
NewTreeBuilder creates a builder with expansion state
func (*TreeBuilder) Add ¶
func (b *TreeBuilder) Add(node TreeNode, parentExpanded bool)
Add adds a node if visible (parent expanded) parentExpanded should be true for root-level nodes
func (*TreeBuilder) MarkLastSiblings ¶
func (b *TreeBuilder) MarkLastSiblings()
MarkLastSiblings sets IsLast flag on nodes that are last at their depth Call after all nodes added, before rendering
func (*TreeBuilder) Nodes ¶
func (b *TreeBuilder) Nodes() []TreeNode
Nodes returns accumulated visible nodes
type TreeExpansion ¶
TreeExpansion manages expand/collapse state
func NewTreeExpansion ¶
func NewTreeExpansion() *TreeExpansion
NewTreeExpansion creates initialized expansion state
func (*TreeExpansion) Collapse ¶
func (e *TreeExpansion) Collapse(key string)
Collapse sets key to collapsed
func (*TreeExpansion) CollapseAll ¶
func (e *TreeExpansion) CollapseAll()
CollapseAll collapses all keys
func (*TreeExpansion) Expand ¶
func (e *TreeExpansion) Expand(key string)
Expand sets key to expanded
func (*TreeExpansion) ExpandAll ¶
func (e *TreeExpansion) ExpandAll(keys []string)
ExpandAll expands all provided keys
func (*TreeExpansion) IsExpanded ¶
func (e *TreeExpansion) IsExpanded(key string) bool
IsExpanded returns expansion state for key
func (*TreeExpansion) SetExpanded ¶
func (e *TreeExpansion) SetExpanded(key string, expanded bool)
SetExpanded sets expansion state for key
func (*TreeExpansion) Toggle ¶
func (e *TreeExpansion) Toggle(key string) bool
Toggle toggles expansion state for key
type TreeLineMode ¶
type TreeLineMode uint8
TreeLineMode specifies connector line rendering
const ( TreeLinesNone TreeLineMode = iota // Indent only, no lines TreeLinesSimple // │ continuation, └ for last )
type TreeNode ¶
type TreeNode struct {
Key string // Unique identifier for expansion state
Label string // Display text
Icon rune // Custom icon, 0 = auto (▶/▼ for expandable, • for leaf)
IconFg color.RGB
Expandable bool // Has children
Expanded bool // Currently expanded
Depth int // Nesting level (0 = root)
Check CheckState // Optional checkbox, CheckNone to skip
CheckFg color.RGB
Style Style // Text styling
IsLast bool // Last sibling at this depth (for tree lines)
Data any // Application payload
Suffix string // Secondary text after label (e.g., "(5 files)")
SuffixStyle Style // Styling for suffix, zero = dimmed version of Style
Badge rune // Icon between checkbox and label (e.g., '★'), 0 = none
BadgeFg color.RGB // Badge color
}
TreeNode represents a node in a hierarchical tree
type TreeOpts ¶
type TreeOpts struct {
CursorBg color.RGB
DefaultBg color.RGB
IndentWidth int // Cells per depth, default 2
IconWidth int // Width for icon column, default 2
LineMode TreeLineMode
LineFg color.RGB
}
TreeOpts configures tree rendering
type TreeState ¶
TreeState manages navigation state for a tree
func NewTreeState ¶
NewTreeState creates initialized tree state
func (*TreeState) AdjustScroll ¶
AdjustScroll ensures cursor is visible
func (*TreeState) MoveCursor ¶
MoveCursor adjusts cursor position by delta
func (*TreeState) SetVisible ¶
SetVisible updates viewport height
type ViewportScroll ¶
type ViewportScroll struct {
Offset int // Row offset from top of content
ContentH int // Total content height in rows
ViewportH int // Visible viewport height
}
ViewportScroll manages row-based scroll for content regions Distinct from ScrollState which is item-index based
func NewViewportScroll ¶
func NewViewportScroll() *ViewportScroll
NewViewportScroll creates viewport scroll state
func (*ViewportScroll) CanScroll ¶
func (v *ViewportScroll) CanScroll() bool
CanScroll returns true if content exceeds viewport
func (*ViewportScroll) ClipToViewport ¶
func (v *ViewportScroll) ClipToViewport(y, h int) (viewY, viewH, contentOffset int, visible bool)
ClipToViewport maps content coordinates to viewport coordinates Returns viewY (in viewport), viewH (visible height), contentOffset (rows clipped from top) visible=false if entirely outside viewport
func (*ViewportScroll) EnsureRange ¶
func (v *ViewportScroll) EnsureRange(y, h int)
EnsureRange scrolls the least distance that brings a content row range into view; a range taller than the viewport is top-aligned
func (*ViewportScroll) IsVisible ¶
func (v *ViewportScroll) IsVisible(y, h int) bool
IsVisible returns true if content row range intersects viewport
func (*ViewportScroll) MaxOffset ¶
func (v *ViewportScroll) MaxOffset() int
MaxOffset returns maximum valid scroll offset
func (*ViewportScroll) PageDown ¶
func (v *ViewportScroll) PageDown()
PageDown scrolls down by viewport height
func (*ViewportScroll) PageUp ¶
func (v *ViewportScroll) PageUp()
PageUp scrolls up by viewport height
func (*ViewportScroll) ScrollBy ¶
func (v *ViewportScroll) ScrollBy(delta int)
ScrollBy adjusts offset by delta
func (*ViewportScroll) ScrollTo ¶
func (v *ViewportScroll) ScrollTo(pos int)
ScrollTo sets absolute offset
func (*ViewportScroll) SetDimensions ¶
func (v *ViewportScroll) SetDimensions(contentH, viewportH int)
SetDimensions updates content and viewport heights, clamps offset
Source Files
¶
- border.go
- button.go
- checkbox.go
- choice.go
- coverage.go
- dialog.go
- document.go
- editor.go
- editor_state.go
- field.go
- form.go
- input.go
- keyvalue.go
- layout.go
- list.go
- masonry.go
- modal.go
- optionlist.go
- overlay.go
- pane.go
- progress.go
- progress_overlay.go
- region.go
- render.go
- scroll.go
- scroll_state.go
- scrollbar.go
- sparkline.go
- status_bar.go
- style.go
- tab.go
- table.go
- text.go
- textfield.go
- textfield_state.go
- theme.go
- toast.go
- tree-expansion.go
- tree.go
- tree_builder.go
- tree_state.go
- viewport.go