Consider space for single ... column not enough space (#6080)

* nu-table: Refactoring

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>

* nu-table: consider space for single `...` column not enough space

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt
2022-07-19 20:35:25 +03:00
committed by GitHub
parent b4a7e7e6e9
commit e5684bc34c
4 changed files with 43 additions and 134 deletions

View File

@ -16,4 +16,4 @@ nu-ansi-term = "0.46.0"
nu-protocol = { path = "../nu-protocol", version = "0.65.1" }
strip-ansi-escapes = "0.1.1"
atty = "0.2.14"
tabled = { git = "https://github.com/zhiburt/tabled", rev = "5ac9aa53196cd5bbf570daa5357a76aa238722c1", features = ["color"] }
tabled = { git = "https://github.com/zhiburt/tabled", rev = "f24b945bdd3a1152d52561b70b0c88c2581ac5ff", features = ["color"] }

View File

@ -86,7 +86,10 @@ fn draw_table(
let count_columns = table_fix_lengths(headers.as_mut(), &mut data);
maybe_truncate_columns(&mut headers, &mut data, count_columns, termwidth);
let is_empty = maybe_truncate_columns(&mut headers, &mut data, count_columns, termwidth);
if is_empty {
return None;
}
let table_data = &table.data;
let theme = &table.theme;
@ -295,33 +298,9 @@ impl TableOption for FooterStyle {
return;
}
let mut line = papergrid::Line::default();
let border = grid.get_border((0, 0));
line.left = border.left_bottom_corner;
line.intersection = border.right_bottom_corner;
line.horizontal = border.bottom;
let border = grid.get_border((0, grid.count_columns() - 1));
line.right = border.right_bottom_corner;
grid.set_split_line(grid.count_rows() - 1, line);
}
}
struct RemoveHeaderLine;
impl TableOption for RemoveHeaderLine {
fn change(&mut self, grid: &mut papergrid::Grid) {
grid.set_split_line(1, papergrid::Line::default());
}
}
struct CountColumns(usize);
impl TableOption for &mut CountColumns {
fn change(&mut self, grid: &mut papergrid::Grid) {
self.0 = grid.count_columns();
if let Some(line) = grid.get_split_line(1) {
grid.set_split_line(grid.count_rows() - 1, line.clone());
}
}
}

View File

@ -3,9 +3,12 @@ pub(crate) fn maybe_truncate_columns(
data: &mut [Vec<String>],
length: usize,
termwidth: usize,
) {
) -> bool {
// Make sure we have enough space for the columns we have
let max_num_of_columns = termwidth / 10;
if max_num_of_columns == 0 {
return true;
}
// If we have too many columns, truncate the table
if let Some(headers) = headers {
@ -21,4 +24,6 @@ pub(crate) fn maybe_truncate_columns(
entry.push(String::from("..."));
}
}
false
}