2023-05-18 18:21:43 +00:00
|
|
|
#![allow(deprecated)]
|
|
|
|
|
2023-03-17 16:03:49 +00:00
|
|
|
use ratatui::{
|
2020-11-15 21:47:00 +00:00
|
|
|
backend::TestBackend,
|
|
|
|
buffer::Buffer,
|
|
|
|
layout::Constraint,
|
2020-11-29 22:43:55 +00:00
|
|
|
style::{Color, Modifier, Style},
|
2023-05-18 18:21:43 +00:00
|
|
|
text::{Line, Span},
|
2023-08-11 14:15:46 +00:00
|
|
|
widgets::{Block, Borders, Cell, HighlightSpacing, Row, Table, TableState},
|
2020-11-15 21:47:00 +00:00
|
|
|
Terminal,
|
|
|
|
};
|
2024-05-14 01:13:46 +00:00
|
|
|
use rstest::rstest;
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
#[case::no_space_between_columns(0, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1Head2Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11Row12Row13 │",
|
|
|
|
"│Row21Row22Row23 │",
|
|
|
|
"│Row31Row32Row33 │",
|
|
|
|
"│Row41Row42Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::one_space_between_columns(1, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::large_width_just_before_pushing_a_column_off(6, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::large_width_pushes_part_of_third_column_off(7, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head Head3│",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row1 Row13│",
|
|
|
|
"│Row21 Row2 Row23│",
|
|
|
|
"│Row31 Row3 Row33│",
|
|
|
|
"│Row41 Row4 Row43│",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
fn widgets_table_column_spacing_can_be_changed<'line, Lines>(
|
|
|
|
#[case] column_spacing: u16,
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered())
|
|
|
|
.column_spacing(column_spacing);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_widget(table, f.area());
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
#[rstest]
|
|
|
|
#[case::zero_width_shows_nothing( &[
|
|
|
|
Constraint::Length(0),
|
|
|
|
Constraint::Length(0),
|
|
|
|
Constraint::Length(0),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::slim_columns_trim_data(&[
|
|
|
|
Constraint::Length(1),
|
|
|
|
Constraint::Length(1),
|
|
|
|
Constraint::Length(1),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│H H H │",
|
|
|
|
"│ │",
|
|
|
|
"│R R R │",
|
|
|
|
"│R R R │",
|
|
|
|
"│R R R │",
|
|
|
|
"│R R R │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::large_width_just_before_pushing_a_column_off(&[
|
|
|
|
Constraint::Length(8),
|
|
|
|
Constraint::Length(8),
|
|
|
|
Constraint::Length(8),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
fn widgets_table_columns_widths_can_use_fixed_length_constraints<'line, Lines>(
|
|
|
|
#[case] widths: &[Constraint],
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]),
|
|
|
|
],
|
|
|
|
widths,
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered());
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_widget(table, f.area());
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
#[rstest]
|
|
|
|
#[case::zero_width_shows_nothing(&[
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::slim_columns_trim_data(&[
|
|
|
|
Constraint::Percentage(11),
|
|
|
|
Constraint::Percentage(11),
|
|
|
|
Constraint::Percentage(11),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│HeaHeaHea │",
|
|
|
|
"│ │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::large_width_just_before_pushing_a_column_off(&[
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::sum_100_equal_widths(&[Constraint::Percentage(50), Constraint::Percentage(50)], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 │",
|
|
|
|
"│Row21 Row22 │",
|
|
|
|
"│Row31 Row32 │",
|
|
|
|
"│Row41 Row42 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
fn widgets_table_columns_widths_can_use_percentage_constraints<'line, Lines>(
|
|
|
|
#[case] widths: &[Constraint],
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]),
|
|
|
|
],
|
|
|
|
widths,
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered())
|
|
|
|
.column_spacing(0);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_widget(table, f.area());
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
}
|
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
#[rstest]
|
|
|
|
#[case::zero_width_shows_nothing(&[
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
Constraint::Length(0),
|
|
|
|
Constraint::Percentage(0),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::slim_columns_trim_data(&[
|
|
|
|
Constraint::Percentage(11),
|
|
|
|
Constraint::Length(20),
|
|
|
|
Constraint::Percentage(11),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Hea Head2 Hea│",
|
|
|
|
"│ │",
|
|
|
|
"│Row Row12 Row│",
|
|
|
|
"│Row Row22 Row│",
|
|
|
|
"│Row Row32 Row│",
|
|
|
|
"│Row Row42 Row│",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::large_width_just_before_pushing_a_column_off(&[
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
Constraint::Length(10),
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::more_than_100(&[
|
|
|
|
Constraint::Percentage(60),
|
|
|
|
Constraint::Length(10),
|
|
|
|
Constraint::Percentage(60),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
fn widgets_table_columns_widths_can_use_mixed_constraints<'line, Lines>(
|
|
|
|
#[case] widths: &[Constraint],
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]),
|
|
|
|
],
|
|
|
|
widths,
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered());
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_widget(table, f.area());
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2019-07-10 10:39:10 +00:00
|
|
|
}
|
2020-11-14 15:45:36 +00:00
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
#[rstest]
|
|
|
|
#[case::zero_shows_nothing(&[
|
|
|
|
Constraint::Ratio(0, 1),
|
|
|
|
Constraint::Ratio(0, 1),
|
|
|
|
Constraint::Ratio(0, 1),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::slim_trims_data(&[
|
|
|
|
Constraint::Ratio(1, 9),
|
|
|
|
Constraint::Ratio(1, 9),
|
|
|
|
Constraint::Ratio(1, 9),
|
|
|
|
], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│HeaHeaHea │",
|
|
|
|
"│ │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│RowRowRow │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::three(&[Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::two(&[Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)], [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 │",
|
|
|
|
"│Row21 Row22 │",
|
|
|
|
"│Row31 Row32 │",
|
|
|
|
"│Row41 Row42 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
fn widgets_table_columns_widths_can_use_ratio_constraints<'line, Lines>(
|
|
|
|
#[case] widths: &[Constraint],
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let backend = TestBackend::new(30, 10);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]),
|
|
|
|
],
|
|
|
|
widths,
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered())
|
|
|
|
.column_spacing(0);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_widget(table, f.area());
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2020-11-14 15:45:36 +00:00
|
|
|
}
|
2020-11-29 22:43:55 +00:00
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
#[rstest]
|
|
|
|
#[case::none(
|
|
|
|
None,
|
|
|
|
[
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
],
|
|
|
|
)]
|
|
|
|
#[case::first(
|
|
|
|
Some(0),
|
|
|
|
[
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│>> Row11 Row12 Row13 │",
|
|
|
|
"│ Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
],
|
|
|
|
)]
|
|
|
|
#[case::second_no_partially_fourth(
|
|
|
|
Some(1),
|
|
|
|
[
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row11 Row12 Row13 │",
|
|
|
|
"│>> Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
],
|
|
|
|
)]
|
|
|
|
#[case::fourth_no_partially_first(
|
|
|
|
Some(3),
|
|
|
|
[
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row31 Row32 Row33 │",
|
|
|
|
"│>> Row41 Row42 Row43 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
],
|
|
|
|
)]
|
|
|
|
fn widgets_table_can_have_rows_with_multi_lines<'line, Lines>(
|
|
|
|
#[case] selected: Option<usize>,
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let mut state = TableState::new().with_selected(selected);
|
|
|
|
let backend = TestBackend::new(30, 8);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]).height(2),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]).height(2),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered())
|
|
|
|
.highlight_symbol(">> ")
|
|
|
|
.column_spacing(1);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_stateful_widget(table, f.area(), &mut state);
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2020-11-29 22:43:55 +00:00
|
|
|
}
|
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
#[rstest]
|
|
|
|
#[case::none_when_selected(None, HighlightSpacing::WhenSelected, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::none_always(
|
|
|
|
None, HighlightSpacing::Always, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row11 Row12 Row13 │",
|
|
|
|
"│ Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::none_never(None, HighlightSpacing::Never, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::first_when_selected(Some(0), HighlightSpacing::WhenSelected, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│>> Row11 Row12 Row13 │",
|
|
|
|
"│ Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::first_always(Some(0), HighlightSpacing::Always, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│>> Row11 Row12 Row13 │",
|
|
|
|
"│ Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│ Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
#[case::first_never(Some(0), HighlightSpacing::Never, [
|
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row11 Row12 Row13 │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
])]
|
|
|
|
fn widgets_table_enable_always_highlight_spacing<'line, Lines>(
|
|
|
|
#[case] selected: Option<usize>,
|
|
|
|
#[case] space: HighlightSpacing,
|
|
|
|
#[case] expected: Lines,
|
|
|
|
) where
|
|
|
|
Lines: IntoIterator,
|
|
|
|
Lines::Item: Into<Line<'line>>,
|
|
|
|
{
|
|
|
|
let mut state = TableState::new().with_selected(selected);
|
|
|
|
let backend = TestBackend::new(30, 8);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]).height(2),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]).height(2),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
|
|
|
.block(Block::bordered())
|
|
|
|
.highlight_symbol(">> ")
|
|
|
|
.highlight_spacing(space)
|
|
|
|
.column_spacing(1);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_stateful_widget(table, f.area(), &mut state);
|
2024-05-14 01:13:46 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
terminal.backend().assert_buffer_lines(expected);
|
2023-08-11 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 22:43:55 +00:00
|
|
|
#[test]
|
|
|
|
fn widgets_table_can_have_elements_styled_individually() {
|
|
|
|
let backend = TestBackend::new(30, 4);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
let mut state = TableState::default();
|
|
|
|
state.select(Some(0));
|
2024-10-13 11:06:29 +00:00
|
|
|
state.select_column(Some(1));
|
2020-11-29 22:43:55 +00:00
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
2023-12-04 23:22:52 +00:00
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"])
|
|
|
|
.style(Style::default().fg(Color::Green)),
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::from("Row21"),
|
|
|
|
Cell::from("Row22").style(Style::default().fg(Color::Yellow)),
|
|
|
|
Cell::from(Line::from(vec![
|
|
|
|
Span::raw("Row"),
|
|
|
|
Span::styled("23", Style::default().fg(Color::Blue)),
|
|
|
|
]))
|
|
|
|
.style(Style::default().fg(Color::Red)),
|
|
|
|
])
|
|
|
|
.style(Style::default().fg(Color::LightGreen)),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constraint::Length(6),
|
|
|
|
Constraint::Length(6),
|
|
|
|
Constraint::Length(6),
|
|
|
|
],
|
|
|
|
)
|
2020-11-29 22:43:55 +00:00
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
2024-05-02 10:09:48 +00:00
|
|
|
.block(Block::new().borders(Borders::LEFT | Borders::RIGHT))
|
2020-11-29 22:43:55 +00:00
|
|
|
.highlight_symbol(">> ")
|
2024-10-13 11:06:29 +00:00
|
|
|
.row_highlight_style(Style::default().add_modifier(Modifier::BOLD))
|
|
|
|
.column_highlight_style(Style::default().add_modifier(Modifier::ITALIC))
|
|
|
|
.cell_highlight_style(Style::default().add_modifier(Modifier::DIM))
|
2020-11-29 22:43:55 +00:00
|
|
|
.column_spacing(1);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_stateful_widget(table, f.area(), &mut state);
|
2020-11-29 22:43:55 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
let mut expected = Buffer::with_lines([
|
2020-11-29 22:43:55 +00:00
|
|
|
"│ Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│>> Row11 Row12 Row13 │",
|
|
|
|
"│ Row21 Row22 Row23 │",
|
|
|
|
]);
|
|
|
|
// First row = row color + highlight style
|
|
|
|
for col in 1..=28 {
|
feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084)
Code which previously called `buf.get(x, y)` or `buf.get_mut(x, y)`
should now use index operators, or be transitioned to `buff.cell()` or
`buf.cell_mut()` for safe access that avoids panics by returning
`Option<&Cell>` and `Option<&mut Cell>`.
The new methods accept `Into<Position>` instead of `x` and `y`
coordinates, which makes them more ergonomic to use.
```rust
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
let cell = buf[(0, 0)];
let cell = buf[Position::new(0, 0)];
let symbol = buf.cell((0, 0)).map(|cell| cell.symbol());
let symbol = buf.cell(Position::new(0, 0)).map(|cell| cell.symbol());
buf[(0, 0)].set_symbol("🐀");
buf[Position::new(0, 0)].set_symbol("🐀");
buf.cell_mut((0, 0)).map(|cell| cell.set_symbol("🐀"));
buf.cell_mut(Position::new(0, 0)).map(|cell| cell.set_symbol("🐀"));
```
The existing `get()` and `get_mut()` methods are marked as deprecated.
These are fairly widely used and we will leave these methods around on
the buffer for a longer time than our normal deprecation approach (2
major release)
Addresses part of: https://github.com/ratatui-org/ratatui/issues/1011
---------
Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
2024-08-06 07:40:47 +00:00
|
|
|
expected[(col, 2)].set_style(
|
2020-11-29 22:43:55 +00:00
|
|
|
Style::default()
|
|
|
|
.fg(Color::Green)
|
|
|
|
.add_modifier(Modifier::BOLD),
|
|
|
|
);
|
|
|
|
}
|
2024-10-13 11:06:29 +00:00
|
|
|
|
|
|
|
// Second column highlight style
|
|
|
|
for row in 2..=3 {
|
|
|
|
for col in 11..=16 {
|
|
|
|
expected[(col, row)].set_style(Style::default().add_modifier(Modifier::ITALIC));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// First row, second column highlight style (cell highlight)
|
|
|
|
for col in 11..=16 {
|
|
|
|
expected[(col, 2)].set_style(Style::default().add_modifier(Modifier::DIM));
|
|
|
|
}
|
|
|
|
|
2020-11-29 22:43:55 +00:00
|
|
|
// Second row:
|
|
|
|
// 1. row color
|
|
|
|
for col in 1..=28 {
|
feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084)
Code which previously called `buf.get(x, y)` or `buf.get_mut(x, y)`
should now use index operators, or be transitioned to `buff.cell()` or
`buf.cell_mut()` for safe access that avoids panics by returning
`Option<&Cell>` and `Option<&mut Cell>`.
The new methods accept `Into<Position>` instead of `x` and `y`
coordinates, which makes them more ergonomic to use.
```rust
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
let cell = buf[(0, 0)];
let cell = buf[Position::new(0, 0)];
let symbol = buf.cell((0, 0)).map(|cell| cell.symbol());
let symbol = buf.cell(Position::new(0, 0)).map(|cell| cell.symbol());
buf[(0, 0)].set_symbol("🐀");
buf[Position::new(0, 0)].set_symbol("🐀");
buf.cell_mut((0, 0)).map(|cell| cell.set_symbol("🐀"));
buf.cell_mut(Position::new(0, 0)).map(|cell| cell.set_symbol("🐀"));
```
The existing `get()` and `get_mut()` methods are marked as deprecated.
These are fairly widely used and we will leave these methods around on
the buffer for a longer time than our normal deprecation approach (2
major release)
Addresses part of: https://github.com/ratatui-org/ratatui/issues/1011
---------
Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
2024-08-06 07:40:47 +00:00
|
|
|
expected[(col, 3)].set_style(Style::default().fg(Color::LightGreen));
|
2020-11-29 22:43:55 +00:00
|
|
|
}
|
|
|
|
// 2. cell color
|
|
|
|
for col in 11..=16 {
|
feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084)
Code which previously called `buf.get(x, y)` or `buf.get_mut(x, y)`
should now use index operators, or be transitioned to `buff.cell()` or
`buf.cell_mut()` for safe access that avoids panics by returning
`Option<&Cell>` and `Option<&mut Cell>`.
The new methods accept `Into<Position>` instead of `x` and `y`
coordinates, which makes them more ergonomic to use.
```rust
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
let cell = buf[(0, 0)];
let cell = buf[Position::new(0, 0)];
let symbol = buf.cell((0, 0)).map(|cell| cell.symbol());
let symbol = buf.cell(Position::new(0, 0)).map(|cell| cell.symbol());
buf[(0, 0)].set_symbol("🐀");
buf[Position::new(0, 0)].set_symbol("🐀");
buf.cell_mut((0, 0)).map(|cell| cell.set_symbol("🐀"));
buf.cell_mut(Position::new(0, 0)).map(|cell| cell.set_symbol("🐀"));
```
The existing `get()` and `get_mut()` methods are marked as deprecated.
These are fairly widely used and we will leave these methods around on
the buffer for a longer time than our normal deprecation approach (2
major release)
Addresses part of: https://github.com/ratatui-org/ratatui/issues/1011
---------
Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
2024-08-06 07:40:47 +00:00
|
|
|
expected[(col, 3)].set_style(Style::default().fg(Color::Yellow));
|
2020-11-29 22:43:55 +00:00
|
|
|
}
|
|
|
|
for col in 18..=23 {
|
feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084)
Code which previously called `buf.get(x, y)` or `buf.get_mut(x, y)`
should now use index operators, or be transitioned to `buff.cell()` or
`buf.cell_mut()` for safe access that avoids panics by returning
`Option<&Cell>` and `Option<&mut Cell>`.
The new methods accept `Into<Position>` instead of `x` and `y`
coordinates, which makes them more ergonomic to use.
```rust
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
let cell = buf[(0, 0)];
let cell = buf[Position::new(0, 0)];
let symbol = buf.cell((0, 0)).map(|cell| cell.symbol());
let symbol = buf.cell(Position::new(0, 0)).map(|cell| cell.symbol());
buf[(0, 0)].set_symbol("🐀");
buf[Position::new(0, 0)].set_symbol("🐀");
buf.cell_mut((0, 0)).map(|cell| cell.set_symbol("🐀"));
buf.cell_mut(Position::new(0, 0)).map(|cell| cell.set_symbol("🐀"));
```
The existing `get()` and `get_mut()` methods are marked as deprecated.
These are fairly widely used and we will leave these methods around on
the buffer for a longer time than our normal deprecation approach (2
major release)
Addresses part of: https://github.com/ratatui-org/ratatui/issues/1011
---------
Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
2024-08-06 07:40:47 +00:00
|
|
|
expected[(col, 3)].set_style(Style::default().fg(Color::Red));
|
2020-11-29 22:43:55 +00:00
|
|
|
}
|
|
|
|
// 3. text color
|
|
|
|
for col in 21..=22 {
|
feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084)
Code which previously called `buf.get(x, y)` or `buf.get_mut(x, y)`
should now use index operators, or be transitioned to `buff.cell()` or
`buf.cell_mut()` for safe access that avoids panics by returning
`Option<&Cell>` and `Option<&mut Cell>`.
The new methods accept `Into<Position>` instead of `x` and `y`
coordinates, which makes them more ergonomic to use.
```rust
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
let cell = buf[(0, 0)];
let cell = buf[Position::new(0, 0)];
let symbol = buf.cell((0, 0)).map(|cell| cell.symbol());
let symbol = buf.cell(Position::new(0, 0)).map(|cell| cell.symbol());
buf[(0, 0)].set_symbol("🐀");
buf[Position::new(0, 0)].set_symbol("🐀");
buf.cell_mut((0, 0)).map(|cell| cell.set_symbol("🐀"));
buf.cell_mut(Position::new(0, 0)).map(|cell| cell.set_symbol("🐀"));
```
The existing `get()` and `get_mut()` methods are marked as deprecated.
These are fairly widely used and we will leave these methods around on
the buffer for a longer time than our normal deprecation approach (2
major release)
Addresses part of: https://github.com/ratatui-org/ratatui/issues/1011
---------
Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de>
2024-08-06 07:40:47 +00:00
|
|
|
expected[(col, 3)].set_style(Style::default().fg(Color::Blue));
|
2020-11-29 22:43:55 +00:00
|
|
|
}
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
}
|
2020-12-08 20:49:16 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn widgets_table_should_render_even_if_empty() {
|
|
|
|
let backend = TestBackend::new(30, 4);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
2023-12-04 23:22:52 +00:00
|
|
|
let table = Table::new(
|
2024-01-11 01:32:58 +00:00
|
|
|
Vec::<Row>::new(),
|
2023-12-04 23:22:52 +00:00
|
|
|
[
|
2020-12-08 20:49:16 +00:00
|
|
|
Constraint::Length(6),
|
|
|
|
Constraint::Length(6),
|
|
|
|
Constraint::Length(6),
|
2023-12-04 23:22:52 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]))
|
2024-05-02 10:09:48 +00:00
|
|
|
.block(Block::new().borders(Borders::LEFT | Borders::RIGHT))
|
2023-12-04 23:22:52 +00:00
|
|
|
.column_spacing(1);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_widget(table, f.area());
|
2020-12-08 20:49:16 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2024-05-14 01:13:46 +00:00
|
|
|
terminal.backend().assert_buffer_lines([
|
2020-12-08 20:49:16 +00:00
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
]);
|
|
|
|
}
|
2021-08-01 14:27:05 +00:00
|
|
|
|
2024-05-14 01:13:46 +00:00
|
|
|
// based on https://github.com/fdehau/tui-rs/issues/470#issuecomment-852562848
|
2021-08-01 14:27:05 +00:00
|
|
|
#[test]
|
|
|
|
fn widgets_table_columns_dont_panic() {
|
2024-05-14 01:13:46 +00:00
|
|
|
let table_width = 98;
|
|
|
|
let table = Table::new(
|
2023-12-04 23:22:52 +00:00
|
|
|
vec![Row::new(vec!["r1", "r2", "r3", "r4"])],
|
|
|
|
[
|
2021-08-01 14:27:05 +00:00
|
|
|
Constraint::Percentage(15),
|
|
|
|
Constraint::Percentage(15),
|
|
|
|
Constraint::Percentage(25),
|
|
|
|
Constraint::Percentage(45),
|
2023-12-04 23:22:52 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["h1", "h2", "h3", "h4"]))
|
2024-05-02 10:09:48 +00:00
|
|
|
.block(Block::bordered())
|
2023-12-04 23:22:52 +00:00
|
|
|
.highlight_symbol(">> ")
|
|
|
|
.column_spacing(1);
|
2021-08-01 14:27:05 +00:00
|
|
|
|
|
|
|
let mut state = TableState::default();
|
|
|
|
|
|
|
|
// select first, which would cause a panic before fix
|
|
|
|
state.select(Some(0));
|
2024-05-14 01:13:46 +00:00
|
|
|
|
|
|
|
let backend = TestBackend::new(table_width, 8);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
2024-08-06 03:15:14 +00:00
|
|
|
.draw(|f| f.render_stateful_widget(table, f.area(), &mut state))
|
2024-05-14 01:13:46 +00:00
|
|
|
.unwrap();
|
2021-08-01 14:27:05 +00:00
|
|
|
}
|
2021-08-01 15:51:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn widgets_table_should_clamp_offset_if_rows_are_removed() {
|
|
|
|
let backend = TestBackend::new(30, 8);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
let mut state = TableState::default();
|
|
|
|
|
|
|
|
// render with 6 items => offset will be at 2
|
|
|
|
state.select(Some(5));
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
2023-12-04 23:22:52 +00:00
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec!["Row01", "Row02", "Row03"]),
|
|
|
|
Row::new(vec!["Row11", "Row12", "Row13"]),
|
|
|
|
Row::new(vec!["Row21", "Row22", "Row23"]),
|
|
|
|
Row::new(vec!["Row31", "Row32", "Row33"]),
|
|
|
|
Row::new(vec!["Row41", "Row42", "Row43"]),
|
|
|
|
Row::new(vec!["Row51", "Row52", "Row53"]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
],
|
|
|
|
)
|
2021-08-01 15:51:44 +00:00
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
2024-05-02 10:09:48 +00:00
|
|
|
.block(Block::bordered())
|
2021-08-01 15:51:44 +00:00
|
|
|
.column_spacing(1);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_stateful_widget(table, f.area(), &mut state);
|
2021-08-01 15:51:44 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2024-05-14 01:13:46 +00:00
|
|
|
terminal.backend().assert_buffer_lines([
|
2021-08-01 15:51:44 +00:00
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row21 Row22 Row23 │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│Row41 Row42 Row43 │",
|
|
|
|
"│Row51 Row52 Row53 │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
]);
|
|
|
|
|
|
|
|
// render with 1 item => offset will be at 1
|
|
|
|
state.select(Some(1));
|
|
|
|
terminal
|
|
|
|
.draw(|f| {
|
2023-12-04 23:22:52 +00:00
|
|
|
let table = Table::new(
|
|
|
|
vec![Row::new(vec!["Row31", "Row32", "Row33"])],
|
|
|
|
[
|
2021-08-01 15:51:44 +00:00
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
|
|
|
Constraint::Length(5),
|
2023-12-04 23:22:52 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
|
2024-05-02 10:09:48 +00:00
|
|
|
.block(Block::bordered())
|
2023-12-04 23:22:52 +00:00
|
|
|
.column_spacing(1);
|
2024-08-06 03:15:14 +00:00
|
|
|
f.render_stateful_widget(table, f.area(), &mut state);
|
2021-08-01 15:51:44 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2024-05-14 01:13:46 +00:00
|
|
|
terminal.backend().assert_buffer_lines([
|
2021-08-01 15:51:44 +00:00
|
|
|
"┌────────────────────────────┐",
|
|
|
|
"│Head1 Head2 Head3 │",
|
|
|
|
"│ │",
|
|
|
|
"│Row31 Row32 Row33 │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"│ │",
|
|
|
|
"└────────────────────────────┘",
|
|
|
|
]);
|
|
|
|
}
|