ui

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package ui holds presentation helpers for the review client: the color theme and static text (help, overlays). Rendering logic that needs model state lives in the app package; this package stays free of app dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinThemeNames added in v0.0.14

func BuiltinThemeNames() []string

BuiltinThemeNames are the reserved theme names: user theme files may not claim them.

func HelpText

func HelpText() string

HelpText returns the key reference shown in the help overlay.

func RenderMarkdown

func RenderMarkdown(src string, width int, th Theme) []string

RenderMarkdown renders a small Markdown subset for terminal display: ATX headings, fenced code blocks, block quotes, thematic breaks, bullet lists, and inline code/link/bold spans. It wraps prose at width (fenced code is left verbatim) and returns the styled lines. It is deliberately not a full Markdown implementation — unknown constructs pass through as plain text.

func ThemeRoles added in v0.0.14

func ThemeRoles() []string

ThemeRoles are the restylable role names, in the order they are documented. The validator uses this list so a typoed role in a theme file is named instead of silently ignored.

Types

type Highlighter

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

Highlighter renders single source lines to ANSI-colored strings using Chroma. It highlights per line (no cross-line lexer state), which is the right trade-off for a diff viewer where lines are shown out of block context. It is disabled when NO_COLOR is set or LEANREVIEW_SYNTAX=0, in which case Line is a passthrough.

func NewHighlighter

func NewHighlighter(enabled bool, style string) *Highlighter

NewHighlighter builds a highlighter with an explicit enabled flag and Chroma style name. The style "auto" (or "") picks one suited to the terminal background — a dark-background style on dark terminals, a light one otherwise — because Chroma styles are background-specific: a light style's dark foreground tokens are unreadable on a dark terminal. An unknown style falls back to the auto choice.

func NewHighlighterFromEnv

func NewHighlighterFromEnv() *Highlighter

NewHighlighterFromEnv builds a highlighter honoring NO_COLOR and LEANREVIEW_SYNTAX with the auto-detected style. Used where no config is available (e.g. tests).

func (*Highlighter) ContentLines added in v0.0.5

func (h *Highlighter) ContentLines(path string, content []byte) []string

ContentLines highlights a whole file and returns one styled string per source line. Tokenizing the full content (rather than line by line) is what makes multi-line constructs — block comments, raw strings, heredocs — color correctly: the lexer keeps its state across lines.

Each returned line is self-contained (token styles are re-emitted after every newline) and uses foreground-only SGR codes terminated by attribute clears, never a full reset — so a caller may wrap a whole line in a background tint and the tint survives the embedded styling. Returns nil when highlighting is disabled or fails; callers fall back to plain text.

func (*Highlighter) Enabled

func (h *Highlighter) Enabled() bool

Enabled reports whether highlighting is active.

func (*Highlighter) Line

func (h *Highlighter) Line(path, text string) string

Line highlights one line of source from the file at path. On any failure it returns the input unchanged, so callers can use the result directly.

type ImageMode added in v0.0.4

type ImageMode uint8

ImageMode selects how comment images are rendered.

const (
	// ImagesOff renders a textual tag only.
	ImagesOff ImageMode = iota
	// ImagesChafa shells out to chafa for ANSI cell art — works in any
	// terminal and scrolls like ordinary text.
	ImagesChafa
	// ImagesKitty uses the kitty graphics protocol with Unicode placeholders,
	// the only kitty mode whose images scroll with the surrounding rows.
	ImagesKitty
)

type ImageRenderer added in v0.0.4

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

ImageRenderer renders image files into terminal rows, memoizing per (path, size): rendering happens inside the draw path, and re-running chafa or re-encoding a PNG on every keystroke would be absurd.

func NewImageRenderer added in v0.0.4

func NewImageRenderer(mode string) *ImageRenderer

NewImageRenderer builds a renderer for the configured mode: "kitty", "chafa", "off", or "auto" — auto prefers the kitty protocol on terminals that speak it (kitty, ghostty), then chafa when installed, then off. Detection is heuristic, which is exactly why the config override exists.

func (*ImageRenderer) Enabled added in v0.0.4

func (r *ImageRenderer) Enabled() bool

Enabled reports whether any graphical rendering is active.

func (*ImageRenderer) Render added in v0.0.4

func (r *ImageRenderer) Render(path string, maxCols, maxRows int) ([]string, bool)

Render returns terminal rows displaying the image at path within the given cell budget, or ok=false when the file cannot be rendered (missing, undecodable, mode off) — the caller falls back to a textual tag.

func (*ImageRenderer) TakeTransmissions added in v0.0.8

func (r *ImageRenderer) TakeTransmissions() string

TakeTransmissions returns (and clears) the pending kitty payload transmissions. It must be called from the code path whose output is guaranteed to reach the terminal — the top of View — never from row construction: rows are also built during update processing (cursor clamping, layout math) where the strings are discarded, and a payload emitted there dies unseen, leaving images invisible until an unrelated width change forces a re-render.

type StyleOverride added in v0.0.14

type StyleOverride struct {
	FG        string
	BG        string
	Bold      *bool
	Underline *bool
	Reverse   *bool
}

StyleOverride restyles one theme role from a theme file. Colors are any lipgloss-accepted terminal color: an ANSI palette index ("114") or hex ("#87d787"). Attribute pointers distinguish "unset" (keep the base) from an explicit false (clear the base's attribute).

type Theme

type Theme struct {
	Addition lipgloss.Style
	Deletion lipgloss.Style
	Context  lipgloss.Style
	Metadata lipgloss.Style

	Gutter lipgloss.Style
	Cursor lipgloss.Style
	Select lipgloss.Style
	Search lipgloss.Style
	Marker lipgloss.Style

	Title  lipgloss.Style
	Status lipgloss.Style
	Error  lipgloss.Style
	Key    lipgloss.Style
	Faint  lipgloss.Style

	// Comment styles inline comment/thread preview text; brighter than Faint
	// so review discussion stays readable.
	Comment lipgloss.Style

	// AdditionTint/DeletionTint are faint background washes carrying diff
	// identity under syntax-colored changed lines (change_colors: syntax).
	// Background-only so the syntax foregrounds show through.
	AdditionTint lipgloss.Style
	DeletionTint lipgloss.Style
}

Theme is the set of styles used to render the diff and chrome. When NO_COLOR is set (or the terminal has no color), the palette collapses to attributes only (bold/reverse), keeping the UI usable.

func BuiltinTheme added in v0.0.14

func BuiltinTheme(name string) (Theme, bool)

BuiltinTheme returns a built-in theme by name ("" means default) and whether the name was recognised.

func DefaultTheme

func DefaultTheme() Theme

DefaultTheme returns the standard palette (terminal background picks the light or dark colors), or a monochrome variant when NO_COLOR is set.

func (Theme) WithOverrides added in v0.0.14

func (t Theme) WithOverrides(overrides map[string]StyleOverride) (Theme, error)

WithOverrides returns a copy of the theme with the given role overrides applied on top — a theme file restyles only the roles it names, so a four-line theme is a valid theme. Unknown roles error (the caller surfaces them; silently ignoring a typo would make the theme look broken instead).

Jump to

Keyboard shortcuts

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