pub struct PtyBackend { /* private fields */ }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
impl PtyBackend
Sourcepub fn new(width: u32, height: u32) -> Self
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.
Sourcepub fn with_color_depth(self, depth: ColorDepth) -> Self
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.
Sourcepub fn render(&mut self, f: impl FnOnce(&mut Context)) -> &PtyFrame
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.
Sourcepub fn render_with_events(
&mut self,
events: Vec<Event>,
f: impl FnOnce(&mut Context),
) -> &PtyFrame
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.
Sourcepub fn frames_raw(&self) -> impl Iterator<Item = &[u8]>
pub fn frames_raw(&self) -> impl Iterator<Item = &[u8]>
Iterate the raw byte stream of every captured frame, oldest first.
Sourcepub fn last_raw(&self) -> &[u8] ⓘ
pub fn last_raw(&self) -> &[u8] ⓘ
Raw bytes of the most recently rendered frame.
Panics if no frame has been rendered yet.
Sourcepub fn assert_emits(&self, needle: &str)
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.
Sourcepub fn assert_not_emits(&self, needle: &str)
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.