mdlite

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mdlite prepares a provider's output for a terminal. Render converts the assistant's markdown prose to ANSI (ADR-0024 Decision 5): bold, inline code, headings, bullets, and code fences, and nothing more — the line-based, self-written conversion the ADR chose over a markdown-renderer dependency (glamour et al.), crossing into markup only far enough to make the answer readable, not to typeset it (links, tables, and numbered lists are left untouched). ToolOutput (ADR-0030) handles the other kind of provider output — a tool's own already-ANSI result — keeping its colour but stripping the escapes that would break the chat's layout.

Render carries no environment knowledge: whether a stream is a TTY, whether NO_COLOR is set, is the caller's gate (the same one dim() uses), not this package's. Render is a pure function of its input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(text string) string

Render converts one message's markdown to ANSI. Fence state is scoped to the single call — a Provider sends one message as one event, so a fence never spans calls, and a caller that reused state across messages would leak an unclosed fence into unrelated text.

func ToolOutput

func ToolOutput(s string, maxVisible, maxLines int) (out string, truncated bool)

ToolOutput prepares a tool's raw output for the chat's terminal view (ADR-0030). Tool output already carries its own ANSI — a Bash colour demo, a coloured diff — so it must not go through Render, which is for prose and would mangle live escapes (a `#` would bold, a backtick would be eaten, an SGR byte would be misread). ToolOutput keeps only SGR (colour/style) sequences (`ESC [ … m`) and drops every other escape and control byte: a stray cursor move, screen clear, or carriage return from a tool would break the chat's gutter and background, and passing arbitrary escapes through would hand the terminal to whatever the provider ran (Decision 2).

A colour left open across a newline is closed before the break and reopened on the next line's first output, so the caller's per-line gutter (turnView.line's indent) is never painted by a background a tool opened and did not reset — the "gutter carries no background" invariant render.go's newline() keeps for the input, now kept for tool output too. A block-background demo (open once, print several lines, reset at the end) is the natural shape that would otherwise bleed.

It caps the output at maxVisible visible runes and maxLines lines, whichever comes first, and reports whether it cut so the caller can mark the elision (Decision 3). SGR bytes and newlines do not count toward maxVisible — it measures visible width, not the escapes that colour it nor the rows — so the line cap is what bounds height for short-line output (a diff, a test log). A cut never lands inside a sequence, because a sequence is copied whole or not at all. A cut also never ends in a newline: the marker the caller appends belongs directly under the last kept line, and the lines shown must equal the lines a budgeting caller is charged (ADR-0031). A non-positive cap disables that dimension. The result always ends reset when it opened any colour, so no unclosed style reaches the next line.

Types

This section is empty.

Jump to

Keyboard shortcuts

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