Skip to content

Commit

Permalink
Reduce default value for maximum column width fraction
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Aug 27, 2023
1 parent c8ec7a7 commit 6e76e33
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 68 deletions.
134 changes: 67 additions & 67 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,21 +749,21 @@ mod tests {
.unwrap();
thread::sleep(time::Duration::from_millis(100));

let backend = TestBackend::new(30, 10);
let backend = TestBackend::new(35, 10);
let mut terminal = Terminal::new(backend).unwrap();

step_and_draw(&mut app, &mut terminal, Control::Nothing);
let expected = vec![
"──────────────────────────────",
" Column1 \"column… ",
"───┬──────────────────────────",
"1 │ 1 \"quote\" ",
"2 │ 5 \"Comma ",
" │ ",
" │ ",
" │ ",
"───┴──────────────────────────",
"stdin [Row 1/2, Col 1/2] ",
"───────────────────────────────────",
" Colum… \"col… ",
"───┬──────────────────────┬────────",
"1 │ 1 \"quo… │ ",
"2 │ 5 \"Com… │ ",
" │ ",
" │ ",
" │ ",
"───┴──────────────────────┴────────",
"stdin [Row 1/2, Col 1/2] ",
];
let actual_buffer = terminal.backend().buffer().clone();
let lines = to_lines(&actual_buffer);
Expand Down Expand Up @@ -823,34 +823,34 @@ mod tests {
step_and_draw(&mut app, &mut terminal, Control::Nothing);
let expected = vec![
"──────────────────────────────────────────────────",
" a b ",
"───┬─────────────────────────────────────────────",
"1 │ 1 this is a very long text that sure… ",
"2 │ 2 thi… ",
"3 │ 3 normal text now ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
"───┴─────────────────────────────────────────────",
" a b c ",
"───┬─────────────────────────────────────────────",
"1 │ 1 this is a … 12345 │ ",
"2 │ 2 thi… 678910 ",
"3 │ 3 normal tex… 123,456,789 ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
" │ ",
"───┴─────────────────────────────────────────────",
"stdin [Row 1/3, Col 1/3] ",
];
let actual_buffer = terminal.backend().buffer().clone();
Expand All @@ -860,34 +860,34 @@ mod tests {
step_and_draw(&mut app, &mut terminal, Control::ToggleLineWrap);
let expected = vec![
"──────────────────────────────────────────────────",
" a b ",
"───┬─────────────────────────────────────────────",
"1 │ 1 this is a very long text that surel ",
" │ y will not fit in your small screen ",
"2 2 this ",
" │ is ",
" │ an ",
" │ even ",
" │ longer ",
" text ",
" │ that ",
" │ surely ",
" │ will ",
" │ not ",
" │ fit ",
" │ in ",
" │ your ",
" │ small ",
" │ screen ",
"3 3 normal text now ",
" │ ",
" │ ",
" │ ",
" │ ",
" ",
" │ ",
" │ ",
"───┴─────────────────────────────────────────────",
" a b c ",
"───┬─────────────────────────────────────────────",
"1 │ 1 this is a v 12345 │ ",
" │ ery long te │ ",
" xt that sur ",
" │ ely will no ",
" │ t fit in yo ",
" │ ur small sc ",
" │ reen ",
"2 2 this 678910 ",
" │ is ",
" │ an ",
" │ even ",
" │ longer ",
" │ text ",
" │ that ",
" │ surely ",
" │ will ",
" │ not ",
" fit ",
" │ in ",
" │ your ",
" │ small ",
" │ screen ",
"3 3 normal text 123,456,789 ",
" │ now ",
" │ ",
"───┴─────────────────────────────────────────────",
"Line wrap enabled ",
];
let actual_buffer = terminal.backend().buffer().clone();
Expand Down
3 changes: 2 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tui::widgets::{Block, Borders, StatefulWidget};
use std::cmp::{max, min};

const NUM_SPACES_BETWEEN_COLUMNS: u16 = 4;
const MAX_COLUMN_WIDTH_FRACTION: f32 = 0.3;

#[derive(Debug)]
pub struct CsvTable<'a> {
Expand Down Expand Up @@ -54,7 +55,7 @@ impl<'a> CsvTable<'a> {
}
for w in &mut column_widths {
*w += NUM_SPACES_BETWEEN_COLUMNS;
*w = min(*w, (area_width as f32 * 0.8) as u16);
*w = min(*w, (area_width as f32 * MAX_COLUMN_WIDTH_FRACTION) as u16);
}
column_widths
}
Expand Down

0 comments on commit 6e76e33

Please sign in to comment.