Documentation
¶
Index ¶
- func GlamourStyle() gansi.StyleConfig
- func LooksLikeJSON(line string) bool
- func ParseFence(line string) (byte, int, bool)
- func PrintMarkdownOrPlain(w io.Writer, text string)
- func RenderLog(r io.Reader, w io.Writer, isTTY bool) error
- func RenderLogWith(r io.Reader, fmtr *Formatter, plainW io.Writer) error
- func RenderMarkdownLines(text string, wrapWidth, maxWidth int, glamourStyle gansi.StyleConfig, ...) []string
- func ResolveColorProfile() termenv.Profile
- func SanitizeControlKeepNewlines(s string) string
- func SanitizeEscapes(line string) string
- func SanitizeLines(lines []string) []string
- func StripANSI(s string) string
- func StripTrailingPadding(line string, noColor bool) string
- func TerminalWidth(w io.Writer) int
- func TruncateLongLines(text string, maxWidth int, tabWidth int) string
- func WrapText(text string, width int) []string
- func WriterIsTerminal(w io.Writer) bool
- type Formatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GlamourStyle ¶
func GlamourStyle() gansi.StyleConfig
GlamourStyle returns a glamour style config with zero margins, matching the TUI's rendering. Detects dark/light background once. Respects ROBOREV_COLOR_MODE env var and NO_COLOR convention.
func LooksLikeJSON ¶
LooksLikeJSON returns true if line is a JSON object with a non-empty "type" field, matching the stream event format used by Claude Code, Codex, and Gemini CLI.
func ParseFence ¶
ParseFence checks if line is a CommonMark fenced code block delimiter. Returns the fence character ('`' or '~'), the run length, and whether trailing content is whitespace-only (required for closing fences). Returns (0, 0, false) if not a valid fence.
func PrintMarkdownOrPlain ¶
PrintMarkdownOrPlain renders text as glamour-styled markdown when writing to a TTY, or prints it as-is otherwise.
func RenderLog ¶
RenderLog reads a job log file and writes human-friendly output. JSONL lines are processed through Formatter for compact tool/text rendering. Non-JSON lines are printed as-is.
func RenderLogWith ¶
RenderLogWith renders a job log using a pre-configured Formatter. plainW receives non-JSON lines directly.
func RenderMarkdownLines ¶
func RenderMarkdownLines( text string, wrapWidth, maxWidth int, glamourStyle gansi.StyleConfig, tabWidth int, colorProfile termenv.Profile, ) []string
RenderMarkdownLines renders markdown text using glamour and splits into lines. wrapWidth controls glamour's word-wrap column. maxWidth controls line truncation (actual terminal width). colorProfile controls glamour's color output (use termenv.Ascii to suppress colors). Falls back to WrapText if glamour rendering fails.
func ResolveColorProfile ¶ added in v0.49.0
ResolveColorProfile returns the termenv color profile based on the ROBOREV_COLOR_MODE env var and the NO_COLOR convention. Returns termenv.Ascii when colors should be suppressed.
func SanitizeControlKeepNewlines ¶
SanitizeControlKeepNewlines strips ANSI escape sequences and non-printable control characters but preserves newlines. Used for agent text content that needs to retain paragraph structure.
func SanitizeEscapes ¶
SanitizeEscapes strips non-SGR terminal escape sequences and dangerous C0 control characters from a line, preventing untrusted content from injecting OSC/CSI/DCS control codes or spoofing output via \r/\b overwrites. SGR sequences (colors/styles), tabs, and newlines are preserved.
func SanitizeLines ¶
SanitizeLines applies SanitizeEscapes to every line in the slice.
func StripTrailingPadding ¶
StripTrailingPadding removes trailing whitespace and ANSI SGR codes from a glamour output line, then appends a reset to ensure clean color state. When noColor is true, all SGR sequences are stripped to prevent open attributes (bold, underline) from bleeding across lines.
func TerminalWidth ¶
TerminalWidth returns the terminal width for the given writer, defaulting to 100 if detection fails.
func TruncateLongLines ¶
TruncateLongLines normalizes tabs and truncates lines inside fenced code blocks that exceed maxWidth, so glamour won't word-wrap them. Prose lines outside code blocks are left intact for glamour to word-wrap naturally.
func WrapText ¶
WrapText wraps text to the specified width, preserving existing line breaks and breaking at word boundaries when possible. Uses runewidth for correct display width with Unicode and wide characters.
func WriterIsTerminal ¶
WriterIsTerminal checks if a writer is backed by a terminal.
Types ¶
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter wraps an io.Writer to transform raw NDJSON stream output from Claude into compact, human-readable progress lines.
In TTY mode, tool calls are shown as one-line summaries:
Read internal/gmail/ratelimit_test.go Edit internal/gmail/ratelimit_test.go Bash go test ./internal/gmail/ -run TestRateLimiter
In non-TTY mode (piped output), raw JSON is passed through unchanged.
func New ¶
New creates a Formatter that writes to w. When isTTY is true, NDJSON lines are rendered as compact progress lines; otherwise raw JSON is passed through unchanged.
func NewWithWidth ¶
NewWithWidth creates a Formatter with an explicit width and pre-computed glamour style. Used when rendering into a buffer (e.g. the TUI log view) where terminal queries aren't possible.
func (*Formatter) SetWriter ¶
SetWriter replaces the underlying writer. Used to redirect a persistent formatter's output to a fresh buffer for incremental rendering.