A lightweight streaming adapter for glamour. Feed it markdown tokens as they arrive from an LLM — raw text appears immediately, then gets replaced with glamour-rendered output when each block completes.
go get github.com/jack-work/largo
r, _ := glamour.NewTermRenderer(glamour.WithAutoStyle(), glamour.WithWordWrap(80))
w := largo.New(os.Stdout, r, largo.Options{Width: 80})
for token := range llmResponseChannel {
w.Write([]byte(token))
}
w.Flush()It implements io.Writer, so it plugs in anywhere:
io.Copy(w, resp.Body)
w.Flush()Stream a markdown file with random chunking to see it in action:
go run ./cmd/largo-demo testdata/sample.md
go run ./cmd/largo-demo -delay 30ms -min 1 -max 20 testdata/sample.md
- Echo raw — every
Write()call immediately prints raw bytes so the user sees text appearing in real time. - Track rows — counts terminal rows consumed (including soft wraps at the configured width).
- Detect boundary — when
\n\nor a closed fenced code block is found, the raw rows are erased using ANSI escape codes. - Render and replace — the completed block is rendered through glamour and written in place.
- Flush — call at stream end to render whatever is left.
MIT