Documentation
¶
Overview ¶
Package termrender replays captured terminal output and writes the resulting text, line by line, to an output writer.
It exists to render the stdout/stderr a CI step produced into the text a human would have seen. A naive ANSI strip is not enough: tools like Docker redraw progress with carriage returns and cursor movement, so stripping the escapes alone leaves a pile of stale, half-drawn lines. Replaying the stream through a terminal model collapses those redraws to their final state.
Two rendering modes are offered:
- Render writes plain text — SGR styling is discarded. Use it when piping to a file or another program (grep/awk/less), where escape codes are noise.
- RenderStyled preserves SGR styling (colors, bold, underline, …): each rendered cell keeps the graphic rendition active when it was drawn, with redraws still collapsed. Use it for a human-facing viewer such as the interactive output pager.
Unlike a general terminal emulator it is built for the one job of rendering a (potentially enormous) append-only log:
- Lines are never wrapped. Each row holds a full logical line of unbounded width, so long log lines survive intact for grep/awk and friends. A fixed-width grid would either wrap (inserting fake breaks) or truncate them.
- Lines are streamed out as they scroll off the top of a fixed-height window, so memory stays flat (O(window)) and nothing is ever silently dropped, however large the log.
- There is no input/reply channel: device-status and color queries in the stream are simply ignored. The renderer never blocks waiting to answer them.
Cursor addressing is tracked in columns of one cell per rune; wide-rune (CJK) alignment inside an in-place redraw is therefore approximate, which is immaterial for the ASCII and box-drawing output that progress redraws use in practice.
Index ¶
Constants ¶
const DefaultHeight = 100
DefaultHeight is the height, in rows, of the window the renderer keeps live for in-place redraws. Cursor movement (e.g. a Docker pull repainting its per-layer progress lines) is collapsed within this window; once a line scrolls above it the line is final and is written out. It only needs to be as tall as the largest block a tool repaints at once.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render replays the captured terminal output read from src and writes the rendered plain text (styling discarded) to dst. Input is consumed one byte at a time and output is streamed as lines scroll off, so memory stays flat regardless of how large the source is. See the package documentation.
Whatever was rendered before a read error is still flushed to dst; the read error is then returned.
func RenderStyled ¶
RenderStyled is like Render but preserves SGR styling: each rendered cell keeps the graphic rendition (colors, bold, …) active when it was drawn, with redraws still collapsed to their final state. Use it for a human-facing viewer where colors matter; use Render for plain-text pipe/file output.
Types ¶
This section is empty.