Skip to main content

Presenter

Struct Presenter 

Source
pub struct Presenter<W: Write> { /* private fields */ }
Expand description

State-tracked ANSI presenter.

Transforms buffer diffs into minimal terminal output by tracking the current terminal state and only emitting necessary escape sequences.

Implementations§

Source§

impl<W: Write> Presenter<W>

Source

pub fn new(writer: W, capabilities: TerminalCapabilities) -> Self

Create a new presenter with the given writer and capabilities.

Source

pub fn writer_mut(&mut self) -> &mut W

Get mutable access to the innermost writer (W).

This allows the caller to write raw data (e.g. logs) bypassing the presenter’s state tracking. Note that this may invalidate cursor tracking if the raw writes move the cursor.

Source

pub fn counting_writer_mut(&mut self) -> &mut CountingWriter<BufWriter<W>>

Get mutable access to the full counting writer stack.

This exposes CountingWriter<BufWriter<W>> so callers can access byte counting, buffered flush, etc.

Source

pub fn set_viewport_offset_y(&mut self, offset: u16)

Set the viewport Y offset.

All subsequent render operations will add this offset to row coordinates. Useful for inline mode where the UI starts at a specific row.

Source

pub fn capabilities(&self) -> &TerminalCapabilities

Get the terminal capabilities.

Source

pub fn present( &mut self, buffer: &Buffer, diff: &BufferDiff, ) -> Result<PresentStats>

Present a frame using the given buffer and diff.

This is the main entry point for rendering. It:

  1. Begins synchronized output (if supported)
  2. Emits changes based on the diff
  3. Resets style and closes links
  4. Ends synchronized output
  5. Flushes all buffered output
Source

pub fn present_with_pool( &mut self, buffer: &Buffer, diff: &BufferDiff, pool: Option<&GraphemePool>, links: Option<&LinkRegistry>, ) -> Result<PresentStats>

Present a frame with grapheme pool and link registry.

Source

pub fn emit_diff_runs( &mut self, buffer: &Buffer, pool: Option<&GraphemePool>, links: Option<&LinkRegistry>, ) -> Result<()>

Emit diff runs using the cost model and internal buffers.

This allows advanced callers (like TerminalWriter) to drive the emission phase manually while still benefiting from the optimization logic. The caller must populate self.runs_buf before calling this (e.g. via diff.runs_into).

Source

pub fn prepare_runs(&mut self, diff: &BufferDiff)

Prepare the runs buffer from a diff.

Helper for external callers to populate the runs buffer before calling emit_diff_runs.

Source

pub fn clear_screen(&mut self) -> Result<()>

Clear the entire screen.

Source

pub fn clear_line(&mut self, y: u16) -> Result<()>

Clear a single line.

Source

pub fn hide_cursor(&mut self) -> Result<()>

Hide the cursor.

Source

pub fn show_cursor(&mut self) -> Result<()>

Show the cursor.

Source

pub fn position_cursor(&mut self, x: u16, y: u16) -> Result<()>

Position the cursor at the specified coordinates.

Source

pub fn reset(&mut self)

Reset the presenter state.

Useful after resize or when terminal state is unknown.

Source

pub fn flush(&mut self) -> Result<()>

Flush any buffered output.

Source

pub fn into_inner(self) -> Result<W, Error>

Get the inner writer (consuming the presenter).

Flushes any buffered data before returning the writer.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for Presenter<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 = Infallible

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.