ansi

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ansi holds small, dependency-free ANSI helpers for the corners of the library where lipgloss's full \x1b[0m reset is the wrong tool — most notably cells inside a styled row (e.g. pkg/table's selected row) where an inner reset would clobber the row's background.

Components that own their own pane (pkg/list, pkg/tree, pkg/logview, …) render with their own per-row styling and you can keep using lipgloss inside them. Reach for this package only when downstream rendering will wrap your content in its own SGR with a background you want preserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CellColor

func CellColor(n int, text string) string

CellColor wraps text in a foreground SGR with a foreground-only reset (\x1b[39m). The 39 reset preserves any outer background, making it safe to nest inside a styled row (e.g. pkg/table's selected row) where the row's Background would otherwise be clobbered by lipgloss's full \x1b[0m reset.

n is a 256-color palette index (0–255):

0–7    standard 8-color palette       (emitted as \x1b[3Nm — 4 bytes open)
8–15   bright variants                (emitted as \x1b[9Nm — 4 bytes open)
16–255 256-color cube + grayscale     (emitted as \x1b[38;5;Nm — 8–10 bytes open)

CellColor picks the shortest valid form to keep escape overhead small.

func CellColorRGB added in v0.24.0

func CellColorRGB(r, g, b uint8, text string) string

CellColorRGB is CellColor for a 24-bit color, emitting the truecolor foreground form with the same foreground-only reset. Callers that hold a lipgloss color rather than a palette index resolve it to RGB and come here; keeping the escape construction in one place is why this lives beside CellColor instead of in the caller.

func ExtractHyperlink(s string) (url, text string, ok bool)

ExtractHyperlink pulls the url and visible text out of a string wrapped by Hyperlink. ok is false when s isn't an OSC 8 envelope, so callers can treat the cell as a bare string in that case. Useful in a screen's Update when "press o to open the focused row's URL" needs the original target — shift-click handles the common case at the terminal level, but programmatic open paths need the URL back.

func Hyperlink(url, text string) string

Hyperlink wraps text in an OSC 8 hyperlink escape so terminals that support it (alacritty, tmux, kitty, wezterm, iTerm2) launch url on click. The wrapper is invisible to terminal width calculation and x/ansi.Cut preserves both the open and close sequences across truncation, so a long URL stays attached to its cell even when the visible label is cut to fit a narrow column.

Use this in pkg/table cells when you want shift-click / cmd-click to open the full URL regardless of column width. Bare URL text would be truncated mid-string and break the launched URL; the OSC 8 envelope decouples display text from the underlying link.

Types

This section is empty.

Jump to

Keyboard shortcuts

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