@@ -1,717 +1,717 @@
1−use helix_tui::{
1+// use helix_tui::{
2− backend::TestBackend,
2+// backend::TestBackend,
3− buffer::Buffer,
3+// buffer::Buffer,
4− layout::Constraint,
4+// layout::Constraint,
5− style::{Color, Modifier, Style},
5+// style::{Color, Modifier, Style},
6− text::{Span, Spans},
6+// text::{Span, Spans},
7− widgets::{Block, Borders, Cell, Row, Table, TableState},
7+// widgets::{Block, Borders, Cell, Row, Table, TableState},
8− Terminal,
8+// Terminal,
12−fn widgets_table_column_spacing_can_be_changed() {
12+// fn widgets_table_column_spacing_can_be_changed() {
13− let test_case = |column_spacing, expected| {
13+// let test_case = |column_spacing, expected| {
14− let backend = TestBackend::new(30, 10);
14+// let backend = TestBackend::new(30, 10);
15− let mut terminal = Terminal::new(backend).unwrap();
15+// let mut terminal = Terminal::new(backend).unwrap();
17− terminal
17+// terminal
18− .draw(|f| {
18+// .draw(|f| {
19− let size = f.size();
19+// let size = f.size();
20− let table = Table::new(vec![
20+// let table = Table::new(vec![
21− Row::new(vec!["Row11", "Row12", "Row13"]),
21+// Row::new(vec!["Row11", "Row12", "Row13"]),
22− Row::new(vec!["Row21", "Row22", "Row23"]),
22+// Row::new(vec!["Row21", "Row22", "Row23"]),
23− Row::new(vec!["Row31", "Row32", "Row33"]),
23+// Row::new(vec!["Row31", "Row32", "Row33"]),
24− Row::new(vec!["Row41", "Row42", "Row43"]),
24+// Row::new(vec!["Row41", "Row42", "Row43"]),
26− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
26+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
27− .block(Block::default().borders(Borders::ALL))
27+// .block(Block::default().borders(Borders::ALL))
28− .widths(&[
28+// .widths(&[
29− Constraint::Length(5),
29+// Constraint::Length(5),
30− Constraint::Length(5),
30+// Constraint::Length(5),
31− Constraint::Length(5),
31+// Constraint::Length(5),
33− .column_spacing(column_spacing);
33+// .column_spacing(column_spacing);
34− f.render_widget(table, size);
34+// f.render_widget(table, size);
36− .unwrap();
36+// .unwrap();
37− terminal.backend().assert_buffer(&expected);
37+// terminal.backend().assert_buffer(&expected);
40− // no space between columns
40+// // no space between columns
41− test_case(
41+// test_case(
43− Buffer::with_lines(vec![
43+// Buffer::with_lines(vec![
44− "┌────────────────────────────┐",
44+// "┌────────────────────────────┐",
45− "│Head1Head2Head3 │",
45+// "│Head1Head2Head3 │",
47− "│Row11Row12Row13 │",
47+// "│Row11Row12Row13 │",
48− "│Row21Row22Row23 │",
48+// "│Row21Row22Row23 │",
49− "│Row31Row32Row33 │",
49+// "│Row31Row32Row33 │",
50− "│Row41Row42Row43 │",
50+// "│Row41Row42Row43 │",
53− "└────────────────────────────┘",
53+// "└────────────────────────────┘",
57− // one space between columns
57+// // one space between columns
58− test_case(
58+// test_case(
60− Buffer::with_lines(vec![
60+// Buffer::with_lines(vec![
61− "┌────────────────────────────┐",
61+// "┌────────────────────────────┐",
62− "│Head1 Head2 Head3 │",
62+// "│Head1 Head2 Head3 │",
64− "│Row11 Row12 Row13 │",
64+// "│Row11 Row12 Row13 │",
65− "│Row21 Row22 Row23 │",
65+// "│Row21 Row22 Row23 │",
66− "│Row31 Row32 Row33 │",
66+// "│Row31 Row32 Row33 │",
67− "│Row41 Row42 Row43 │",
67+// "│Row41 Row42 Row43 │",
70− "└────────────────────────────┘",
70+// "└────────────────────────────┘",
74− // enough space to just not hide the third column
74+// // enough space to just not hide the third column
75− test_case(
75+// test_case(
77− Buffer::with_lines(vec![
77+// Buffer::with_lines(vec![
78− "┌────────────────────────────┐",
78+// "┌────────────────────────────┐",
79− "│Head1 Head2 Head3 │",
79+// "│Head1 Head2 Head3 │",
81− "│Row11 Row12 Row13 │",
81+// "│Row11 Row12 Row13 │",
82− "│Row21 Row22 Row23 │",
82+// "│Row21 Row22 Row23 │",
83− "│Row31 Row32 Row33 │",
83+// "│Row31 Row32 Row33 │",
84− "│Row41 Row42 Row43 │",
84+// "│Row41 Row42 Row43 │",
87− "└────────────────────────────┘",
87+// "└────────────────────────────┘",
91− // enough space to hide part of the third column
91+// // enough space to hide part of the third column
92− test_case(
92+// test_case(
94− Buffer::with_lines(vec![
94+// Buffer::with_lines(vec![
95− "┌────────────────────────────┐",
95+// "┌────────────────────────────┐",
96− "│Head1 Head2 Head│",
96+// "│Head1 Head2 Head│",
98− "│Row11 Row12 Row1│",
98+// "│Row11 Row12 Row1│",
99− "│Row21 Row22 Row2│",
99+// "│Row21 Row22 Row2│",
100− "│Row31 Row32 Row3│",
100+// "│Row31 Row32 Row3│",
101− "│Row41 Row42 Row4│",
101+// "│Row41 Row42 Row4│",
104− "└────────────────────────────┘",
104+// "└────────────────────────────┘",
109−#[test]
109+// #[test]
110−fn widgets_table_columns_widths_can_use_fixed_length_constraints() {
110+// fn widgets_table_columns_widths_can_use_fixed_length_constraints() {
111− let test_case = |widths, expected| {
111+// let test_case = |widths, expected| {
112− let backend = TestBackend::new(30, 10);
112+// let backend = TestBackend::new(30, 10);
113− let mut terminal = Terminal::new(backend).unwrap();
113+// let mut terminal = Terminal::new(backend).unwrap();
115− terminal
115+// terminal
116− .draw(|f| {
116+// .draw(|f| {
117− let size = f.size();
117+// let size = f.size();
118− let table = Table::new(vec![
118+// let table = Table::new(vec![
119− Row::new(vec!["Row11", "Row12", "Row13"]),
119+// Row::new(vec!["Row11", "Row12", "Row13"]),
120− Row::new(vec!["Row21", "Row22", "Row23"]),
120+// Row::new(vec!["Row21", "Row22", "Row23"]),
121− Row::new(vec!["Row31", "Row32", "Row33"]),
121+// Row::new(vec!["Row31", "Row32", "Row33"]),
122− Row::new(vec!["Row41", "Row42", "Row43"]),
122+// Row::new(vec!["Row41", "Row42", "Row43"]),
124− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
124+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
125− .block(Block::default().borders(Borders::ALL))
125+// .block(Block::default().borders(Borders::ALL))
126− .widths(widths);
126+// .widths(widths);
127− f.render_widget(table, size);
127+// f.render_widget(table, size);
129− .unwrap();
129+// .unwrap();
130− terminal.backend().assert_buffer(&expected);
130+// terminal.backend().assert_buffer(&expected);
133− // columns of zero width show nothing
133+// // columns of zero width show nothing
134− test_case(
134+// test_case(
136− Constraint::Length(0),
136+// Constraint::Length(0),
137− Constraint::Length(0),
137+// Constraint::Length(0),
138− Constraint::Length(0),
138+// Constraint::Length(0),
140− Buffer::with_lines(vec![
140+// Buffer::with_lines(vec![
141− "┌────────────────────────────┐",
141+// "┌────────────────────────────┐",
150− "└────────────────────────────┘",
150+// "└────────────────────────────┘",
154− // columns of 1 width trim
154+// // columns of 1 width trim
155− test_case(
155+// test_case(
157− Constraint::Length(1),
157+// Constraint::Length(1),
158− Constraint::Length(1),
158+// Constraint::Length(1),
159− Constraint::Length(1),
159+// Constraint::Length(1),
161− Buffer::with_lines(vec![
161+// Buffer::with_lines(vec![
162− "┌────────────────────────────┐",
162+// "┌────────────────────────────┐",
163− "│H H H │",
163+// "│H H H │",
165− "│R R R │",
165+// "│R R R │",
166− "│R R R │",
166+// "│R R R │",
167− "│R R R │",
167+// "│R R R │",
168− "│R R R │",
168+// "│R R R │",
171− "└────────────────────────────┘",
171+// "└────────────────────────────┘",
175− // columns of large width just before pushing a column off
175+// // columns of large width just before pushing a column off
176− test_case(
176+// test_case(
178− Constraint::Length(8),
178+// Constraint::Length(8),
179− Constraint::Length(8),
179+// Constraint::Length(8),
180− Constraint::Length(8),
180+// Constraint::Length(8),
182− Buffer::with_lines(vec![
182+// Buffer::with_lines(vec![
183− "┌────────────────────────────┐",
183+// "┌────────────────────────────┐",
184− "│Head1 Head2 Head3 │",
184+// "│Head1 Head2 Head3 │",
186− "│Row11 Row12 Row13 │",
186+// "│Row11 Row12 Row13 │",
187− "│Row21 Row22 Row23 │",
187+// "│Row21 Row22 Row23 │",
188− "│Row31 Row32 Row33 │",
188+// "│Row31 Row32 Row33 │",
189− "│Row41 Row42 Row43 │",
189+// "│Row41 Row42 Row43 │",
192− "└────────────────────────────┘",
192+// "└────────────────────────────┘",
197−#[test]
197+// #[test]
198−fn widgets_table_columns_widths_can_use_percentage_constraints() {
198+// fn widgets_table_columns_widths_can_use_percentage_constraints() {
199− let test_case = |widths, expected| {
199+// let test_case = |widths, expected| {
200− let backend = TestBackend::new(30, 10);
200+// let backend = TestBackend::new(30, 10);
201− let mut terminal = Terminal::new(backend).unwrap();
201+// let mut terminal = Terminal::new(backend).unwrap();
203− terminal
203+// terminal
204− .draw(|f| {
204+// .draw(|f| {
205− let size = f.size();
205+// let size = f.size();
206− let table = Table::new(vec![
206+// let table = Table::new(vec![
207− Row::new(vec!["Row11", "Row12", "Row13"]),
207+// Row::new(vec!["Row11", "Row12", "Row13"]),
208− Row::new(vec!["Row21", "Row22", "Row23"]),
208+// Row::new(vec!["Row21", "Row22", "Row23"]),
209− Row::new(vec!["Row31", "Row32", "Row33"]),
209+// Row::new(vec!["Row31", "Row32", "Row33"]),
210− Row::new(vec!["Row41", "Row42", "Row43"]),
210+// Row::new(vec!["Row41", "Row42", "Row43"]),
212− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
212+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
213− .block(Block::default().borders(Borders::ALL))
213+// .block(Block::default().borders(Borders::ALL))
214− .widths(widths)
214+// .widths(widths)
215− .column_spacing(0);
215+// .column_spacing(0);
216− f.render_widget(table, size);
216+// f.render_widget(table, size);
218− .unwrap();
218+// .unwrap();
219− terminal.backend().assert_buffer(&expected);
219+// terminal.backend().assert_buffer(&expected);
222− // columns of zero width show nothing
222+// // columns of zero width show nothing
223− test_case(
223+// test_case(
225− Constraint::Percentage(0),
225+// Constraint::Percentage(0),
226− Constraint::Percentage(0),
226+// Constraint::Percentage(0),
227− Constraint::Percentage(0),
227+// Constraint::Percentage(0),
229− Buffer::with_lines(vec![
229+// Buffer::with_lines(vec![
230− "┌────────────────────────────┐",
230+// "┌────────────────────────────┐",
239− "└────────────────────────────┘",
239+// "└────────────────────────────┘",
243− // columns of not enough width trims the data
243+// // columns of not enough width trims the data
244− test_case(
244+// test_case(
246− Constraint::Percentage(11),
246+// Constraint::Percentage(11),
247− Constraint::Percentage(11),
247+// Constraint::Percentage(11),
248− Constraint::Percentage(11),
248+// Constraint::Percentage(11),
250− Buffer::with_lines(vec![
250+// Buffer::with_lines(vec![
251− "┌────────────────────────────┐",
251+// "┌────────────────────────────┐",
252− "│HeaHeaHea │",
252+// "│HeaHeaHea │",
254− "│RowRowRow │",
254+// "│RowRowRow │",
255− "│RowRowRow │",
255+// "│RowRowRow │",
256− "│RowRowRow │",
256+// "│RowRowRow │",
257− "│RowRowRow │",
257+// "│RowRowRow │",
260− "└────────────────────────────┘",
260+// "└────────────────────────────┘",
264− // columns of large width just before pushing a column off
264+// // columns of large width just before pushing a column off
265− test_case(
265+// test_case(
267− Constraint::Percentage(33),
267+// Constraint::Percentage(33),
268− Constraint::Percentage(33),
268+// Constraint::Percentage(33),
269− Constraint::Percentage(33),
269+// Constraint::Percentage(33),
271− Buffer::with_lines(vec![
271+// Buffer::with_lines(vec![
272− "┌────────────────────────────┐",
272+// "┌────────────────────────────┐",
273− "│Head1 Head2 Head3 │",
273+// "│Head1 Head2 Head3 │",
275− "│Row11 Row12 Row13 │",
275+// "│Row11 Row12 Row13 │",
276− "│Row21 Row22 Row23 │",
276+// "│Row21 Row22 Row23 │",
277− "│Row31 Row32 Row33 │",
277+// "│Row31 Row32 Row33 │",
278− "│Row41 Row42 Row43 │",
278+// "│Row41 Row42 Row43 │",
281− "└────────────────────────────┘",
281+// "└────────────────────────────┘",
285− // percentages summing to 100 should give equal widths
285+// // percentages summing to 100 should give equal widths
286− test_case(
286+// test_case(
287− &[Constraint::Percentage(50), Constraint::Percentage(50)],
287+// &[Constraint::Percentage(50), Constraint::Percentage(50)],
288− Buffer::with_lines(vec![
288+// Buffer::with_lines(vec![
289− "┌────────────────────────────┐",
289+// "┌────────────────────────────┐",
290− "│Head1 Head2 │",
290+// "│Head1 Head2 │",
292− "│Row11 Row12 │",
292+// "│Row11 Row12 │",
293− "│Row21 Row22 │",
293+// "│Row21 Row22 │",
294− "│Row31 Row32 │",
294+// "│Row31 Row32 │",
295− "│Row41 Row42 │",
295+// "│Row41 Row42 │",
298− "└────────────────────────────┘",
298+// "└────────────────────────────┘",
303−#[test]
303+// #[test]
304−fn widgets_table_columns_widths_can_use_mixed_constraints() {
304+// fn widgets_table_columns_widths_can_use_mixed_constraints() {
305− let test_case = |widths, expected| {
305+// let test_case = |widths, expected| {
306− let backend = TestBackend::new(30, 10);
306+// let backend = TestBackend::new(30, 10);
307− let mut terminal = Terminal::new(backend).unwrap();
307+// let mut terminal = Terminal::new(backend).unwrap();
309− terminal
309+// terminal
310− .draw(|f| {
310+// .draw(|f| {
311− let size = f.size();
311+// let size = f.size();
312− let table = Table::new(vec![
312+// let table = Table::new(vec![
313− Row::new(vec!["Row11", "Row12", "Row13"]),
313+// Row::new(vec!["Row11", "Row12", "Row13"]),
314− Row::new(vec!["Row21", "Row22", "Row23"]),
314+// Row::new(vec!["Row21", "Row22", "Row23"]),
315− Row::new(vec!["Row31", "Row32", "Row33"]),
315+// Row::new(vec!["Row31", "Row32", "Row33"]),
316− Row::new(vec!["Row41", "Row42", "Row43"]),
316+// Row::new(vec!["Row41", "Row42", "Row43"]),
318− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
318+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
319− .block(Block::default().borders(Borders::ALL))
319+// .block(Block::default().borders(Borders::ALL))
320− .widths(widths);
320+// .widths(widths);
321− f.render_widget(table, size);
321+// f.render_widget(table, size);
323− .unwrap();
323+// .unwrap();
324− terminal.backend().assert_buffer(&expected);
324+// terminal.backend().assert_buffer(&expected);
327− // columns of zero width show nothing
327+// // columns of zero width show nothing
328− test_case(
328+// test_case(
330− Constraint::Percentage(0),
330+// Constraint::Percentage(0),
331− Constraint::Length(0),
331+// Constraint::Length(0),
332− Constraint::Percentage(0),
332+// Constraint::Percentage(0),
334− Buffer::with_lines(vec![
334+// Buffer::with_lines(vec![
335− "┌────────────────────────────┐",
335+// "┌────────────────────────────┐",
344− "└────────────────────────────┘",
344+// "└────────────────────────────┘",
348− // columns of not enough width trims the data
348+// // columns of not enough width trims the data
349− test_case(
349+// test_case(
351− Constraint::Percentage(11),
351+// Constraint::Percentage(11),
352− Constraint::Length(20),
352+// Constraint::Length(20),
353− Constraint::Percentage(11),
353+// Constraint::Percentage(11),
355− Buffer::with_lines(vec![
355+// Buffer::with_lines(vec![
356− "┌────────────────────────────┐",
356+// "┌────────────────────────────┐",
357− "│Hea Head2 Hea│",
357+// "│Hea Head2 Hea│",
359− "│Row Row12 Row│",
359+// "│Row Row12 Row│",
360− "│Row Row22 Row│",
360+// "│Row Row22 Row│",
361− "│Row Row32 Row│",
361+// "│Row Row32 Row│",
362− "│Row Row42 Row│",
362+// "│Row Row42 Row│",
365− "└────────────────────────────┘",
365+// "└────────────────────────────┘",
369− // columns of large width just before pushing a column off
369+// // columns of large width just before pushing a column off
370− test_case(
370+// test_case(
372− Constraint::Percentage(33),
372+// Constraint::Percentage(33),
373− Constraint::Length(10),
373+// Constraint::Length(10),
374− Constraint::Percentage(33),
374+// Constraint::Percentage(33),
376− Buffer::with_lines(vec![
376+// Buffer::with_lines(vec![
377− "┌────────────────────────────┐",
377+// "┌────────────────────────────┐",
378− "│Head1 Head2 Head3 │",
378+// "│Head1 Head2 Head3 │",
380− "│Row11 Row12 Row13 │",
380+// "│Row11 Row12 Row13 │",
381− "│Row21 Row22 Row23 │",
381+// "│Row21 Row22 Row23 │",
382− "│Row31 Row32 Row33 │",
382+// "│Row31 Row32 Row33 │",
383− "│Row41 Row42 Row43 │",
383+// "│Row41 Row42 Row43 │",
386− "└────────────────────────────┘",
386+// "└────────────────────────────┘",
390− // columns of large size (>100% total) hide the last column
390+// // columns of large size (>100% total) hide the last column
391− test_case(
391+// test_case(
393− Constraint::Percentage(60),
393+// Constraint::Percentage(60),
394− Constraint::Length(10),
394+// Constraint::Length(10),
395− Constraint::Percentage(60),
395+// Constraint::Percentage(60),
397− Buffer::with_lines(vec![
397+// Buffer::with_lines(vec![
398− "┌────────────────────────────┐",
398+// "┌────────────────────────────┐",
399− "│Head1 Head2 │",
399+// "│Head1 Head2 │",
401− "│Row11 Row12 │",
401+// "│Row11 Row12 │",
402− "│Row21 Row22 │",
402+// "│Row21 Row22 │",
403− "│Row31 Row32 │",
403+// "│Row31 Row32 │",
404− "│Row41 Row42 │",
404+// "│Row41 Row42 │",
407− "└────────────────────────────┘",
407+// "└────────────────────────────┘",
412−#[test]
412+// #[test]
413−fn widgets_table_columns_widths_can_use_ratio_constraints() {
413+// fn widgets_table_columns_widths_can_use_ratio_constraints() {
414− let test_case = |widths, expected| {
414+// let test_case = |widths, expected| {
415− let backend = TestBackend::new(30, 10);
415+// let backend = TestBackend::new(30, 10);
416− let mut terminal = Terminal::new(backend).unwrap();
416+// let mut terminal = Terminal::new(backend).unwrap();
418− terminal
418+// terminal
419− .draw(|f| {
419+// .draw(|f| {
420− let size = f.size();
420+// let size = f.size();
421− let table = Table::new(vec![
421+// let table = Table::new(vec![
422− Row::new(vec!["Row11", "Row12", "Row13"]),
422+// Row::new(vec!["Row11", "Row12", "Row13"]),
423− Row::new(vec!["Row21", "Row22", "Row23"]),
423+// Row::new(vec!["Row21", "Row22", "Row23"]),
424− Row::new(vec!["Row31", "Row32", "Row33"]),
424+// Row::new(vec!["Row31", "Row32", "Row33"]),
425− Row::new(vec!["Row41", "Row42", "Row43"]),
425+// Row::new(vec!["Row41", "Row42", "Row43"]),
427− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
427+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
428− .block(Block::default().borders(Borders::ALL))
428+// .block(Block::default().borders(Borders::ALL))
429− .widths(widths)
429+// .widths(widths)
430− .column_spacing(0);
430+// .column_spacing(0);
431− f.render_widget(table, size);
431+// f.render_widget(table, size);
433− .unwrap();
433+// .unwrap();
434− terminal.backend().assert_buffer(&expected);
434+// terminal.backend().assert_buffer(&expected);
437− // columns of zero width show nothing
437+// // columns of zero width show nothing
438− test_case(
438+// test_case(
440− Constraint::Ratio(0, 1),
440+// Constraint::Ratio(0, 1),
441− Constraint::Ratio(0, 1),
441+// Constraint::Ratio(0, 1),
442− Constraint::Ratio(0, 1),
442+// Constraint::Ratio(0, 1),
444− Buffer::with_lines(vec![
444+// Buffer::with_lines(vec![
445− "┌────────────────────────────┐",
445+// "┌────────────────────────────┐",
454− "└────────────────────────────┘",
454+// "└────────────────────────────┘",
458− // columns of not enough width trims the data
458+// // columns of not enough width trims the data
459− test_case(
459+// test_case(
461− Constraint::Ratio(1, 9),
461+// Constraint::Ratio(1, 9),
462− Constraint::Ratio(1, 9),
462+// Constraint::Ratio(1, 9),
463− Constraint::Ratio(1, 9),
463+// Constraint::Ratio(1, 9),
465− Buffer::with_lines(vec![
465+// Buffer::with_lines(vec![
466− "┌────────────────────────────┐",
466+// "┌────────────────────────────┐",
467− "│HeaHeaHea │",
467+// "│HeaHeaHea │",
469− "│RowRowRow │",
469+// "│RowRowRow │",
470− "│RowRowRow │",
470+// "│RowRowRow │",
471− "│RowRowRow │",
471+// "│RowRowRow │",
472− "│RowRowRow │",
472+// "│RowRowRow │",
475− "└────────────────────────────┘",
475+// "└────────────────────────────┘",
479− // columns of large width just before pushing a column off
479+// // columns of large width just before pushing a column off
480− test_case(
480+// test_case(
482− Constraint::Ratio(1, 3),
482+// Constraint::Ratio(1, 3),
483− Constraint::Ratio(1, 3),
483+// Constraint::Ratio(1, 3),
484− Constraint::Ratio(1, 3),
484+// Constraint::Ratio(1, 3),
486− Buffer::with_lines(vec![
486+// Buffer::with_lines(vec![
487− "┌────────────────────────────┐",
487+// "┌────────────────────────────┐",
488− "│Head1 Head2 Head3 │",
488+// "│Head1 Head2 Head3 │",
490− "│Row11 Row12 Row13 │",
490+// "│Row11 Row12 Row13 │",
491− "│Row21 Row22 Row23 │",
491+// "│Row21 Row22 Row23 │",
492− "│Row31 Row32 Row33 │",
492+// "│Row31 Row32 Row33 │",
493− "│Row41 Row42 Row43 │",
493+// "│Row41 Row42 Row43 │",
496− "└────────────────────────────┘",
496+// "└────────────────────────────┘",
500− // percentages summing to 100 should give equal widths
500+// // percentages summing to 100 should give equal widths
501− test_case(
501+// test_case(
502− &[Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
502+// &[Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
503− Buffer::with_lines(vec![
503+// Buffer::with_lines(vec![
504− "┌────────────────────────────┐",
504+// "┌────────────────────────────┐",
505− "│Head1 Head2 │",
505+// "│Head1 Head2 │",
507− "│Row11 Row12 │",
507+// "│Row11 Row12 │",
508− "│Row21 Row22 │",
508+// "│Row21 Row22 │",
509− "│Row31 Row32 │",
509+// "│Row31 Row32 │",
510− "│Row41 Row42 │",
510+// "│Row41 Row42 │",
513− "└────────────────────────────┘",
513+// "└────────────────────────────┘",
518−#[test]
518+// #[test]
519−fn widgets_table_can_have_rows_with_multi_lines() {
519+// fn widgets_table_can_have_rows_with_multi_lines() {
520− let test_case = |state: &mut TableState, expected: Buffer| {
520+// let test_case = |state: &mut TableState, expected: Buffer| {
521− let backend = TestBackend::new(30, 8);
521+// let backend = TestBackend::new(30, 8);
522− let mut terminal = Terminal::new(backend).unwrap();
522+// let mut terminal = Terminal::new(backend).unwrap();
523− terminal
523+// terminal
524− .draw(|f| {
524+// .draw(|f| {
525− let size = f.size();
525+// let size = f.size();
526− let table = Table::new(vec![
526+// let table = Table::new(vec![
527− Row::new(vec!["Row11", "Row12", "Row13"]),
527+// Row::new(vec!["Row11", "Row12", "Row13"]),
528− Row::new(vec!["Row21", "Row22", "Row23"]).height(2),
528+// Row::new(vec!["Row21", "Row22", "Row23"]).height(2),
529− Row::new(vec!["Row31", "Row32", "Row33"]),
529+// Row::new(vec!["Row31", "Row32", "Row33"]),
530− Row::new(vec!["Row41", "Row42", "Row43"]).height(2),
530+// Row::new(vec!["Row41", "Row42", "Row43"]).height(2),
532− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
532+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
533− .block(Block::default().borders(Borders::ALL))
533+// .block(Block::default().borders(Borders::ALL))
534− .highlight_symbol(">> ")
534+// .highlight_symbol(">> ")
535− .widths(&[
535+// .widths(&[
536− Constraint::Length(5),
536+// Constraint::Length(5),
537− Constraint::Length(5),
537+// Constraint::Length(5),
538− Constraint::Length(5),
538+// Constraint::Length(5),
540− .column_spacing(1);
540+// .column_spacing(1);
541− f.render_stateful_widget(table, size, state);
541+// f.render_stateful_widget(table, size, state);
543− .unwrap();
543+// .unwrap();
544− terminal.backend().assert_buffer(&expected);
544+// terminal.backend().assert_buffer(&expected);
547− let mut state = TableState::default();
547+// let mut state = TableState::default();
548− // no selection
548+// // no selection
549− test_case(
549+// test_case(
550− &mut state,
550+// &mut state,
551− Buffer::with_lines(vec![
551+// Buffer::with_lines(vec![
552− "┌────────────────────────────┐",
552+// "┌────────────────────────────┐",
553− "│Head1 Head2 Head3 │",
553+// "│Head1 Head2 Head3 │",
555− "│Row11 Row12 Row13 │",
555+// "│Row11 Row12 Row13 │",
556− "│Row21 Row22 Row23 │",
556+// "│Row21 Row22 Row23 │",
558− "│Row31 Row32 Row33 │",
558+// "│Row31 Row32 Row33 │",
559− "└────────────────────────────┘",
559+// "└────────────────────────────┘",
563− // select first
563+// // select first
564− state.select(Some(0));
564+// state.select(Some(0));
565− test_case(
565+// test_case(
566− &mut state,
566+// &mut state,
567− Buffer::with_lines(vec![
567+// Buffer::with_lines(vec![
568− "┌────────────────────────────┐",
568+// "┌────────────────────────────┐",
569− "│ Head1 Head2 Head3 │",
569+// "│ Head1 Head2 Head3 │",
571− "│>> Row11 Row12 Row13 │",
571+// "│>> Row11 Row12 Row13 │",
572− "│ Row21 Row22 Row23 │",
572+// "│ Row21 Row22 Row23 │",
574− "│ Row31 Row32 Row33 │",
574+// "│ Row31 Row32 Row33 │",
575− "└────────────────────────────┘",
575+// "└────────────────────────────┘",
579− // select second (we don't show partially the 4th row)
579+// // select second (we don't show partially the 4th row)
580− state.select(Some(1));
580+// state.select(Some(1));
581− test_case(
581+// test_case(
582− &mut state,
582+// &mut state,
583− Buffer::with_lines(vec![
583+// Buffer::with_lines(vec![
584− "┌────────────────────────────┐",
584+// "┌────────────────────────────┐",
585− "│ Head1 Head2 Head3 │",
585+// "│ Head1 Head2 Head3 │",
587− "│ Row11 Row12 Row13 │",
587+// "│ Row11 Row12 Row13 │",
588− "│>> Row21 Row22 Row23 │",
588+// "│>> Row21 Row22 Row23 │",
590− "│ Row31 Row32 Row33 │",
590+// "│ Row31 Row32 Row33 │",
591− "└────────────────────────────┘",
591+// "└────────────────────────────┘",
595− // select 4th (we don't show partially the 1st row)
595+// // select 4th (we don't show partially the 1st row)
596− state.select(Some(3));
596+// state.select(Some(3));
597− test_case(
597+// test_case(
598− &mut state,
598+// &mut state,
599− Buffer::with_lines(vec![
599+// Buffer::with_lines(vec![
600− "┌────────────────────────────┐",
600+// "┌────────────────────────────┐",
601− "│ Head1 Head2 Head3 │",
601+// "│ Head1 Head2 Head3 │",
603− "│ Row31 Row32 Row33 │",
603+// "│ Row31 Row32 Row33 │",
604− "│>> Row41 Row42 Row43 │",
604+// "│>> Row41 Row42 Row43 │",
607− "└────────────────────────────┘",
607+// "└────────────────────────────┘",
612−#[test]
612+// #[test]
613−fn widgets_table_can_have_elements_styled_individually() {
613+// fn widgets_table_can_have_elements_styled_individually() {
614− let backend = TestBackend::new(30, 4);
614+// let backend = TestBackend::new(30, 4);
615− let mut terminal = Terminal::new(backend).unwrap();
615+// let mut terminal = Terminal::new(backend).unwrap();
616− let mut state = TableState::default();
616+// let mut state = TableState::default();
617− state.select(Some(0));
617+// state.select(Some(0));
618− terminal
618+// terminal
619− .draw(|f| {
619+// .draw(|f| {
620− let size = f.size();
620+// let size = f.size();
621− let table = Table::new(vec![
621+// let table = Table::new(vec![
622− Row::new(vec!["Row11", "Row12", "Row13"]).style(Style::default().fg(Color::Green)),
622+// Row::new(vec!["Row11", "Row12", "Row13"]).style(Style::default().fg(Color::Green)),
623− Row::new(vec![
623+// Row::new(vec![
624− Cell::from("Row21"),
624+// Cell::from("Row21"),
625− Cell::from("Row22").style(Style::default().fg(Color::Yellow)),
625+// Cell::from("Row22").style(Style::default().fg(Color::Yellow)),
626− Cell::from(Spans::from(vec![
626+// Cell::from(Spans::from(vec![
627− Span::raw("Row"),
627+// Span::raw("Row"),
628− Span::styled("23", Style::default().fg(Color::Blue)),
628+// Span::styled("23", Style::default().fg(Color::Blue)),
630− .style(Style::default().fg(Color::Red)),
630+// .style(Style::default().fg(Color::Red)),
632− .style(Style::default().fg(Color::LightGreen)),
632+// .style(Style::default().fg(Color::LightGreen)),
634− .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
634+// .header(Row::new(vec!["Head1", "Head2", "Head3"]).bottom_margin(1))
635− .block(Block::default().borders(Borders::LEFT | Borders::RIGHT))
635+// .block(Block::default().borders(Borders::LEFT | Borders::RIGHT))
636− .highlight_symbol(">> ")
636+// .highlight_symbol(">> ")
637− .highlight_style(Style::default().add_modifier(Modifier::BOLD))
637+// .highlight_style(Style::default().add_modifier(Modifier::BOLD))
638− .widths(&[
638+// .widths(&[
639− Constraint::Length(6),
639+// Constraint::Length(6),
640− Constraint::Length(6),
640+// Constraint::Length(6),
641− Constraint::Length(6),
641+// Constraint::Length(6),
643− .column_spacing(1);
643+// .column_spacing(1);
644− f.render_stateful_widget(table, size, &mut state);
644+// f.render_stateful_widget(table, size, &mut state);
646− .unwrap();
646+// .unwrap();
648− let mut expected = Buffer::with_lines(vec![
648+// let mut expected = Buffer::with_lines(vec![
649− "│ Head1 Head2 Head3 │",
649+// "│ Head1 Head2 Head3 │",
651− "│>> Row11 Row12 Row13 │",
651+// "│>> Row11 Row12 Row13 │",
652− "│ Row21 Row22 Row23 │",
652+// "│ Row21 Row22 Row23 │",
654− // First row = row color + highlight style
654+// // First row = row color + highlight style
655− for col in 1..=28 {
655+// for col in 1..=28 {
656− expected.get_mut(col, 2).set_style(
656+// expected.get_mut(col, 2).set_style(
657− Style::default()
657+// Style::default()
658− .fg(Color::Green)
658+// .fg(Color::Green)
659− .add_modifier(Modifier::BOLD),
659+// .add_modifier(Modifier::BOLD),
662− // Second row:
662+// // Second row:
663− // 1. row color
663+// // 1. row color
664− for col in 1..=28 {
664+// for col in 1..=28 {
665− expected
665+// expected
666− .get_mut(col, 3)
666+// .get_mut(col, 3)
667− .set_style(Style::default().fg(Color::LightGreen));
667+// .set_style(Style::default().fg(Color::LightGreen));
669− // 2. cell color
669+// // 2. cell color
670− for col in 11..=16 {
670+// for col in 11..=16 {
671− expected
671+// expected
672− .get_mut(col, 3)
672+// .get_mut(col, 3)
673− .set_style(Style::default().fg(Color::Yellow));
673+// .set_style(Style::default().fg(Color::Yellow));
675− for col in 18..=23 {
675+// for col in 18..=23 {
676− expected
676+// expected
677− .get_mut(col, 3)
677+// .get_mut(col, 3)
678− .set_style(Style::default().fg(Color::Red));
678+// .set_style(Style::default().fg(Color::Red));
680− // 3. text color
680+// // 3. text color
681− for col in 21..=22 {
681+// for col in 21..=22 {
682− expected
682+// expected
683− .get_mut(col, 3)
683+// .get_mut(col, 3)
684− .set_style(Style::default().fg(Color::Blue));
684+// .set_style(Style::default().fg(Color::Blue));
686− terminal.backend().assert_buffer(&expected);
686+// terminal.backend().assert_buffer(&expected);
689−#[test]
689+// #[test]
690−fn widgets_table_should_render_even_if_empty() {
690+// fn widgets_table_should_render_even_if_empty() {
691− let backend = TestBackend::new(30, 4);
691+// let backend = TestBackend::new(30, 4);
692− let mut terminal = Terminal::new(backend).unwrap();
692+// let mut terminal = Terminal::new(backend).unwrap();
693− terminal
693+// terminal
694− .draw(|f| {
694+// .draw(|f| {
695− let size = f.size();
695+// let size = f.size();
696− let table = Table::new(vec![])
696+// let table = Table::new(vec![])
697− .header(Row::new(vec!["Head1", "Head2", "Head3"]))
697+// .header(Row::new(vec!["Head1", "Head2", "Head3"]))
698− .block(Block::default().borders(Borders::LEFT | Borders::RIGHT))
698+// .block(Block::default().borders(Borders::LEFT | Borders::RIGHT))
699− .widths(&[
699+// .widths(&[
700− Constraint::Length(6),
700+// Constraint::Length(6),
701− Constraint::Length(6),
701+// Constraint::Length(6),
702− Constraint::Length(6),
702+// Constraint::Length(6),
704− .column_spacing(1);
704+// .column_spacing(1);
705− f.render_widget(table, size);
705+// f.render_widget(table, size);
707− .unwrap();
707+// .unwrap();
709− let expected = Buffer::with_lines(vec![
709+// let expected = Buffer::with_lines(vec![
710− "│Head1 Head2 Head3 │",
710+// "│Head1 Head2 Head3 │",
716− terminal.backend().assert_buffer(&expected);
716+// terminal.backend().assert_buffer(&expected);