mdstream

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package mdstream partitions streamed markdown into a stable prefix and a mutable tail. Streaming text into a terminal renderer has a conflict: text committed to scrollback is rendered once and never touched again, but markdown cannot be rendered correctly until its enclosing block is complete (a table cannot be laid out from half its rows; an unclosed fence's end is unknown). The splitter resolves it by advancing a commit boundary only at provably safe points, so the renderer commits the stable prefix exactly once and re-renders only the small mutable tail each frame.

Safe boundaries are structural, not heuristic: the end of a line that closes a code fence, or a blank line outside any fence. Everything after the last safe boundary is tail. This yields the holdback behavior the session needs for free: a streaming table has no blank line inside it, so it stays in the tail (re-rendered whole each frame, laid out correctly once complete), and everything inside an open fence stays in the tail until the fence closes.

The splitter never inspects render output and allocates nothing per write beyond the buffer append: it is a cursor over bytes, cheap enough to run on every streamed chunk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Splitter

type Splitter struct {
	// contains filtered or unexported fields
}

Splitter accumulates streamed markdown and tracks the commit boundary. The zero value is ready to use.

func (*Splitter) Close

func (s *Splitter) Close() string

Close marks the stream complete and returns any remaining uncommitted text: at end of stream every block is as complete as it will ever be, so the whole tail becomes stable.

func (*Splitter) Stable

func (s *Splitter) Stable() string

Stable returns the newly committed text since the last call: the part of the stream that is now provably safe to render and print exactly once.

func (*Splitter) Tail

func (s *Splitter) Tail() string

Tail returns the mutable remainder after the commit boundary: the text a live region re-renders each frame.

func (*Splitter) Write

func (s *Splitter) Write(chunk string)

Write appends the next streamed chunk and advances the boundary scan.

Jump to

Keyboard shortcuts

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