TestBackend

Struct TestBackend 

Source
pub struct TestBackend { /* private fields */ }
Expand description

A test backend for unit testing and snapshot testing.

Records operations and maintains a virtual terminal buffer.

§Example

use tuxtui_core::backend::{Backend, TestBackend};
use tuxtui_core::geometry::Rect;

let mut backend = TestBackend::new(80, 24);
backend.clear().unwrap();
let size = backend.size().unwrap();
assert_eq!(size.width, 80);
assert_eq!(size.height, 24);

Implementations§

Source§

impl TestBackend

Source

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

Create a new test backend with the given dimensions.

Source

pub fn buffer(&self) -> &Buffer

Get the current buffer content.

Source

pub fn buffer_mut(&mut self) -> &mut Buffer

Get a mutable reference to the buffer.

Source

pub fn resize(&mut self, width: u16, height: u16)

Resize the test backend.

Source

pub const fn is_cursor_visible(&self) -> bool

Get the cursor visibility state.

Source

pub fn assert_buffer_equals(&self, expected: &str)

Assert that the buffer contains the expected string at the given position.

§Panics

Panics if the buffer content doesn’t match.

Trait Implementations§

Source§

impl Backend for TestBackend

Source§

type Error = TestBackendError

The error type for this backend.
Source§

fn size(&self) -> Result<Rect, Self::Error>

Get the size of the terminal in columns and rows.
Source§

fn clear(&mut self) -> Result<(), Self::Error>

Clear the entire screen.
Source§

fn clear_region(&mut self, region: Rect) -> Result<(), Self::Error>

Clear a specific region.
Source§

fn hide_cursor(&mut self) -> Result<(), Self::Error>

Hide the cursor.
Source§

fn show_cursor(&mut self) -> Result<(), Self::Error>

Show the cursor.
Source§

fn get_cursor(&mut self) -> Result<Position, Self::Error>

Get the current cursor position.
Source§

fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), Self::Error>

Set the cursor position.
Source§

fn draw_cell(&mut self, x: u16, y: u16, cell: &Cell) -> Result<(), Self::Error>

Draw a single cell at the given position.
Source§

fn set_style(&mut self, _style: Style) -> Result<(), Self::Error>

Set the current style for subsequent operations.
Source§

fn reset_style(&mut self) -> Result<(), Self::Error>

Reset all styling to default.
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush any buffered output to the terminal.
Source§

fn enable_raw_mode(&mut self) -> Result<(), Self::Error>

Enable raw mode.
Source§

fn disable_raw_mode(&mut self) -> Result<(), Self::Error>

Disable raw mode.
Source§

fn enter_alternate_screen(&mut self) -> Result<(), Self::Error>

Enter alternate screen.
Source§

fn leave_alternate_screen(&mut self) -> Result<(), Self::Error>

Leave alternate screen.
Source§

fn set_scroll_region( &mut self, top: u16, bottom: u16, ) -> Result<(), Self::Error>

Available on crate feature scrolling-regions only.
Enable mouse capture (if supported).
Source§

fn clear_scroll_region(&mut self) -> Result<(), Self::Error>

Available on crate feature scrolling-regions only.
Clear scroll region (if supported).

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.