Documentation
¶
Overview ¶
Package bubbleteandmd renders streaming LLM Markdown in a terminal, for bubbletea programs. Finished blocks are rendered once and cached; only the open tail is rendered again as tokens arrive, and that tail is healed (an open fence, `**`, a half-typed link) so raw syntax does not show mid-stream. It reads llx-markdown's directive syntax (`> [!STEPS]`, `> [!TABS]`, ```tree fences …). See README.md.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTrimmed = errors.New("bubbleteandmd: Renderer output ends a paragraph without a newline; pass a raw *glamour.TermRenderer")
ErrTrimmed is returned by Frame and Final when the Renderer ends a paragraph without its newline (a wrapper that trims glamour's output): the blocks cannot be joined as the whole document renders.
Functions ¶
func Sanitize ¶ added in v0.2.0
Sanitize removes from src what a terminal reads as a command, not text, so model output cannot write the clipboard (OSC 52), set the title, move the cursor, clear the screen or overwrite a line. glamour v2.0.1 passes these through unchanged, in prose, tables and code.
Removed:
- C0 controls (U+0000–U+001F) except tab and newline; "\r\n" becomes "\n" and any other "\r" goes too. ESC goes, so the text of an escape sequence after it stays as plain characters.
- DEL (U+007F) and C1 controls (U+0080–U+009F), among them CSI U+009B.
- bytes that are not UTF-8 (a raw 0x9B byte is one).
- an incomplete UTF-8 sequence at the end of src: it can complete in the next chunk, so it is held back, not shown as an error.
- Unicode bidi embeddings, overrides and isolates (U+202A–U+202E, U+2066–U+2069): they reorder the text shown, so a line can read differently from its bytes (spoofing).
Everything else stays, ZWJ and emoji included.
Sanitize is prefix-stable: for any cut k, Sanitize(s[:k]) is a prefix of Sanitize(s), so a stream that grows keeps its rendered blocks. It is idempotent. Stream.Frame and Stream.Final call it; a caller that renders model text some other way must call it first.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds rendered stable blocks, keyed by (Stream key, block source). One Cache can serve many Streams; it is safe for concurrent use.
type DirectiveRenderer ¶ added in v0.2.0
type DirectiveRenderer struct {
// contains filtered or unexported fields
}
DirectiveRenderer renders Markdown as glamour does, and draws llx-markdown's directive forms (callouts, steps, tabs, stats, pros and cons, details, sources, quotes with a source, file trees, titled code fences) and `$$` formulas. It satisfies Renderer, so NewStream can stream it. A document with no form and no `$$` formula renders exactly as glamour renders it.
A DirectiveRenderer is used by one goroutine at a time.
func NewRenderer ¶ added in v0.2.0
func NewRenderer(style ansi.StyleConfig, width int, opts ...glamour.TermRendererOption) (*DirectiveRenderer, error)
NewRenderer returns a renderer for style at word wrap width. opts go to glamour after the style and the word wrap; they must not change either.
type Renderer ¶
Renderer renders one whole Markdown document. *glamour.TermRenderer satisfies it. A Renderer is used by one goroutine at a time.
Pass a raw *glamour.TermRenderer (or a DirectiveRenderer), not a wrapper that changes its output: Stream renders each block alone and joins the pieces by the document prefix, suffix and line ends glamour writes. A wrapper that trims the newlines makes Frame and Final return ErrTrimmed. Do pre-processing on src before Frame; do post-processing on the output of Frame and Final.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream renders one document that grows at its end. Blocks before the last two are rendered once and cached; the last two (the tail) are rendered on every call. Both first remove terminal controls (Sanitize). Frame heals the tail; Final does not. The result equals r.Render of the whole sanitized (and healed, for Frame) text.
A Stream is not safe for concurrent use.
func NewStream ¶
NewStream returns a Stream that renders with r and caches stable blocks in c under key. key must name everything that changes r's output (dun: width and style). c may be shared by Streams; nil means no cache.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
blocks
Package blocks cuts a Markdown document into top-level blocks that can be rendered, and cached, one by one.
|
Package blocks cuts a Markdown document into top-level blocks that can be rendered, and cached, one by one. |
|
corpus
Package corpus holds the streaming test corpora, the seeded reply generator and the chunking helpers ported from llx-markdown, for invariant tests.
|
Package corpus holds the streaming test corpora, the seeded reply generator and the chunking helpers ported from llx-markdown, for invariant tests. |
|
directive
Package directive reads llx-markdown's directive forms out of one top-level block: callouts, steps, tabs, stats, pros and cons, folded sections, sources, quotes with a source, file trees and titled code fences.
|
Package directive reads llx-markdown's directive forms out of one top-level block: callouts, steps, tabs, stats, pros and cons, folded sections, sources, quotes with a source, file trees and titled code fences. |
|
heal
Package heal stabilizes the tail of a markdown text that is still streaming.
|
Package heal stabilizes the tail of a markdown text that is still streaming. |
|
join
Package join puts separately rendered glamour blocks together so that the result equals glamour's render of the whole document.
|
Package join puts separately rendered glamour blocks together so that the result equals glamour's render of the whole document. |
|
lru
Package lru is a small bounded least-recently-used cache.
|
Package lru is a small bounded least-recently-used cache. |
|
Package prompt holds the instructions that teach a model to write the directive forms the renderer draws.
|
Package prompt holds the instructions that teach a model to write the directive forms the renderer draws. |