Skip to main content

Screen

Struct Screen 

Source
pub struct Screen<W> { /* private fields */ }
Expand description

A synchronous full-screen presentation engine.

Screen owns the working and committed cell buffers, but it does not own a terminal session or any input path. A caller may use it directly in its own loop with any CommandWriter, independently of the optional Urushi TEA runtime and Tokio.

A draw is transactional with respect to the committed baseline: changed cells, the cursor request, and the writer flush must all succeed before the working frame becomes committed. If output fails after an arbitrary prefix, the next draw clears the physical surface and reconstructs it from a blank baseline.

Implementations§

Source§

impl<W: CommandWriter> Screen<W>

Source

pub fn new(writer: W, size: TerminalSize) -> Result<Self>

Creates a screen for a terminal surface of size.

Source

pub const fn size(&self) -> TerminalSize

Returns the current frame size.

Source

pub const fn writer(&self) -> &W

Returns the command writer used for physical output.

Source

pub fn into_inner(self) -> W

Consumes the screen and returns its command writer.

Source

pub fn resize(&mut self, size: TerminalSize) -> Result<()>

Replaces both frame buffers and invalidates the physical baseline.

Source

pub fn invalidate(&mut self)

Invalidates the physical cell baseline without changing frame size.

The next draw clears the surface and emits the complete working frame. Hosts use this when another presentation layer, such as immediate-mode terminal graphics, can leave pixels that a cell diff cannot remove.

Source

pub fn modify_surface( &mut self, output: impl FnOnce(&mut W) -> Result<()>, ) -> Result<()>

Runs direct physical output and invalidates the cell baseline.

This is for output such as presentation-layer cleanup that can change what is physically visible independently of the committed cell buffer. The next draw clears the surface and reconstructs every cell, whether output succeeds or fails.

Source

pub fn draw(&mut self, draw: impl FnOnce(&mut Frame<'_>)) -> Result<()>

Builds and presents one frame synchronously.

The closure may only change the working cells and cursor request through its borrowed Frame. Presentation history and commit remain owned by the screen.

Source

pub fn draw_with( &mut self, draw: impl FnOnce(&mut Frame<'_>), present: impl FnOnce(&mut W) -> Result<()>, ) -> Result<()>

Builds one cell frame and presents additional terminal output before commit.

present runs after changed cells and the cursor request have been written, but before the final flush and cell-baseline commit. If either closure, output, or flushing fails, the next draw reconstructs the full cell frame from a cleared physical surface. present must not clear or otherwise replace the cell layer; use Screen::modify_surface for direct output that does.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for Screen<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.