Skip to main content

PtyBackend

Struct PtyBackend 

Source
pub struct PtyBackend { /* private fields */ }
Available on crate feature pty-test only.
Expand description

Drives the real crate::run flush pipeline into an in-process byte sink, so escape-code / color-depth / image-protocol output is asserted end-to-end — the byte/protocol tier that TestBackend’s buffer-only model deliberately cannot reach (see tests/visual_snapshots.rs).

Each render constructs a fresh fullscreen Terminal whose sink is a captured Vec<u8> (no real TTY, no raw mode), runs one frame through the same crate::frame_owned entry point the production loop uses, and captures the emitted bytes. Because the previous frame buffer starts empty, every frame emits a complete first-paint diff — fully deterministic and reproducible on a headless CI runner.

This type is gated behind the dev-only pty-test feature and is not present in a default build.

Since 0.21.0.

§Example

use slt::{Color, PtyBackend};

let mut pb = PtyBackend::new(10, 1);
pb.render(|ui| {
    ui.text("x").fg(Color::Red).bold();
});
// The real flush pipeline emitted an SGR sequence for the styled glyph.
pb.assert_emits("\u{1b}[");

Implementations§

Source§

impl PtyBackend

Source

pub fn new(width: u32, height: u32) -> Self

Create a PTY capture backend with the given terminal dimensions.

Defaults to ColorDepth::TrueColor; override with with_color_depth.

Source

pub fn with_color_depth(self, depth: ColorDepth) -> Self

Set the ColorDepth the flush pipeline encodes SGR colors with (e.g. truecolor vs 256-color). Returns self for chaining.

Source

pub fn render(&mut self, f: impl FnOnce(&mut Context)) -> &PtyFrame

Render one frame through the real Terminal flush pipeline, capturing the emitted bytes. Returns the just-captured PtyFrame.

Source

pub fn render_with_events( &mut self, events: Vec<Event>, f: impl FnOnce(&mut Context), ) -> &PtyFrame

Render one frame with injected input events, capturing the emitted bytes. Returns the just-captured PtyFrame.

Source

pub fn frames_raw(&self) -> impl Iterator<Item = &[u8]>

Iterate the raw byte stream of every captured frame, oldest first.

Source

pub fn last_raw(&self) -> &[u8]

Raw bytes of the most recently rendered frame.

Panics if no frame has been rendered yet.

Source

pub fn assert_emits(&self, needle: &str)

Assert the last frame’s byte stream contains needle.

Panics with an escaped + hex dump of the emitted bytes on a miss.

Source

pub fn assert_not_emits(&self, needle: &str)

Assert the last frame’s byte stream does not contain needle.

Panics with an escaped + hex dump on an unexpected hit.

Auto Trait Implementations§

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.