Struct ratatui::backend::TestBackend
source · pub struct TestBackend { /* private fields */ }
Expand description
A Backend
implementation used for integration testing that that renders to an in memory
buffer.
Note: that although many of the integration and unit tests in ratatui are written using this backend, it is preferable to write unit tests for widgets directly against the buffer rather than using this backend. This backend is intended for integration tests that test the entire terminal UI.
§Example
use ratatui::{backend::TestBackend, prelude::*};
let mut backend = TestBackend::new(10, 2);
backend.clear()?;
backend.assert_buffer(&Buffer::with_lines(vec![" "; 2]));
Implementations§
source§impl TestBackend
impl TestBackend
sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Creates a new TestBackend
with the specified width and height.
sourcepub const fn buffer(&self) -> &Buffer
pub const fn buffer(&self) -> &Buffer
Returns a reference to the internal buffer of the TestBackend
.
sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resizes the TestBackend
to the specified width and height.
sourcepub fn assert_buffer(&self, expected: &Buffer)
pub fn assert_buffer(&self, expected: &Buffer)
Asserts that the TestBackend
’s buffer is equal to the expected buffer.
If the buffers are not equal, a panic occurs with a detailed error message
showing the differences between the expected and actual buffers.
Trait Implementations§
source§impl Backend for TestBackend
impl Backend for TestBackend
source§fn append_lines(&mut self, n: u16) -> Result<()>
fn append_lines(&mut self, n: u16) -> Result<()>
Inserts n line breaks at the current cursor position.
After the insertion, the cursor x position will be incremented by 1 (unless it’s already at the end of line). This is a common behaviour of terminals in raw mode.
If the number of lines to append is fewer than the number of lines in the buffer after the cursor y position then the cursor is moved down by n rows.
If the number of lines to append is greater than the number of lines in the buffer after the cursor y position then that number of empty lines (at most the buffer’s height in this case but this limit is instead replaced with scrolling in most backend implementations) will be added after the current position and the cursor will be moved to the last row.
source§fn draw<'a, I>(&mut self, content: I) -> Result<()>
fn draw<'a, I>(&mut self, content: I) -> Result<()>
source§fn get_cursor(&mut self) -> Result<(u16, u16)>
fn get_cursor(&mut self) -> Result<(u16, u16)>
source§fn set_cursor(&mut self, x: u16, y: u16) -> Result<()>
fn set_cursor(&mut self, x: u16, y: u16) -> Result<()>
source§fn window_size(&mut self) -> Result<WindowSize>
fn window_size(&mut self) -> Result<WindowSize>
WindowSize
. Read moresource§impl Clone for TestBackend
impl Clone for TestBackend
source§fn clone(&self) -> TestBackend
fn clone(&self) -> TestBackend
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TestBackend
impl Debug for TestBackend
source§impl<'de> Deserialize<'de> for TestBackend
impl<'de> Deserialize<'de> for TestBackend
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for TestBackend
impl Display for TestBackend
source§impl Hash for TestBackend
impl Hash for TestBackend
source§impl PartialEq for TestBackend
impl PartialEq for TestBackend
source§fn eq(&self, other: &TestBackend) -> bool
fn eq(&self, other: &TestBackend) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for TestBackend
impl Serialize for TestBackend
impl Eq for TestBackend
impl StructuralPartialEq for TestBackend
Auto Trait Implementations§
impl Freeze for TestBackend
impl RefUnwindSafe for TestBackend
impl Send for TestBackend
impl Sync for TestBackend
impl Unpin for TestBackend
impl UnwindSafe for TestBackend
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more