Documentation
¶
Index ¶
- Constants
- Variables
- func ContentRows(frameHeight, chromeRows int, header, footer string) int
- func DistributeColumns(totalWidth, gapCount, gapWidth int, cols []int, flexIndices []int) []int
- func FilterFragment(query string) string
- func Frame(title, content string, width int) string
- func LeftPadContent(content string) string
- func OverlayCentered(base, overlay string, width, height int) string
- func RenderColumnHeader(labels []string, colWidths []int) string
- func RenderConfirmDialog(message string) string
- func RenderFileBrowserDialog(title, currentPath string, files []string, cursor int) string
- func RenderFramedBox(title, header, content, footer string, width int) string
- func RenderFramedBoxHeight(title, header, content, footer string, width, frameHeight int) string
- func RenderViewFrame(title, header, content, footer string, width, height int, fullscreen bool) string
- func ScopedTitle(label, scope string, count int) string
- func ScopedTitleFiltered(label, scope string, count int, filter string) string
- func SpinnerCharAt(frame int) string
- func SpinnerMarker() string
- func ToggleRow(items []Toggle, width int) string
- func TrimOrPadContentToLines(content string, lines int) string
- func TruncateANSI(s string, width int) string
- func TruncateANSIAfter(s string, skipWidth int) string
- func WrapText(text string, width int) []string
- type FrameSpec
- type Toggle
- type ToggleTone
Constants ¶
const ( // FrameChromeColumns is what a frame spends on itself horizontally: the two // border columns, plus a column of padding inside each of them. Turning a // content or viewport width into the width of the frame around it means // adding this, and going the other way means subtracting it. FrameChromeColumns = 4 // BorderColumns is the two vertical border glyphs alone, without the // padding — the span between the corners of a frame of a given width is // that width less this. BorderColumns = 2 // FramedChromeRows is what RenderViewFrame's bordered layout spends on the // frame itself: the top border, which carries the title, and the bottom one. FramedChromeRows = 2 // FullscreenChromeRows is what its borderless layout spends instead: a // single centered title line. FullscreenChromeRows = 1 )
const DefaultSpinnerCharsetIndex = 14
DefaultSpinnerCharsetIndex is the charset index used across views.
Variables ¶
var ( BorderStyle = lipgloss.NewStyle(). Border(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("117")). Padding(0, 1) StatusStyle = lipgloss.NewStyle(). Padding(0, 1). Width(30) ListStyle = lipgloss.NewStyle(). Border(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("117")). Margin(1, 0). Padding(1) HelpStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#888888")). Italic(true). Margin(1, 0) CursorStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("230")). Background(lipgloss.Color("63")). Bold(true) StatusBarStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("250")). Background(lipgloss.Color("237")). Padding(0, 1) )
var ( FrameTitleStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("81")). Bold(true) FrameHeaderStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("15")). Bold(true) FrameBorderColor = lipgloss.Color("117") ListItemStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("117")) ListSelectedStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("230")). Background(lipgloss.Color("63")). Bold(true) )
Styles (you can override these per-view if desired)
var Rainbow = []lipgloss.Style{ lipgloss.NewStyle().Foreground(lipgloss.Color("#FF5F87")), lipgloss.NewStyle().Foreground(lipgloss.Color("#FFAF00")), lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFF00")), lipgloss.NewStyle().Foreground(lipgloss.Color("#00FF87")), lipgloss.NewStyle().Foreground(lipgloss.Color("#5FD7FF")), lipgloss.NewStyle().Foreground(lipgloss.Color("#AF87FF")), }
Functions ¶
func ContentRows ¶ added in v1.14.0
ContentRows is the space left for content inside a frame of frameHeight rows once the frame's own chrome (chromeRows) and the header and footer have taken theirs. A view that renders a viewport should size that viewport to this, so what the viewport scrolls is exactly what the frame draws.
func DistributeColumns ¶
DistributeColumns adjusts column widths to fit `totalWidth` after accounting for `gapCount` gaps of `gapWidth` each. `cols` contains preferred/min widths for each column. `flexIndices` are indexes into `cols` that are allowed to absorb remaining space when total cols < available, or to be reduced when cols exceed available. The function returns a new slice with adjusted widths.
func FilterFragment ¶
FilterFragment renders a trailing " </query>" fragment marking an active `/` filter, mirroring k9s (which appends the filter rather than folding it into the scope). The angle brackets share the label colour while the "/query" reuses the scope colour, so the filter reads as a scope refinement. It returns "" when no filter is active. Like the rest of ScopedTitle the result already carries ANSI styling, so styleFrameTitle passes it through unchanged.
func LeftPadContent ¶
LeftPadContent prepends a single space to each line of content.
func OverlayCentered ¶
func RenderColumnHeader ¶
RenderColumnHeader builds a single-line header from labels and column widths. `labels` and `colWidths` must have the same length. It applies the FrameHeaderStyle to the resulting line so callers can place it in the framed header slot.
func RenderConfirmDialog ¶
RenderConfirmDialog renders a standard confirmation dialog with y/n options
func RenderFileBrowserDialog ¶
RenderFileBrowserDialog renders a file browser dialog with common styling
func RenderFramedBox ¶
RenderFramedBox draws a bordered frame with title, optional header, and content. If width <= 0, defaults to content width + padding. ANSI sequences in content are preserved.
func RenderFramedBoxHeight ¶
RenderFramedBoxHeight renders a framed box constrained to `frameHeight` lines (including borders). If `frameHeight` <= 0 the function falls back to the unconstrained `RenderFramedBox` behavior. This helper pads the content so the resulting framed box occupies exactly `frameHeight` lines when possible.
func RenderViewFrame ¶
func RenderViewFrame(title, header, content, footer string, width, height int, fullscreen bool) string
RenderViewFrame composes a complete framed view from its parts. It computes frame dimensions, trims/pads content to fit, and renders the bordered frame. When fullscreen is true the borders are dropped and a centered title line takes their place. Either way the result occupies exactly `height` rows, as long as the chrome, header and footer fit in them.
func ScopedTitle ¶
ScopedTitle renders a frame title of the form "Label(scope)[count]" with the label/separators, scope, and count coloured distinctly. The returned string already carries its own ANSI styling, so RenderFramedBox passes it through unchanged instead of re-applying FrameTitleStyle (see styleFrameTitle).
func ScopedTitleFiltered ¶
ScopedTitleFiltered renders ScopedTitle and, when filter is non-empty, appends a FilterFragment so the header reflects the active `/` filter, e.g. "Stacks(all)[1] </pos>". The count is expected to be the post-filter row count. See FilterFragment.
func SpinnerCharAt ¶
SpinnerCharAt returns the spinner character for the given frame index. Falls back to an ellipsis if spinner charset is not available.
func SpinnerMarker ¶
func SpinnerMarker() string
SpinnerMarker returns the first spinner character (useful as a marker).
func ToggleRow ¶ added in v1.14.0
ToggleRow renders items as "Label:Value", gapped by toggleGap and centred in width, so a view's options read at a glance instead of hiding in prose. The result is always a single line no wider than width: the row is a frame header, and a header that grows a second line silently shrinks the content the frame draws.
A narrowing terminal closes the gaps first and only then drops items, from the right, marking the cut with "…" rather than truncating mid-item — a value cut to "Hid" reads as a state rather than as missing text.
func TrimOrPadContentToLines ¶
TrimOrPadContentToLines returns content limited to exactly `lines` rows, padding with empty lines when shorter. Useful when framing viewport content to a fixed height.
func TruncateANSI ¶
TruncateANSI truncates a string with ANSI codes to a specific visual (cell) width. It is grapheme/display-width aware (wide East-Asian chars and emoji count as 2 cells) and never splits an escape sequence.
func TruncateANSIAfter ¶
TruncateANSIAfter skips skipWidth visual cells and returns the rest, re-emitting the active SGR state at the cut so colors survive. It is grapheme/display-width aware and never splits an escape sequence.
Types ¶
type FrameSpec ¶
FrameSpec captures the calculated dimensions for a framed view.
func ComputeFrameDimensions ¶
func ComputeFrameDimensions(viewportWidth, viewportHeight, fallbackWidth, fallbackHeight int, header, footer string) FrameSpec
ComputeFrameDimensions derives consistent frame sizing across views.
Inputs: - viewportWidth/Height: usable dimensions provided by app/update.go - fallbackWidth/Height: model dimensions to use if the viewport is not ready - header/footer: rendered strings used to count occupied lines
Behavior aligns with stacks view: add 4 columns for frame padding, use the already-adjusted viewport height directly, and compute the inner content lines as frameHeight - vertical padding - header - footer (never negative).
type Toggle ¶ added in v1.14.0
type Toggle struct {
Label string
Value string
Tone ToggleTone
}
Toggle is one "Label:Value" item of a status row.
type ToggleTone ¶ added in v1.14.0
type ToggleTone int
ToggleTone selects the colour a toggle's value carries.
const ( // ToggleOff dims the value: the option is not engaged. ToggleOff ToggleTone = iota // ToggleOn highlights the value: the option is engaged. ToggleOn // ToggleInfo marks a value that is not a yes/no — a node name, a query. ToggleInfo )