2020-08-02 16:30:52 +00:00
|
|
|
#[cfg(feature = "termion")]
|
|
|
|
#[test]
|
|
|
|
fn backend_termion_should_only_write_diffs() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
use std::{fmt::Write, io::Cursor};
|
|
|
|
|
|
|
|
let mut bytes = Vec::new();
|
|
|
|
let mut stdout = Cursor::new(&mut bytes);
|
|
|
|
{
|
2023-03-17 16:03:49 +00:00
|
|
|
use ratatui::{
|
2020-08-02 16:30:52 +00:00
|
|
|
backend::TermionBackend, layout::Rect, widgets::Paragraph, Terminal, TerminalOptions,
|
|
|
|
Viewport,
|
|
|
|
};
|
|
|
|
let backend = TermionBackend::new(&mut stdout);
|
|
|
|
let area = Rect::new(0, 0, 3, 1);
|
|
|
|
let mut terminal = Terminal::with_options(
|
|
|
|
backend,
|
|
|
|
TerminalOptions {
|
2023-04-17 12:23:50 +00:00
|
|
|
viewport: Viewport::Fixed(area),
|
2020-08-02 16:30:52 +00:00
|
|
|
},
|
|
|
|
)?;
|
|
|
|
terminal.draw(|f| {
|
|
|
|
f.render_widget(Paragraph::new("a"), area);
|
|
|
|
})?;
|
|
|
|
terminal.draw(|f| {
|
|
|
|
f.render_widget(Paragraph::new("ab"), area);
|
|
|
|
})?;
|
|
|
|
terminal.draw(|f| {
|
|
|
|
f.render_widget(Paragraph::new("abc"), area);
|
|
|
|
})?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let expected = {
|
2024-05-28 20:23:39 +00:00
|
|
|
use ratatui::termion::{color, cursor, style};
|
2020-08-02 16:30:52 +00:00
|
|
|
let mut s = String::new();
|
|
|
|
// First draw
|
|
|
|
write!(s, "{}", cursor::Goto(1, 1))?;
|
2020-11-29 17:35:52 +00:00
|
|
|
s.push('a');
|
2020-08-02 16:30:52 +00:00
|
|
|
write!(s, "{}", color::Fg(color::Reset))?;
|
|
|
|
write!(s, "{}", color::Bg(color::Reset))?;
|
|
|
|
write!(s, "{}", style::Reset)?;
|
|
|
|
write!(s, "{}", cursor::Hide)?;
|
|
|
|
// Second draw
|
|
|
|
write!(s, "{}", cursor::Goto(2, 1))?;
|
2020-11-29 17:35:52 +00:00
|
|
|
s.push('b');
|
2020-08-02 16:30:52 +00:00
|
|
|
write!(s, "{}", color::Fg(color::Reset))?;
|
|
|
|
write!(s, "{}", color::Bg(color::Reset))?;
|
|
|
|
write!(s, "{}", style::Reset)?;
|
|
|
|
write!(s, "{}", cursor::Hide)?;
|
|
|
|
// Third draw
|
|
|
|
write!(s, "{}", cursor::Goto(3, 1))?;
|
2020-11-29 17:35:52 +00:00
|
|
|
s.push('c');
|
2020-08-02 16:30:52 +00:00
|
|
|
write!(s, "{}", color::Fg(color::Reset))?;
|
|
|
|
write!(s, "{}", color::Bg(color::Reset))?;
|
|
|
|
write!(s, "{}", style::Reset)?;
|
|
|
|
write!(s, "{}", cursor::Hide)?;
|
|
|
|
// Terminal drop
|
|
|
|
write!(s, "{}", cursor::Show)?;
|
|
|
|
s
|
|
|
|
};
|
|
|
|
assert_eq!(std::str::from_utf8(&bytes)?, expected);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|