term

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package term renders a ui Node tree as terminal text: headings, paragraphs word-wrapped at a width, lists, tables, quotes, code, links, and inline bold/italic/underline as ANSI styles when Color is on.

It walks the tree (ui.Walk), so it sees elements and text. A component that only renders HTML — a templ component, a NodeFunc — and Safe content arrive as HTML, which is parsed into the same tree, so their headings, tables and lists lay out as if written in JSX.

The package is pure: whether to use color (NO_COLOR, a tty) is the caller's decision. The page's text never carries terminal commands: its control characters, but newlines and tabs, are dropped (ANSI escapes, OSC sequences, carriage returns, C1 controls), so text a visitor wrote can't restyle, retitle or clear the terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(ctx context.Context, w io.Writer, n ui.Node, o Options) error

Render writes n as terminal text to w, ending with a newline unless empty.

func String

func String(ctx context.Context, n ui.Node, o Options) (string, error)

String renders n as terminal text.

Types

type Options

type Options struct {
	Width int  // wrap paragraphs at this many columns; 0 doesn't wrap
	Color bool // ANSI styles: bold, italic, underline, dim, inverse
}

Options shape the output.

Jump to

Keyboard shortcuts

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