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>
impl<W: Write> Presenter<W>
Sourcepub fn new(writer: W, capabilities: TerminalCapabilities) -> Self
pub fn new(writer: W, capabilities: TerminalCapabilities) -> Self
Create a new presenter with the given writer and capabilities.
Sourcepub fn writer_mut(&mut self) -> &mut W
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.
Sourcepub fn counting_writer_mut(&mut self) -> &mut CountingWriter<BufWriter<W>> ⓘ
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.
Sourcepub fn set_viewport_offset_y(&mut self, offset: u16)
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.
Sourcepub fn capabilities(&self) -> &TerminalCapabilities
pub fn capabilities(&self) -> &TerminalCapabilities
Get the terminal capabilities.
Sourcepub fn present(
&mut self,
buffer: &Buffer,
diff: &BufferDiff,
) -> Result<PresentStats>
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:
- Begins synchronized output (if supported)
- Emits changes based on the diff
- Resets style and closes links
- Ends synchronized output
- Flushes all buffered output
Sourcepub fn present_with_pool(
&mut self,
buffer: &Buffer,
diff: &BufferDiff,
pool: Option<&GraphemePool>,
links: Option<&LinkRegistry>,
) -> Result<PresentStats>
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.
Sourcepub fn emit_diff_runs(
&mut self,
buffer: &Buffer,
pool: Option<&GraphemePool>,
links: Option<&LinkRegistry>,
) -> Result<()>
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).
Sourcepub fn prepare_runs(&mut self, diff: &BufferDiff)
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.
Sourcepub fn clear_screen(&mut self) -> Result<()>
pub fn clear_screen(&mut self) -> Result<()>
Clear the entire screen.
Sourcepub fn clear_line(&mut self, y: u16) -> Result<()>
pub fn clear_line(&mut self, y: u16) -> Result<()>
Clear a single line.
Sourcepub fn hide_cursor(&mut self) -> Result<()>
pub fn hide_cursor(&mut self) -> Result<()>
Hide the cursor.
Sourcepub fn show_cursor(&mut self) -> Result<()>
pub fn show_cursor(&mut self) -> Result<()>
Show the cursor.
Sourcepub fn position_cursor(&mut self, x: u16, y: u16) -> Result<()>
pub fn position_cursor(&mut self, x: u16, y: u16) -> Result<()>
Position the cursor at the specified coordinates.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the presenter state.
Useful after resize or when terminal state is unknown.
Sourcepub fn into_inner(self) -> Result<W, Error>
pub fn into_inner(self) -> Result<W, Error>
Get the inner writer (consuming the presenter).
Flushes any buffered data before returning the writer.