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>
impl<W: CommandWriter> Screen<W>
Sourcepub fn new(writer: W, size: TerminalSize) -> Result<Self>
pub fn new(writer: W, size: TerminalSize) -> Result<Self>
Creates a screen for a terminal surface of size.
Sourcepub const fn size(&self) -> TerminalSize
pub const fn size(&self) -> TerminalSize
Returns the current frame size.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Consumes the screen and returns its command writer.
Sourcepub fn resize(&mut self, size: TerminalSize) -> Result<()>
pub fn resize(&mut self, size: TerminalSize) -> Result<()>
Replaces both frame buffers and invalidates the physical baseline.
Sourcepub fn invalidate(&mut self)
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.
Sourcepub fn modify_surface(
&mut self,
output: impl FnOnce(&mut W) -> Result<()>,
) -> Result<()>
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.
Sourcepub fn draw(&mut self, draw: impl FnOnce(&mut Frame<'_>)) -> Result<()>
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.
Sourcepub fn draw_with(
&mut self,
draw: impl FnOnce(&mut Frame<'_>),
present: impl FnOnce(&mut W) -> Result<()>,
) -> Result<()>
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.