Skip to content

Commit

Permalink
Fix rendering of right border with irregular columns
Browse files Browse the repository at this point in the history
Closes #73.
  • Loading branch information
YS-L committed Apr 28, 2024
1 parent 56a71af commit 829937f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
26 changes: 26 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,32 @@ mod tests {
assert_eq!(lines, expected);
}

#[test]
fn test_extra_fields_right_most_border() {
let mut app = AppBuilder::new("tests/data/bad_73.csv").build().unwrap();
thread::sleep(time::Duration::from_millis(100));

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![
"───────────────────────────────────",
" COL1 COL2 ",
"───┬───────────────────┬───────────",
"1 │ c1 │ ",
"2 │ c2 v2 │ ",
"3 │ c2 4 │ ",
"4 │ c3 │ ",
"5 │ c4 │ ",
"───┴───────────────────┴───────────",
"stdin [Row 1/13, Col 1/2] ",
];
let actual_buffer = terminal.backend().buffer().clone();
let lines = to_lines(&actual_buffer);
assert_eq!(lines, expected);
}

#[test]
fn test_sniff_delimiter() {
let mut app = AppBuilder::new("tests/data/small.bsv")
Expand Down
10 changes: 4 additions & 6 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ impl<'a> CsvTable<'a> {
}
remaining_width = remaining_width.saturating_sub(hlen);
}
state.set_num_cols_rendered(num_cols_rendered);
state.num_cols_rendered = max(state.num_cols_rendered, num_cols_rendered);
state.set_more_cols_to_show(has_more_cols_to_show);
state.col_ending_pos_x = col_ending_pos_x;
state.col_ending_pos_x = max(state.col_ending_pos_x, col_ending_pos_x);
row_height
}

Expand Down Expand Up @@ -674,6 +674,8 @@ impl<'a> CsvTable<'a> {
state.enable_line_wrap,
state.is_word_wrap,
);
state.num_cols_rendered = 0;
state.col_ending_pos_x = 0;
// state.debug = format!("get_row_heights elapsed: {:?}", _tic.elapsed());
// state.debug = format!("row_heights: {:?}, area_height: {:?}", row_heights, area.height);
ViewLayout {
Expand Down Expand Up @@ -1099,10 +1101,6 @@ impl CsvTableState {
self.more_cols_to_show
}

fn set_num_cols_rendered(&mut self, n: u64) {
self.num_cols_rendered = n;
}

pub fn set_total_line_number(&mut self, n: usize, is_approx: bool) {
self.total_line_number = Some((n, is_approx));
}
Expand Down
14 changes: 14 additions & 0 deletions tests/data/bad_73.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
COL1, COL2
c1
c2, v2
c2, 4,
c3
c4
c5
c7
c9
c10
c11
c12
c13
c14,2

0 comments on commit 829937f

Please sign in to comment.