Documentation
¶
Overview ¶
Package widgets holds small, stateless, presentational render helpers — Divider, Badge, StatusIndicator, KeyHint, ProgressBar, CodeBlock, DiffView, TokenCounter — bundled into one package rather than one apiece since each is a handful of lines with no internal state.
This is a deliberately different shape from textinput/viewport: those are interactive (they implement Update(tui.Msg) (Model, tui.Cmd) and hold state like a cursor or a scroll offset), so they depend on tui and live in their own packages. Everything here is a pure function of its arguments to a string, needs no Msg handling, and never imports tui or a stateful component package: it sits below the components, not beside them.
Index ¶
- func Alert(message string, variant Variant, t theme.Theme, width int) string
- func Badge(text string, variant Variant, t theme.Theme) string
- func Banner(message string, variant Variant, t theme.Theme, width int) string
- func BarChart(items []BarItem, width int, t theme.Theme) stringdeprecated
- func BigText(text string, font Font, t theme.Theme) string
- func BigTextGradient(text string, font Font, t theme.Theme, from, to ansi.RGB) string
- func Box(title, content string, t theme.Theme, width int) string
- func Breadcrumb(items []string, t theme.Theme) string
- func Card(title, content string, t theme.Theme, width int) string
- func Center(content string, width, height int) string
- func ChatMessage(sender Sender, name, content string, timestamp time.Time, streaming bool, ...) string
- func ChatMessageRaw(sender Sender, name, content string, timestamp time.Time, streaming bool, ...) string
- func Checkbox(label string, checked, focused bool, t theme.Theme) string
- func CodeBlock(code string, width int, lineNumbers bool, t theme.Theme) string
- func CodeBlockLang(code, lang string, width int, lineNumbers bool, t theme.Theme) string
- func CompactCount(n int) string
- func DiffView(diff string, width int, t theme.Theme) string
- func Divider(width int) string
- func DividerLabel(width int, label string) string
- func DividerLabelWith(width int, label string, t theme.Theme) string
- func DividerWith(width int, t theme.Theme) string
- func ErrorBoundary(render func() string, fallback string, t theme.Theme) (out string)
- func Form(fields ...string) string
- func FormField(label string, fieldView string, err string, t theme.Theme) string
- func Gauge(percent float64, width int, t theme.Theme) stringdeprecated
- func Gradient(text string, colors []ansi.RGB, bold bool, t theme.Theme) string
- func Header(title string, t theme.Theme) string
- func HeaderWithAccessory(title, accessory string, width int, t theme.Theme) string
- func HeatMap(values [][]float64, t theme.Theme) stringdeprecated
- func InfoBox(title string, rows []TreeRow, t theme.Theme, width int) string
- func KeyHint(key, action string) string
- func KeyHints(sep string, hints ...Hint) string
- func KeyValue(pairs []KV, t theme.Theme) string
- func LineChart(values []float64, width, height int, t theme.Theme) stringdeprecated
- func Link(text, href string, showHref bool, t theme.Theme) string
- func List(items []string, marker Marker) string
- func ListWith(items []string, marker Marker, t theme.Theme) string
- func MultiProgress(items []ProgressItem, width int, t theme.Theme) string
- func Node(rendered string) layout.Node
- func Pagination(current, total int, t theme.Theme) string
- func PaginationDots(current, total int, t theme.Theme) string
- func Panel(title, content string, t theme.Theme, width int) string
- func ProgressBar(percent float64, width int, t theme.Theme) string
- func ProgressCircle(percent float64, width int, t theme.Theme) string
- func Spacer(width, height int) string
- func Sparkline(values []float64) stringdeprecated
- func SparklineWith(values []float64, t theme.Theme) stringdeprecated
- func StatusIndicator(label string, variant Variant, t theme.Theme) string
- func Stepper(steps []string, current int, t theme.Theme) string
- func Table(headers []string, rows [][]string, t theme.Theme) string
- func TableRows(headers []string, rows [][]string, headerStyle, dividerStyle ansi.Style, ...) string
- func TableRowsWith(headers []string, rows [][]string, headerStyle, dividerStyle ansi.Style, ...) string
- func Tag(text string, style TagStyle, variant Variant, t theme.Theme) string
- func Toggle(label string, on, focused bool, t theme.Theme) string
- func TokenCounter(used, limit int, t theme.Theme) string
- func Tooltip(text string, t theme.Theme, width int) string
- func TooltipOverlay(base string, text string, anchorX, anchorY int, t theme.Theme) string
- func UsageMonitor(title string, stats []UsageStat, t theme.Theme) string
- type BarItemdeprecated
- type Font
- type Hint
- type KV
- type Marker
- type ProgressItem
- type ProgressStatus
- type Sender
- type TagStyle
- type TreeRow
- type UsageStat
- type Variant
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alert ¶
Alert renders message in a bordered box colored by variant via variant.Color(t) (not t.BorderColor), like Box/Panel but with a leading severity icon that visibly differs by variant (e.g. "✗" for VariantError vs "✓" for VariantSuccess), so severity reads even without color. width behaves exactly as it does for Box/Panel: 0 sizes to content, a positive width wraps content so every rendered line's ansi.Width stays within it.
func Badge ¶
Badge renders text as a small solid-pill label colored by variant (via t's matching semantic color as the background, with t.TextInverse as the foreground), e.g. a bright-green pill reading " OK ". Every variant but VariantNeutral leads its text with Variant.Mark, so the variant shows without colour too.
func Banner ¶
Banner renders message as a full-width solid bar colored by variant via variant.Color(t) as the background (with t.TextInverse as the foreground) — no border characters at all, visually distinct from Alert's bordered box. Given a positive width, the line is padded (or truncated) so its ansi.Width equals width exactly. width<=0 sizes the bar to its content instead, with no padding, since Banner has no fixed-width requirement to satisfy in that case.
func BigText ¶
BigText renders text as multi-row, block-letter ASCII art, one glyph per character joined horizontally with a small column gap, styled in the theme's Primary color.
Each font has its own glyph table covering uppercase A-Z, digits 0-9 and space: FontBlock (5 rows, full blocks), FontSimple (5 rows, ASCII only), FontShade (5 rows, light/medium/dark shades) and FontSlim (3 rows, thin box-drawing strokes). Under an ASCII theme every font degrades to ASCII: FontBlock uses the theme's BarFull, FontShade and FontSlim map their characters to ASCII stand-ins.
Characters outside the glyph table (lowercase letters, punctuation, etc.) render as a blank glyph of the same height rather than panicking. Empty text returns "" without panicking.
func BigTextGradient ¶
BigTextGradient is BigText with a colour gradient across the columns: the first column is from, the last is to, and the columns between interpolate linearly in RGB. Only styling differs from BigText, so the stripped output and every row width are identical. A single-column text is drawn in from.
func Box ¶
Box renders content in a padded, bordered container using t's border style and color. An empty title renders no title line; a non-empty title renders as a bold line above the content, inside the border (the same composition dialog.Model.Render uses). width is the box's total rendered width, borders and padding included; 0 sizes the box to its content instead, matching layout.Box's own convention. When width is set, content is word-wrapped (and title truncated) to fit it exactly.
Example ¶
Widgets are stateless: each is a function from its inputs and a theme to a styled string, so it can be called from any View. The examples strip the styling so the output is plain text.
package main
import (
"fmt"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/theme"
"github.com/ows4444/tui/widgets"
)
func main() {
fmt.Println(ansi.StripANSI(widgets.Box("Status", "all good", theme.DarkTheme(), 20)))
}
Output: ┌──────────────────┐ │ │ │ Status │ │ all good │ │ │ └──────────────────┘
func Breadcrumb ¶
Breadcrumb renders a horizontal "a / b / c" navigation trail: each item separated by a muted " / " separator, with the last item styled distinctly (bold, Theme's Primary color) to mark the current location. Like Stepper, it's stateless — the caller passes the full path fresh each render.
Example ¶
package main
import (
"fmt"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/theme"
"github.com/ows4444/tui/widgets"
)
func main() {
fmt.Println(ansi.StripANSI(widgets.Breadcrumb([]string{"home", "docs", "api"}, theme.DarkTheme())))
}
Output: home / docs / api
func Card ¶
Card renders content the same way Panel does — a reverse-styled title row separated from the body by a divider — but always draws a rounded border, regardless of t.Border, for callers that want a Card's rounded look consistently even under a theme configured with square or double borders elsewhere. width behaves exactly as it does for Box and Panel.
func Center ¶
Center returns content padded to exactly width columns and height lines, with the content horizontally and vertically centered inside that box. Horizontal padding is split evenly between left and right, with any odd extra column going on the right; vertical padding is split evenly between top and bottom, with any odd extra line going on the bottom. If width or height is less than or equal to content's own size on that axis, that axis is left unpadded and unchanged rather than truncated.
func ChatMessage ¶
func ChatMessage(sender Sender, name, content string, timestamp time.Time, streaming bool, t theme.Theme) string
ChatMessage renders a single chat message: a header naming sender (name if non-empty, else Sender's default label) and timestamp, styled by sender via Sender.Variant's Variant color, followed by content. content may be empty; the header still renders. If streaming is true, a trailing cursor is appended after content instead of any character-reveal timing — ChatMessage is a stateless pure-render function, so the actual reveal animation stays owned by a caller's streamtext.Model elsewhere.
name and content are untrusted (model output): tabs are expanded and every escape sequence and control character except SGR styling is removed. Use ChatMessageRaw to render them unchanged.
func ChatMessageRaw ¶
func ChatMessageRaw(sender Sender, name, content string, timestamp time.Time, streaming bool, t theme.Theme) string
ChatMessageRaw is ChatMessage without sanitising: name and content are used unchanged. Only use it for trusted text.
func Checkbox ¶
Checkbox renders a single checked/unchecked indicator ("[x]"/"[ ]") followed by label — a standalone InkUI-style Checkbox. focused=true colors the indicator with t.Focus so it reads as visually distinct from an unfocused one; checked=true additionally colors the indicator with t.Success (bold) so checked/unchecked stay distinct from each other regardless of focus. An empty label renders just the indicator, with no trailing space.
For a list of checkboxes, see multiselect.Model (InkUI's CheckboxGroup): it already implements cursor navigation plus per-item Space-toggle, so this function doesn't duplicate that as a separate group widget.
func CodeBlock ¶
CodeBlock renders code in a bordered box exactly width columns wide (border and padding included), one row per source line, optionally with a right-aligned line-number gutter.
It is deliberately plain: code is drawn in t.Text with no syntax highlighting (see CodeBlockLang for Go, JSON and shell), the frame uses t.Border in t.BorderColor, and line numbers use t.Muted. Lines never wrap — one wider than the box is cut and ends in a Muted "…" — so the row count always equals the number of source lines plus the two border rows. Tabs become four spaces, carriage returns are dropped and one trailing newline is ignored. If the gutter would leave no room for code it is omitted, and below codeBlockMinWidth columns the frame is dropped and each line is just truncated to width. A width of zero or less returns "".
func CodeBlockLang ¶
CodeBlockLang is CodeBlock with syntax highlighting for lang: "go", "json", "sh", "yaml" or "python" (also "golang", "bash", "shell", "zsh", "yml", "py", "python3"); "js" ("javascript", "jsx", "mjs", "cjs"); "ts" ("typescript", "tsx"); "rust" ("rs"); "c" ("h"); "cpp" ("c++", "cc", "cxx", "hpp", "hh", "hxx"); "java"; "csharp" ("cs", "c#"); "kotlin" ("kt", "kts"); "swift"; "php"; "ruby" ("rb"); "lua"; "html" ("htm", "xhtml"; its <script> and <style> content is highlighted as JavaScript and CSS); "xml" ("svg", "xsd", "xsl", "plist"); "css"; "diff" ("patch"); "markdown" ("md"); "sql"; "toml"; "ini" ("cfg", "conf", "properties", "editorconfig", "gitconfig"); "makefile" ("make", "mk", "gnumakefile"); "dockerfile" ("docker"). Names are case-insensitive. Tokens are coloured from the theme: keywords in t.Primary, types in t.Info, strings in t.Success, numbers in t.Warning, comments in t.Muted, literals (true, nil, null, Ruby symbols) in t.Secondary, keys (JSON, YAML, TOML and INI keys, CSS properties, HTML and XML attributes) and variables (shell, PHP, Ruby and Makefile) in t.Info, and everything else in t.Text.
The highlighter is a lexer, not a parser, so it colours what it recognises and never rejects input. For an empty or unsupported lang the result is byte-identical to CodeBlock. Layout, width, gutter, tab and truncation rules are exactly CodeBlock's: the output is always width columns wide and one row per source line plus the two border rows.
func CompactCount ¶
CompactCount formats n (>= 0) as "999", "1.2k", "8k", "1.5M", ... A value that rounds up to 1000 of its unit moves to the next one (999950 -> "1M").
func DiffView ¶
DiffView renders unified-diff text (as produced by `git diff` or `diff -u`) in the same bordered box as CodeBlock, colouring each line by kind: added lines in t.Success, removed in t.Error, context in t.Text, hunk headers in t.Info, and file/metadata lines in t.Muted. The leading +/-/space marker stays visible. Framing, truncation with "…", tab and newline handling, and the width rules are exactly CodeBlock's, so every line is width columns and the row count is the diff's line count plus two.
Inside a hunk, lines are classified by the counts in its @@ header, so a removed line whose content begins "--" is not mistaken for a file header. Outside any hunk, a line starting with a single + or - counts as added or removed, so header-less snippets colour correctly. There is no line numbering and no intra-line highlighting in v1.
func Divider ¶
Divider returns a plain horizontal rule, width columns of '─'. Unlike Badge/StatusIndicator/KeyHint, it's returned unstyled — a divider is normally one uniform color, so the caller can just wrap the whole result in ansi.Style.Render themselves instead of this function taking a style parameter.
func DividerLabel ¶
DividerLabel returns a horizontal rule width columns wide with label centered in it, e.g. "── Section ───". If the label (plus one space of padding on each side) doesn't fit in width, it's truncated instead.
func DividerLabelWith ¶
DividerLabelWith is DividerLabel drawn with t's rule glyph.
func DividerWith ¶
DividerWith is Divider drawn with t's rule glyph (theme.Glyphs.RuleH), so an ASCII theme gets a row of '-'. Divider is DividerWith on the default theme.
func ErrorBoundary ¶
ErrorBoundary calls render and returns its output unchanged when it returns normally. If render panics, ErrorBoundary recovers the panic and returns fallback styled as a VariantError Alert instead of letting the panic propagate to the caller. This is a widgets-layer helper only (no Program-level rendering primitive involved): it wraps a single func() string call.
func Form ¶
Form stacks multiple already-rendered FormField blocks vertically with a blank line of separation between each, as a layout.Column rather than re-implementing block-joining. Like FormField, it does not bound or truncate its output to any width.
func FormField ¶
FormField renders label above fieldView, styled distinctly from plain body text using t.Muted, so a form's labels read as labels rather than content. A non-empty err renders as an additional line below fieldView, styled in t.Error so it stands apart from both the label and the field; an empty err renders no error line at all — not even a blank one, so a field without a validation error doesn't shift the layout below it. FormField does not bound or truncate its output to any width: it is a composition helper, not a fixed-width container like widgets.Box.
func Gradient ¶
Gradient renders text with each character individually colored, linearly interpolating across the given colors stops. The theme parameter is accepted for signature consistency with the rest of the widgets package (every widget here takes a theme.Theme) but is unused: gradients are defined entirely by the caller-supplied color stops, not by theme colors.
With len(colors) == 0 the text is returned unstyled. With a single color the text is rendered uniformly in that color (the degenerate, no-gradient case). With two or more stops, character i of n total maps to position p = i/(n-1) (or 0 when n == 1) along the gradient; p is then scaled by len(colors)-1 to find the two nearest stops and the fractional distance between them, and the color is linearly interpolated (per channel, rounded to the nearest integer) between those two stops. This stretches the interpolation proportionally across the whole string even when text is longer than colors, rather than repeating or clamping to the nearest stop.
bold=true applies bold styling on top of each character's interpolated color. Empty text returns "".
func Header ¶
Header renders a styled title bar. With no accessory it's just the styled title; with one, the title is left-aligned and the accessory (e.g. a version string or a Badge/StatusIndicator) is right-aligned within width, using the theme's Muted color.
func HeaderWithAccessory ¶
HeaderWithAccessory is Header plus a right-aligned accessory: the gap between them is a growing layout.Row child, filling whatever width title and accessory don't use themselves. If title and accessory together don't fit in width (leaving no room for even one space), they fall back to a single-space separator instead of being jammed together.
func InfoBox ¶
InfoBox renders rows inside a Panel: reuses KeyValue's "key: value" alignment when every row is flat (no row has Children anywhere), or falls back to indented tree rendering — reusing treeview.Model.View's " " (two-space) per-depth indent and ▾/space branch marker — as soon as any row is nested. width behaves exactly as it does for Panel.
func KeyHint ¶
KeyHint renders a single "[key] action" hint, e.g. "[enter] submit", with the brackets and action dim and the key itself bold.
func KeyHints ¶
KeyHints joins several KeyHint results with sep, e.g. for a status-line help string like "up/down move [enter] select [q] quit".
func KeyValue ¶
KeyValue renders pairs one per line as "key: value", padding keys with spaces (measured via ansi.Width) so every value starts at the same column regardless of key width. The key is styled distinctly from the value using t.Muted. An empty pairs slice renders as "".
func Link ¶
Link renders text as a clickable hyperlink via the OSC 8 escape sequence (ansi.Hyperlink), underlined and colored with t.Primary so it reads as a link even in terminals that ignore OSC 8.
This package has no way to detect whether the attached terminal actually supports OSC 8 hyperlinks, so showHref is an always-on visible fallback, not a conditional one: when true, the literal href is appended after the text in faint styling, guaranteeing the destination is readable even when OSC 8 support is absent (or the text is copied out of the terminal).
An empty href disables the hyperlink entirely: text is rendered plainly, with no OSC 8 wrapping. The same applies when href fails ansi.SafeLinkTarget (control characters, or a scheme other than http, https, mailto or file, including relative targets); the unsafe href is never emitted, even as the showHref fallback.
func List ¶
List renders items one per line with the given marker prefix. It is a plain, stateless render — no cursor, no Update/Model — distinct from the interactive picker.Model and multiselect.Model widgets. An empty items slice renders as "".
func ListWith ¶
ListWith is List with the bullet drawn from t (theme.Glyphs.Bullet), so an ASCII theme gets "* ". List is ListWith on the default theme.
func MultiProgress ¶
func MultiProgress(items []ProgressItem, width int, t theme.Theme) string
MultiProgress renders one row per item — label, status indicator, and a ProgressBar — stacked vertically as a layout.Column. Labels are padded to a common column across all rows following KeyValue's alignment convention (measured with ansi.Width), and status text is likewise padded to a common column so every row's bar starts at the same offset. The bar is sized to fill whatever of width remains after the label and status columns; there is no aggregate or combined-total row. An empty items renders as "".
func Node ¶
Node adapts any widget's rendered string (Badge, Table, Gauge, ...) to a layout.Node. Measure reports the string's natural size; Render pads or clips to the allotted size, so the result is always exactly W x H. It does not change what the widget functions return.
func Pagination ¶
Pagination renders a compact "Page X of Y" indicator (1-indexed). current is clamped into [1, total] so an out-of-range value never produces a nonsensical or panicking result. Like ProgressBar, it's stateless — the caller owns "current page" and passes it in fresh on every render.
func PaginationDots ¶
PaginationDots renders one dot per page, filled for the current page (Theme's Primary color) and hollow for the rest (Theme's Muted color) — mirroring ProgressBar's filled/track color convention as a compact page indicator alternative to Pagination's "Page X of Y" text.
func Panel ¶
Panel renders content in a padded, bordered container like Box, but with its title on its own reverse-styled row, separated from the body by a divider line, rather than just a bold line — Box for when the title needs to stand apart from the content, not just be labeled. width behaves exactly as it does for Box.
func ProgressBar ¶
ProgressBar renders a determinate progress meter width columns wide, filled proportionally to percent (clamped to [0,1]) — the static counterpart to an animated spinner/loading-bar widget. Unlike those, it has no internal state: the caller owns "current progress" (bytes downloaded / total, steps done / total, ...) and passes it in fresh on every render.
func ProgressCircle ¶
ProgressCircle renders a full 360-degree ring width columns wide, filled clockwise from the top in proportion to percent (clamped to [0,1]; NaN counts as 0), with the rounded percentage centred in the middle of the ring. Like Gauge and ProgressBar it is stateless: the caller passes the current value in on every render.
It reuses Gauge's braille dot-arc-filling technique (brailleArc): the only differences are that the centre sits in the middle of the grid instead of on the bottom edge, so both the top and bottom halves of the ring are drawn, and the angle test accepts the full 0..2*Pi range instead of only the upper half-plane. The filled part uses t.Primary, the remainder t.Muted, and the label t.Text. Every line is exactly width columns wide and the line count depends only on width. Below progressCircleMinWidth columns there's no room for the ring, and ProgressCircle returns a one-line ProgressBar instead.
func Spacer ¶
Spacer returns a block of exactly height blank lines, each exactly width spaces wide. width <= 0 or height <= 0 returns "" rather than panicking or producing negative-sized output.
func SparklineWith
deprecated
func StatusIndicator ¶
StatusIndicator renders a colored dot followed by a label, e.g. a green "● Running", colored by variant via t's matching semantic color.
func Stepper ¶
Stepper renders a horizontal sequence of step labels, marking steps before current as done, current as active, and the rest as upcoming. Like ProgressBar, it's stateless — the caller owns "which step we're on" and passes it in fresh each render.
func Table ¶
Table renders a static, column-aligned table: a styled header row, a divider, then each data row. Like ProgressBar, it's stateless — for row highlighting/navigation, see the datatable package instead.
func TableRows ¶
func TableRows(headers []string, rows [][]string, headerStyle, dividerStyle ansi.Style, styleForRow func(i int) ansi.Style) string
TableRows renders headers/rows with the same column-width computation, divider, and cell padding as Table, except each data row's style comes from styleForRow(i) instead of always being unstyled — the shared implementation datatable.Model.View uses to highlight its cursor row without reimplementing column layout. headerStyle and dividerStyle style the header row and the divider line respectively. An empty headers returns "".
func TableRowsWith ¶
func TableRowsWith(headers []string, rows [][]string, headerStyle, dividerStyle ansi.Style, styleForRow func(i int) ansi.Style, t theme.Theme) string
TableRowsWith is TableRows with the divider drawn from t's rule glyph (theme.Glyphs.RuleH), so an ASCII theme gets a row of '-'.
func Tag ¶
Tag renders text as a small chip colored by variant (via widgets.Variant's existing color mapping — no separate severity type), either as a solid filled pill (TagSolid, Badge's Background+TextInverse convention) or as an outlined chip with just a colored border/foreground and no background fill (TagOutline).
Tag is a pure render function with no Model/Update of its own, following widgets.Checkbox's caller-owns-state convention: dismissing/removing a tag is the CALLER's responsibility — drop it from the caller's own slice of tags and re-render without it. Tag itself has no notion of dismissal or interactive state.
Empty text renders a minimal chip (just the outline/pill markers) without panicking.
func Toggle ¶
Toggle renders a single on/off switch ("(●)" on, "( )" off) followed by label — a standalone InkUI-style Toggle, the switch-shaped sibling of Checkbox. Its coloring follows the same convention Checkbox uses: on state is colored with t.Success so it reads as distinct from off (which uses t.Muted), and focused=true colors and bolds the indicator with t.Focus (or keeps t.Success, bolded, when also on) so focus stays visually distinct from an unfocused Toggle the same way it does for Checkbox. An empty label renders just the indicator, with no trailing space.
For a single-choice list, see picker.Model (InkUI's RadioGroup): this function only renders one standalone switch, not a group of them.
func TokenCounter ¶
TokenCounter renders a one-line token readout for an AI-chat UI: "1.2k / 8k tokens" with a limit, "1.2k tokens" without (limit <= 0). Counts are compact — exact below 1000, then k/M/B with one decimal (rounded half up, a trailing ".0" dropped) — and a negative used counts as 0. Like Badge it is stateless: pass the current numbers on every render.
The colour warns as the limit nears: t.Muted below 80% of limit, t.Warning from 80% up to 100%, and bold t.Error from 100% on. With no limit there is nothing to warn about, so it stays t.Muted.
func Tooltip ¶
Tooltip renders text in a small bordered box styled via t.Info (so a tooltip visibly differs from the neutral Box/Panel border color), the same width convention as Box/Alert: width == 0 sizes the box to text, a positive width wraps text so every rendered line's ansi.Width stays within it.
func TooltipOverlay ¶
TooltipOverlay composites a Tooltip showing text onto base near the anchor point (anchorX, anchorY), via layout.Overlay.
Default placement is below and right-aligned to the anchor: the tooltip's top-left corner starts at (anchorX, anchorY+1), so the tooltip sits directly under the anchor and grows to the right of it (its left edge, not its right edge, is what lines up with anchorX).
If that default placement would push the tooltip's right edge (anchorX + tooltip width) past base's rendered width, the tooltip is shifted left just enough to stay within base's width instead of being clipped by Overlay.
If placing the tooltip below the anchor would push it past base's last line (anchorY + 1 + tooltip height > base's line count), the tooltip is placed above the anchor instead, its bottom edge ending at the row just before anchorY.
func UsageMonitor ¶
UsageMonitor renders a titled panel of usage stat rows, one per line, each formatted "label: value" or "label: value / limit" when Limit > 0. Values are formatted with TokenCounter's compact exact/k/M/B rule (CompactCount) and colored with the same Muted/Warning/Error threshold (tokenCounterStyle): Muted below 80% of limit, Warning from 80% up to 100%, bold Error at/over limit, and always Muted when Limit <= 0.
Rows are aligned to a common label column following KeyValue's padding convention (padding measured via ansi.Width to the widest label). An empty stats slice renders just the title, or "" if title is also empty.
Types ¶
type Font ¶
type Font int
Font selects the glyph style BigText renders with.
const ( // FontBlock is a solid 5-row block glyph set covering uppercase // A-Z, digits 0-9, and space. FontBlock Font = iota // FontSimple is a 5-row font drawn only with ASCII characters // (+ - | / \ and similar). FontSimple // FontShade is a 5-row block font drawn with the light, medium and dark // shade characters for depth. FontShade // FontSlim is a 3-row font drawn with thin box-drawing strokes. FontSlim )
type Hint ¶
Hint is one KeyHint's worth of arguments, for building a help line out of several with KeyHints.
type ProgressItem ¶
type ProgressItem struct {
Label string
Percent float64
Status ProgressStatus
}
ProgressItem is one row of a MultiProgress: a labeled, independently tracked progress meter with its own lifecycle status.
type ProgressStatus ¶
type ProgressStatus int
ProgressStatus is the lifecycle state of a MultiProgress row, driving both its StatusIndicator text and color (via Variant).
const ( // ProgressPending is a row not started yet ("Pending", muted). It is // the zero value. ProgressPending ProgressStatus = iota // ProgressRunning is a row in progress ("Running", Info colour). ProgressRunning // ProgressDone is a finished row ("Done", Success colour). ProgressDone // ProgressError is a failed row ("Error", Error colour). ProgressError )
func (ProgressStatus) String ¶
func (s ProgressStatus) String() string
String is the label StatusIndicator renders for s.
func (ProgressStatus) Variant ¶
func (s ProgressStatus) Variant() Variant
Variant maps s to the Variant (and so the Theme color) StatusIndicator renders it with.
type Sender ¶
type Sender int
Sender identifies who a ChatMessage is from, so ChatMessage can style the header distinctly per sender via widgets.Variant's existing color mapping rather than inventing a parallel one.
const ( // SenderUser is a message from the user (Muted header colour). It is // the zero value. SenderUser Sender = iota // SenderAssistant is a message from the assistant (Success colour). SenderAssistant // SenderSystem is a system notice (Info colour). SenderSystem // SenderError is an error message (Error colour). SenderError )
type TagStyle ¶
type TagStyle int
TagStyle selects how Tag fills its chip.
const ( // TagSolid renders a filled background chip, matching Badge's // Background(variant.Color(t))+Foreground(t.TextInverse) convention. TagSolid TagStyle = iota // TagOutline renders only a colored border/foreground, with no // background fill, so it stays visually distinct from TagSolid. TagOutline )
type TreeRow ¶
TreeRow is one row of an InfoBox: a key/value pair, optionally with nested Children rendered indented beneath it. A row with Children renders as a tree branch (treeview's depth-indent/marker convention); a row with no Children renders as a flat "key: value" line.
type UsageStat ¶
UsageStat is a single tracked quantity rendered as one UsageMonitor row: a label, its current Value, and an optional Limit (Limit <= 0 means "no limit").
type Variant ¶
type Variant int
Variant selects which of a Theme's semantic colors Badge and StatusIndicator render with.
const ( // VariantNeutral uses the Theme's Muted colour. It is the zero value. VariantNeutral Variant = iota // VariantInfo uses the Theme's Info colour. VariantInfo // VariantSuccess uses the Theme's Success colour. VariantSuccess // VariantWarning uses the Theme's Warning colour. VariantWarning // VariantError uses the Theme's Error colour. VariantError )
func (Variant) Color ¶
Color resolves v to one of t's semantic colors — exported so other packages (e.g. toast) can share the same Variant-to-color mapping instead of re-implementing it.
Source Files
¶
- alert.go
- badge.go
- banner.go
- bigtext.go
- box.go
- breadcrumb.go
- card.go
- center.go
- chart_deprecated.go
- chatmessage.go
- checkbox.go
- codeblock.go
- codeblock_lang.go
- diffview.go
- divider.go
- doc.go
- errorboundary.go
- form.go
- gradient.go
- header.go
- infobox.go
- keyhint.go
- keyvalue.go
- layoutnode.go
- link.go
- list.go
- multiprogress.go
- pagination.go
- panel.go
- progressbar.go
- progresscircle.go
- spacer.go
- status.go
- stepper.go
- table.go
- tag.go
- toggle.go
- tokencounter.go
- tooltip.go
- usagemonitor.go
- variant.go