pub struct TokenRenderer<W: Write> { /* private fields */ }Expand description
Streaming markdown-aware terminal renderer for assistant output.
Port of agent_token_renderer: bold/italic/inline code, fenced code
blocks with keyword highlighting, grey thinking text, and UTF-8-safe
byte-at-a-time streaming.
Implementations§
Source§impl<W: Write> TokenRenderer<W>
impl<W: Write> TokenRenderer<W>
Sourcepub fn sink_mut(&mut self) -> &mut W
pub fn sink_mut(&mut self) -> &mut W
Borrows the sink, so a caller rendering into a buffer can harvest bytes without consuming the renderer.
Sourcepub fn new(sink: W, opts: RenderOptions) -> Self
pub fn new(sink: W, opts: RenderOptions) -> Self
Creates a renderer writing to sink with the given options.
Sourcepub fn set_capture(&mut self, capture: Option<TailCapture>)
pub fn set_capture(&mut self, capture: Option<TailCapture>)
Attaches a tail capture; output is recorded instead of written.
Sourcepub fn take_capture(&mut self) -> Option<TailCapture>
pub fn take_capture(&mut self) -> Option<TailCapture>
Detaches and returns the tail capture, if any.
Sourcepub fn wrote_visible_output(&self) -> bool
pub fn wrote_visible_output(&self) -> bool
Returns true if any visible byte has been emitted.
Sourcepub fn last_output_newline(&self) -> bool
pub fn last_output_newline(&self) -> bool
Returns true if the last emitted output byte was a newline.
Sourcepub fn set_in_think(&mut self, in_think: bool)
pub fn set_in_think(&mut self, in_think: bool)
Sets thinking mode: grey text, markdown disabled.
Sourcepub fn write_bytes(&mut self, bytes: &[u8])
pub fn write_bytes(&mut self, bytes: &[u8])
Streams raw bytes; UTF-8 sequences may be split across calls.
Sourcepub fn into_sink(self) -> W
pub fn into_sink(self) -> W
Consumes the renderer and returns the sink it was writing into.
The Turbo Vision front end renders into a Vec<u8> and harvests the
ANSI, rather than writing it to a terminal.
Sourcepub fn color(&mut self, seq: &str)
pub fn color(&mut self, seq: &str)
Emits a raw color escape, tracking whether a manual color is open.
Sourcepub fn plain(&mut self, s: &str)
pub fn plain(&mut self, s: &str)
Emits text verbatim, bypassing markdown but flushing pending state.
Sourcepub fn restore_text_attrs(&mut self)
pub fn restore_text_attrs(&mut self)
Re-applies tracked text attributes after external output.
Sourcepub fn code_stream_begin(&mut self, syntax: &'static Syntax)
pub fn code_stream_begin(&mut self, syntax: &'static Syntax)
Enters code-block streaming mode with an explicit syntax.
Sourcepub fn code_stream_set_prefix(
&mut self,
prefix: Option<&str>,
color: Option<&str>,
)
pub fn code_stream_set_prefix( &mut self, prefix: Option<&str>, color: Option<&str>, )
Sets a per-line prefix (and its color) restored on repaint.
Sourcepub fn code_stream_set_upto_marker(&mut self, enabled: bool)
pub fn code_stream_set_upto_marker(&mut self, enabled: bool)
Enables highlighting of the literal [upto] marker in code lines.
Sourcepub fn code_stream_end(&mut self)
pub fn code_stream_end(&mut self)
Ends code-block streaming mode, emitting any buffered line.