2021-01-01 15:20:51 +00:00
|
|
|
use std::error::Error;
|
2020-05-21 18:42:34 +00:00
|
|
|
use tui::{
|
|
|
|
backend::{Backend, TestBackend},
|
2021-01-01 15:20:51 +00:00
|
|
|
layout::Rect,
|
|
|
|
widgets::Paragraph,
|
2020-05-21 18:42:34 +00:00
|
|
|
Terminal,
|
|
|
|
};
|
2018-11-24 18:19:14 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn terminal_buffer_size_should_be_limited() {
|
2018-11-24 18:19:14 +00:00
|
|
|
let backend = TestBackend::new(400, 400);
|
|
|
|
let terminal = Terminal::new(backend).unwrap();
|
|
|
|
let size = terminal.backend().size().unwrap();
|
|
|
|
assert_eq!(size.width, 255);
|
|
|
|
assert_eq!(size.height, 255);
|
|
|
|
}
|
2021-01-01 15:20:51 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn terminal_draw_returns_the_completed_frame() -> Result<(), Box<dyn Error>> {
|
|
|
|
let backend = TestBackend::new(10, 10);
|
|
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
let frame = terminal.draw(|f| {
|
2023-03-16 13:26:50 +00:00
|
|
|
let paragraph = Paragraph::new("Test");
|
|
|
|
f.render_widget(paragraph, f.size());
|
2021-01-01 15:20:51 +00:00
|
|
|
})?;
|
|
|
|
assert_eq!(frame.buffer.get(0, 0).symbol, "T");
|
|
|
|
assert_eq!(frame.area, Rect::new(0, 0, 10, 10));
|
|
|
|
terminal.backend_mut().resize(8, 8);
|
|
|
|
let frame = terminal.draw(|f| {
|
2023-03-16 13:26:50 +00:00
|
|
|
let paragraph = Paragraph::new("test");
|
|
|
|
f.render_widget(paragraph, f.size());
|
2021-01-01 15:20:51 +00:00
|
|
|
})?;
|
|
|
|
assert_eq!(frame.buffer.get(0, 0).symbol, "t");
|
|
|
|
assert_eq!(frame.area, Rect::new(0, 0, 8, 8));
|
|
|
|
Ok(())
|
|
|
|
}
|