Skip to main content

InlineViewport

Struct InlineViewport 

Source
pub struct InlineViewport<T: TermOut> { /* private fields */ }
Expand description

A custom inline viewport that lives at the bottom of the terminal screen.

Unlike ratatui’s built-in Viewport::Inline, this implementation handles resize correctly by re-deriving its anchor from a single cursor query and local knowledge of what it drew, avoiding terminal round-trips during normal operation entirely.

§Anchor tracking

All positioning is relative to the anchor: the DECSC saved cursor position, which sits at the end of the scrollback content, one row above the viewport (mid-line while a response is streaming). Reflowing terminals (kitty/alacritty/VTE) translate the live cursor through a resize reflow but merely clamp the saved cursor, so after a resize the anchor must be reconstructed from the live cursor:

  • when the cursor is hidden it is parked on the anchor, so the queried position is the anchor;
  • when the cursor is shown in the viewport, we compute how many rows the previously drawn viewport rows rewrap to at the new width (we know exactly what we drew) and subtract;
  • non-reflowing terminals (xterm-class) keep everything in place — they are detected by the queried position matching the old one, in which case the old anchor remains valid.

The anchor’s column (end of a partially streamed line) is tracked by parsing everything printed through InlineViewport::print_above, so it can be recomputed for any width without asking the terminal.

All terminal output and queries go through the owned TermOut, so the viewport can be driven against a virtual terminal in tests.

Implementations§

Source§

impl<T: TermOut> InlineViewport<T>

Source

pub fn new(term: T, height: u16) -> Result<Self>

Source

pub fn term_mut(&mut self) -> &mut T

Direct access to the underlying terminal, e.g. for cleanup sequences or setting the terminal title.

Source

pub fn area(&self) -> Rect

Source

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

Handle a terminal resize with NO terminal output or queries.

Marks the anchor stale; the next draw or print re-derives it with a single cursor-position query (see InlineViewport::re_anchor).

Source

pub fn print_above( &mut self, writer: impl FnOnce(&mut Vec<u8>) -> Result<()>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Source

pub fn print_line_above( &mut self, line: Line<'_>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Source

pub fn print_spans_above( &mut self, line: Line<'_>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Source

pub fn draw<F>(&mut self, desired_lines: u16, render_fn: F) -> Result<()>
where F: FnOnce(&mut ViewportFrame<'_>),

Draw the viewport using relative cursor movement from the saved cursor position (end of scrollback). Restores the saved cursor, then uses MoveToNextLine / MoveToColumn to reach each cell, avoiding any absolute coordinates.

Auto Trait Implementations§

§

impl<T> Freeze for InlineViewport<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for InlineViewport<T>
where T: RefUnwindSafe,

§

impl<T> Send for InlineViewport<T>
where T: Send,

§

impl<T> Sync for InlineViewport<T>
where T: Sync,

§

impl<T> Unpin for InlineViewport<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for InlineViewport<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for InlineViewport<T>
where T: 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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