feat[table]: Allow specific table width with -w, like command grid. (#5643)

This commit is contained in:
Vanilla
2022-05-26 19:53:05 +08:00
committed by GitHub
parent 3d62528d8c
commit 727ff5f2d4
2 changed files with 33 additions and 16 deletions

View File

@ -491,14 +491,20 @@ pub fn draw_table(
config: &Config,
) -> String {
// Remove the edges, if used
let termwidth = if table.theme.print_left_border && table.theme.print_right_border {
termwidth - 3
let edges_width = if table.theme.print_left_border && table.theme.print_right_border {
3
} else if table.theme.print_left_border || table.theme.print_right_border {
termwidth - 1
1
} else {
termwidth
0
};
if termwidth < edges_width {
return format!("Couldn't fit table into {} columns!", termwidth);
}
let termwidth = termwidth - edges_width;
let mut processed_table = process_table(table);
let max_per_column = get_max_column_widths(&processed_table);