Documentation
¶
Overview ¶
Package streaming provides a streaming markdown renderer that wraps glamour's TermRenderer. It buffers markdown input and renders complete blocks as they become available, making it suitable for rendering markdown from streaming sources like LLM outputs.
Index ¶
- type StreamRenderer
- func (sr *StreamRenderer) Close() error
- func (sr *StreamRenderer) CommittedMarkdownLen() int
- func (sr *StreamRenderer) Flush() error
- func (sr *StreamRenderer) PendingIsList() bool
- func (sr *StreamRenderer) PendingIsTable() bool
- func (sr *StreamRenderer) PendingMarkdown() string
- func (sr *StreamRenderer) Resize(newWidth int) error
- func (sr *StreamRenderer) Write(p []byte) (n int, err error)
- type StreamRendererOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StreamRenderer ¶
type StreamRenderer struct {
// contains filtered or unexported fields
}
StreamRenderer wraps glamour's TermRenderer and provides streaming capabilities. It buffers markdown input and renders complete blocks immediately to the output writer.
func NewRenderer ¶
func NewRenderer(w io.Writer, opts ...glamour.TermRendererOption) (*StreamRenderer, error)
NewRenderer creates a new streaming markdown renderer. Options are passed directly to glamour.NewTermRenderer.
func NewRendererWithOptions ¶
func NewRendererWithOptions( w io.Writer, streamOpts []StreamRendererOption, glamourOpts ...glamour.TermRendererOption, ) (*StreamRenderer, error)
NewRendererWithOptions creates a new streaming markdown renderer with additional streaming-specific options like partial rendering.
func (*StreamRenderer) Close ¶
func (sr *StreamRenderer) Close() error
Close flushes any remaining content and cleans up.
func (*StreamRenderer) CommittedMarkdownLen ¶ added in v0.0.55
func (sr *StreamRenderer) CommittedMarkdownLen() int
CommittedMarkdownLen returns the number of raw markdown bytes that have been committed as complete blocks. This excludes any pending/incomplete block content.
func (*StreamRenderer) Flush ¶
func (sr *StreamRenderer) Flush() error
Flush renders any buffered content, treating incomplete blocks as complete.
func (*StreamRenderer) PendingIsList ¶ added in v0.0.75
func (sr *StreamRenderer) PendingIsList() bool
PendingIsList reports whether the current incomplete block should be treated as a list for preview purposes.
func (*StreamRenderer) PendingIsTable ¶ added in v0.0.60
func (sr *StreamRenderer) PendingIsTable() bool
PendingIsTable reports whether the current incomplete block should be treated as a table for preview purposes.
func (*StreamRenderer) PendingMarkdown ¶ added in v0.0.60
func (sr *StreamRenderer) PendingMarkdown() string
PendingMarkdown returns the current incomplete block markdown. This includes pending complete lines plus any partial line in the buffer.
func (*StreamRenderer) Resize ¶
func (sr *StreamRenderer) Resize(newWidth int) error
Resize handles terminal resize events by re-creating the glamour renderer with the new width and re-rendering all accumulated content. The caller should clear the screen before calling this method.
type StreamRendererOption ¶
type StreamRendererOption func(*StreamRenderer)
StreamRendererOption configures a StreamRenderer.
func WithPartialRendering ¶
func WithPartialRendering() StreamRendererOption
WithPartialRendering enables partial block rendering with re-rendering. When enabled, safe text within incomplete blocks will be shown immediately, and the output will be re-rendered when syntax completes.
func WithTerminalWidth ¶
func WithTerminalWidth(width int) StreamRendererOption
WithTerminalWidth sets the terminal width for accurate line counting during partial rendering. This is used to calculate how many lines the rendered output occupies for cursor repositioning.