mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-14 00:47:14 +00:00
728f82c084
* refactor: add Line type to replace Spans `Line` is a significantly better name over `Spans` as the plural causes confusion and the type really is a representation of a line of text made up of spans. This is a backwards compatible version of the approach from https://github.com/tui-rs-revival/ratatui/pull/175 There is a significant amount of code that uses the Spans type and methods, so instead of just renaming it, we add a new type and replace parameters that accepts a `Spans` with a parameter that accepts `Into<Line>`. Note that the examples have been intentionally left using `Spans` in this commit to demonstrate the compiler warnings that will be emitted in existing code. Implementation notes: - moves the Spans code to text::spans and publicly reexports on the text module. This makes the test in that module only relevant to the Spans type. - adds a line module with a copy of the code and tests from Spans with a single addition: `impl<'a> From<Spans<'a>> for Line<'a>` - adds tests for `Spans` (created and checked before refactoring) - adds the same tests for `Line` - updates all widget methods that accept and store Spans to instead store `Line` and accept `Into<Line>` * refactor: move text::Masked to text::masked::Masked Re-exports the Masked type at text::Masked * refactor: replace Spans with Line in tests/examples/docs
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
#![allow(deprecated)]
|
|
|
|
use ratatui::{
|
|
backend::TestBackend, buffer::Buffer, layout::Rect, symbols, text::Line, widgets::Tabs,
|
|
Terminal,
|
|
};
|
|
|
|
#[test]
|
|
fn widgets_tabs_should_not_panic_on_narrow_areas() {
|
|
let backend = TestBackend::new(1, 1);
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
terminal
|
|
.draw(|f| {
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Line::from).collect());
|
|
f.render_widget(
|
|
tabs,
|
|
Rect {
|
|
x: 0,
|
|
y: 0,
|
|
width: 1,
|
|
height: 1,
|
|
},
|
|
);
|
|
})
|
|
.unwrap();
|
|
let expected = Buffer::with_lines(vec![" "]);
|
|
terminal.backend().assert_buffer(&expected);
|
|
}
|
|
|
|
#[test]
|
|
fn widgets_tabs_should_truncate_the_last_item() {
|
|
let backend = TestBackend::new(10, 1);
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
terminal
|
|
.draw(|f| {
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Line::from).collect());
|
|
f.render_widget(
|
|
tabs,
|
|
Rect {
|
|
x: 0,
|
|
y: 0,
|
|
width: 9,
|
|
height: 1,
|
|
},
|
|
);
|
|
})
|
|
.unwrap();
|
|
let expected = Buffer::with_lines(vec![format!(" Tab1 {} T ", symbols::line::VERTICAL)]);
|
|
terminal.backend().assert_buffer(&expected);
|
|
}
|