Skip to main content

TokenRenderer

Struct TokenRenderer 

Source
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>

Source

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.

Source

pub fn new(sink: W, opts: RenderOptions) -> Self

Creates a renderer writing to sink with the given options.

Source

pub fn set_capture(&mut self, capture: Option<TailCapture>)

Attaches a tail capture; output is recorded instead of written.

Source

pub fn take_capture(&mut self) -> Option<TailCapture>

Detaches and returns the tail capture, if any.

Source

pub fn wrote_visible_output(&self) -> bool

Returns true if any visible byte has been emitted.

Source

pub fn last_output_newline(&self) -> bool

Returns true if the last emitted output byte was a newline.

Source

pub fn set_in_think(&mut self, in_think: bool)

Sets thinking mode: grey text, markdown disabled.

Source

pub fn write(&mut self, text: &str)

Streams a chunk of assistant text through the renderer.

Source

pub fn write_bytes(&mut self, bytes: &[u8])

Streams raw bytes; UTF-8 sequences may be split across calls.

Source

pub fn finish(&mut self)

Flushes pending state and emits the trailing blank line.

Source

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.

Source

pub fn color(&mut self, seq: &str)

Emits a raw color escape, tracking whether a manual color is open.

Source

pub fn plain(&mut self, s: &str)

Emits text verbatim, bypassing markdown but flushing pending state.

Source

pub fn restore_text_attrs(&mut self)

Re-applies tracked text attributes after external output.

Source

pub fn code_stream_begin(&mut self, syntax: &'static Syntax)

Enters code-block streaming mode with an explicit syntax.

Source

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.

Source

pub fn code_stream_set_upto_marker(&mut self, enabled: bool)

Enables highlighting of the literal [upto] marker in code lines.

Source

pub fn code_stream_end(&mut self)

Ends code-block streaming mode, emitting any buffered line.

Trait Implementations§

Source§

impl<W: Write> Debug for TokenRenderer<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for TokenRenderer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for TokenRenderer<W>
where W: RefUnwindSafe,

§

impl<W> Send for TokenRenderer<W>
where W: Send,

§

impl<W> Sync for TokenRenderer<W>
where W: Sync,

§

impl<W> Unpin for TokenRenderer<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for TokenRenderer<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for TokenRenderer<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.