ui

package
v2.1.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const DefaultSpinnerCharsetIndex = 14

DefaultSpinnerCharsetIndex is the charset index used across views.

Variables

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

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

func BackgroundANSI(s string, bg termenv.Color) string

BackgroundANSI draws s over background colour bg without discarding the colours it already carries. A log line arrives with its own escapes — our own node prefix ends in a reset — and a reset clears the background along with everything else, so a plain sequence+s would tint the text only as far as the first one. The background is therefore re-asserted after everything that turns one off.

func ContentRows

func ContentRows(frameHeight, chromeRows int, header, footer string) int

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

func DistributeColumns(totalWidth, gapCount, gapWidth int, cols []int, flexIndices []int) []int

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

func FilterFragment(query string) string

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 Frame

func Frame(title, content string, width int) string

func LeftPadContent

func LeftPadContent(content string) string

LeftPadContent prepends a single space to each line of content.

func OverlayCentered

func OverlayCentered(base, overlay string, width, height int) string

func RenderColumnHeader

func RenderColumnHeader(labels []string, colWidths []int) string

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

func RenderConfirmDialog(message string) string

RenderConfirmDialog renders a standard confirmation dialog with y/n options

func RenderFileBrowserDialog

func RenderFileBrowserDialog(title, currentPath string, files []string, cursor int) string

RenderFileBrowserDialog renders a file browser dialog with common styling

func RenderFramedBox

func RenderFramedBox(title, header, content, footer string, width int) string

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

func RenderFramedBoxHeight(title, header, content, footer string, width, frameHeight int) string

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

func ScopedTitle(label, scope string, count int) string

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

func ScopedTitleFiltered(label, scope string, count int, filter string) string

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

func SpinnerCharAt(frame int) string

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

func ToggleRow(items []Toggle, width int) string

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

func TrimOrPadContentToLines(content string, lines int) string

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

func TruncateANSI(s string, width int) string

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

func TruncateANSIAfter(s string, skipWidth int) string

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.

func WrapText

func WrapText(text string, width int) []string

WrapText wraps text to the specified width, breaking on word boundaries.

Types

type FrameSpec

type FrameSpec struct {
	FrameWidth          int
	FrameHeight         int
	DesiredContentLines int
}

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

type Toggle struct {
	Label string
	Value string
	Tone  ToggleTone
}

Toggle is one "Label:Value" item of a status row.

type ToggleTone

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
)

Directories

Path Synopsis
components

Jump to

Keyboard shortcuts

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