Skip to main content

PlainRenderer

Struct PlainRenderer 

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

Plain-text renderer for pipes, CI, dumb terminals, and TUI-incompatible terminals (e.g. JetBrains JediTerm — see lib.rs JediTerm fallback). No raw-mode dependencies, no DECSTBM, no cursor positioning.

Plain mode does support a few low-effort UX wins on top of bare printf, all gated by TerminalCaps:

  • Spinner via \r — overwrites the same line during streaming, so users see “in progress” feedback without animation tearing (cooked-mode \r always works; this is what read-with-progress scripts have used for decades).
  • SGR colours — red errors, green/red ✓/✗, cyan tool-call names when caps.colors is on. Pure inline SGR; no positioning required.
  • chevron — replaces > when caps.unicode_symbols is on, so the prompt visually matches the retained-mode chevron. Same two-cell width as > so layout math is unchanged.

Implementations§

Source§

impl PlainRenderer<BufWriter<Stdout>>

Source

pub fn new() -> Self

Convenience for the common “stdout + probe caps” path. Tests should use with_writer_and_caps so they can pin caps deterministically.

Source§

impl<W: Write + Send> PlainRenderer<W>

Source

pub fn with_writer(out: W) -> Self

Backwards-compat constructor used by older test paths. Probes caps from the environment — fine for production, but tests that want predictable behaviour should use with_writer_and_caps or the explicit with_writer_caps_and_interactive.

Source

pub fn with_writer_and_caps(out: W, caps: TerminalCaps) -> Self

Defaults interactive_terminal to caps.tty. Production callers in lib.rs use with_writer_caps_and_interactive instead because the force_plain branch needs to pass the PRE-mutation tty value (caps.tty has already been zeroed by then so the renderer would otherwise think it’s in pipe mode).

Source

pub fn with_writer_caps_and_interactive( out: W, caps: TerminalCaps, interactive_terminal: bool, ) -> Self

Explicit constructor that decouples caps.tty from the echo-handling decision. Used by lib.rs to pass the original tty value alongside a force_plain-mutated caps.

Trait Implementations§

Source§

impl Default for PlainRenderer<BufWriter<Stdout>>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<W: Write + Send> Renderer for PlainRenderer<W>

Source§

fn render(&mut self, line: UiLine)

Emit one UiLine. Implementations may batch internally; call flush() to force.
Source§

fn flush(&mut self)

Source§

fn shutdown(&mut self)

Shutdown: disable bracketed paste, disable raw mode, etc.
Source§

fn reset(&mut self)

Forget all cached rendering state (footer rows, last footer snapshot, assistant-text mid-line buffer, markdown parser) AND clear the physical terminal screen. Used by callers that hand control back to a non-TUI process (e.g. the blocking OAuth flow in /login) and then want a clean slate — without this, the next render tries to erase_footer at a position the terminal cursor is no longer at, corrupting every subsequent ANSI cursor move.
Source§

fn clear_screen(&mut self)

Wipe the physical terminal with \x1b[2J\x1b[H and flush. Does not touch cached footer/stream state — callers that want a full state wipe should call reset() instead. Use this when only the visible scrollback should be cleared (e.g. the /clear command after which the footer immediately redraws).
Source§

fn suspend_for_external(&mut self)

Hand the terminal off to a non-TUI child process (blocking OAuth flow, /shell, etc.): disable raw mode + bracketed paste, finish any pending writes. After this returns, the child is free to use the terminal in cooked mode; resume_from_external() must be called before any further render() calls.
Source§

fn resume_from_external(&mut self)

Take the terminal back after suspend_for_external(): re-enable raw mode + bracketed paste AND call reset() to wipe the cached state (the child wrote to stdout in cooked mode, so our cursor tracking is now lying).
Source§

fn flush_deferred(&mut self)

Paint any throttled payload that’s been sitting in the deferred queue past its throttle window. Called from the event loop on a ~50fps timer so the “trailing edge” of a burst of input renders actually lands — without this tick a lone stale payload would stay invisible until the next unrelated render arrived. Read more
Source§

fn pop_approval_prompt(&mut self)

Remove the most recent ApprovalPrompt body row, if the tail row is one. Called by the event loop after the user responds Y/A/N so the prompt stops sitting in the body above the footer. Default: no-op — implementations that stream body lines to stdout (plain/pipe mode) can’t retract them.
Source§

fn on_resize(&mut self, _cols: u16, _rows: u16)

Terminal window was resized to (cols, rows). DECSTBM-based renderers must re-issue the scroll region (\x1b[1;H-N r) so the fixed footer stays pinned to the new bottom. Non-DECSTBM renderers can treat this as a redraw hint or a no-op. Read more
Source§

fn scroll_body(&mut self, _delta: i32)

Scroll the body viewport up (negative delta) or down (positive delta) by delta rows. Used by AltScreenRenderer to support PageUp / PageDown / arrow-up scrollback navigation inside the alt-screen (where the host terminal’s native scrollback is unavailable). Read more
Source§

fn scroll_body_to_top(&mut self)

Jump the body viewport to the absolute top / bottom of scrollback. Used for Home / End key handling.
Source§

fn scroll_body_to_bottom(&mut self)

Source§

fn begin_selection(&mut self, _col: u16, _row: u16)

Mouse text-selection hooks. Backends that own mouse capture can override these; streaming/native-scrollback backends keep host terminal selection behavior and no-op here.
Source§

fn update_selection(&mut self, _col: u16, _row: u16)

Source§

fn end_selection(&mut self)

Source§

fn copy_selection(&mut self) -> bool

Copy the current mouse-selection text to the system clipboard (using arboard, not OSC 52) and clear the selection highlight. Returns true if a non-empty selection was copied. Read more
Source§

fn refresh_welcome_banner(&mut self, _model: &str, _working_dir: &str)

Update the cached welcome banner’s model / working_dir fields in place and trigger a repaint of the banner rows. Used after the QR-onboarding /codingplan claim finishes: the banner was painted at the top of scrollback with model="" (the claim hadn’t picked a default provider yet) — once the claim writes ctx.model_name, this hook splices the resolved model into the existing banner rows so the user doesn’t see a permanently blank model bullet. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<W> Send for PlainRenderer<W>

§

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

§

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

§

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

§

impl<W> UnwindSafe for PlainRenderer<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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more