streaming

package
v0.0.201 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package streaming provides a streaming markdown renderer for incremental terminal markdown output. It buffers markdown input and renders complete blocks as they become available, making it suitable for streaming sources like LLM outputs.

Index

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 a terminal markdown renderer and provides streaming capabilities. It buffers markdown input and renders complete blocks immediately to the output writer.

func NewRenderer

func NewRenderer(w io.Writer, renderer rendermarkdown.Renderer) (*StreamRenderer, error)

NewRenderer creates a new streaming markdown renderer.

func NewRendererWithOptions

func NewRendererWithOptions(
	w io.Writer,
	renderer rendermarkdown.Renderer,
	streamOpts []StreamRendererOption,
) (*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 resizing the markdown renderer with the new width and re-rendering all accumulated content. The caller should clear the screen before calling this method.

func (*StreamRenderer) Write

func (sr *StreamRenderer) Write(p []byte) (n int, err error)

Write accepts markdown chunks and renders complete blocks immediately. It implements io.Writer.

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.

Jump to

Keyboard shortcuts

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