render

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package render turns session content into pre-styled, pre-wrapped terminal lines: markdown through a goldmark AST walk, fenced code through a chroma highlighter bucketed into the theme's syntax roles, and file changes through a width-adaptive diff view. Everything it returns obeys the screen contract: each string is one terminal row no wider than the given width, and every styled span is self-contained (prefix, text, reset), so the output can be committed to scrollback or repainted in the live region without any escape-state bookkeeping.

The package is pure: no clock, no terminal, nothing mutated per render. The same source at the same width always renders to the same lines, which keeps it property-testable and safe to call from a replayed session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(th *theme.Theme, path, before, after string, width int) []string

Diff renders the change from before to after as themed terminal lines: a header naming the path with added and removed counts, then hunks with line-number gutters. The layout adapts to width: side-by-side columns on a wide terminal, unified below that. Paired changed lines carry a word-level highlight (reverse video over the add and remove styles) so a one-token edit inside a long line is findable at a glance.

func Highlight

func Highlight(th *theme.Theme, lang, code string, width int) []string

Highlight renders source code as themed rows of at most width cells, using the lexer registered for lang (or plain code styling when the language is unknown). Code wraps hard rather than word-wraps: whitespace is content.

Types

type Markdown

type Markdown struct {
	// contains filtered or unexported fields
}

Markdown renders markdown source to themed terminal lines. It understands the GFM constructs the session actually meets in model output: headings, paragraphs, fenced and indented code (syntax-highlighted), blockquotes, nested ordered and unordered lists, task lists, tables, thematic breaks, links, images, emphasis, strikethrough, and inline code. Unknown or raw HTML degrades to muted plain text, never to dropped content.

func NewMarkdown

func NewMarkdown(th *theme.Theme) *Markdown

NewMarkdown returns a renderer bound to a theme. The parser is retained because goldmark parsers are expensive to build and safe to reuse.

func (*Markdown) Render

func (m *Markdown) Render(source string, width int) []string

Render parses source and renders it to rows of at most width cells.

Jump to

Keyboard shortcuts

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