layout

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 2 Imported by: 0

Documentation

Overview

Package layout provides terminal-aware text layout primitives. It owns: visual width measurement, ANSI-transparent wrapping, and value column detection. It has no I/O and no terminal detection — those are the caller's responsibility.

Index

Constants

View Source
const (
	// FramePrefix is the visible column width of the section row prefix "    │ ".
	// Used by callers computing a content budget from terminal width.
	FramePrefix = 6

	// DefaultContentWidth is the fallback content budget when terminal width
	// cannot be detected (CI pipes, file output, etc.).
	// 120 is a safe width for CI log viewers and wide terminals.
	DefaultContentWidth = 120
)

Variables

This section is empty.

Functions

func DetectValueIndent

func DetectValueIndent(line string) int

DetectValueIndent returns the column position where the value starts in a formatted row string — immediately after the first padding gap of 2+ spaces that follows non-space content. Used to align continuation lines.

For "key value..." this returns the position of 'v' (e.g. 16). Returns 0 if no gap is found.

func VisualWidth

func VisualWidth(s string) int

VisualWidth returns the visible column width of s. ANSI escape sequences contribute zero width; wide characters (emoji, CJK) are counted at their actual terminal column width via go-runewidth.

func WrapContent

func WrapContent(line string, budget int) []string

WrapContent wraps line at word boundaries so each segment fits within budget visible columns. ANSI escape sequences are transparent (zero visual width); emoji and other wide characters are measured at their true terminal width.

Wrap pattern:

first line:        "key   value value value"
continuation:      "      value value value"

Continuation lines are indented to the value column — the position after the first padding gap (2+ spaces) that follows key content.

The "..." ellipsis is used ONLY for hard mid-token cuts (no word boundary available). Word-boundary wraps are clean — no decoration.

Types

This section is empty.

Jump to

Keyboard shortcuts

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