mirror of
https://github.com/nushell/nushell.git
synced 2025-04-03 14:10:41 +02:00
fix[table]: Panic when passthru small number of table -w
. (#5705)
This commit is contained in:
parent
a75318d7e8
commit
cb909f810e
@ -503,6 +503,7 @@ pub fn draw_table(
|
|||||||
return format!("Couldn't fit table into {} columns!", termwidth);
|
return format!("Couldn't fit table into {} columns!", termwidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let raw_termwidth = termwidth;
|
||||||
let termwidth = termwidth - edges_width;
|
let termwidth = termwidth - edges_width;
|
||||||
|
|
||||||
let mut processed_table = process_table(table);
|
let mut processed_table = process_table(table);
|
||||||
@ -533,12 +534,15 @@ pub fn draw_table(
|
|||||||
let max_column_width = column_space.max_width(termwidth);
|
let max_column_width = column_space.max_width(termwidth);
|
||||||
|
|
||||||
// This width isn't quite right, as we're rounding off some of our space
|
// This width isn't quite right, as we're rounding off some of our space
|
||||||
let column_space = column_space.fix_almost_column_width(
|
let column_space = match max_column_width {
|
||||||
&max_per_column,
|
None => return format!("Couldn't fit table into {} columns!", raw_termwidth),
|
||||||
max_naive_column_width,
|
Some(max_column_width) => column_space.fix_almost_column_width(
|
||||||
max_column_width,
|
&max_per_column,
|
||||||
headers_len,
|
max_naive_column_width,
|
||||||
);
|
max_column_width,
|
||||||
|
headers_len,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
// This should give us the final max column width
|
// This should give us the final max column width
|
||||||
let max_column_width = column_space.max_width(termwidth);
|
let max_column_width = column_space.max_width(termwidth);
|
||||||
@ -547,13 +551,16 @@ pub fn draw_table(
|
|||||||
let re_trailing =
|
let re_trailing =
|
||||||
regex::Regex::new(r"(?P<endsp>\s+$)").expect("error with trailing space regex");
|
regex::Regex::new(r"(?P<endsp>\s+$)").expect("error with trailing space regex");
|
||||||
|
|
||||||
let wrapped_table = wrap_cells(
|
let wrapped_table = match max_column_width {
|
||||||
processed_table,
|
None => return format!("Couldn't fit table into {} columns!", raw_termwidth),
|
||||||
max_column_width,
|
Some(max_column_width) => wrap_cells(
|
||||||
color_hm,
|
processed_table,
|
||||||
&re_leading,
|
max_column_width,
|
||||||
&re_trailing,
|
color_hm,
|
||||||
);
|
&re_leading,
|
||||||
|
&re_trailing,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
wrapped_table.print_table(color_hm, config)
|
wrapped_table.print_table(color_hm, config)
|
||||||
}
|
}
|
||||||
@ -743,7 +750,7 @@ impl ColumnSpace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_width(&self, termwidth: usize) -> usize {
|
fn max_width(&self, termwidth: usize) -> Option<usize> {
|
||||||
let ColumnSpace {
|
let ColumnSpace {
|
||||||
num_overages,
|
num_overages,
|
||||||
underage_sum,
|
underage_sum,
|
||||||
@ -751,9 +758,13 @@ impl ColumnSpace {
|
|||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
if *num_overages > 0 {
|
if *num_overages > 0 {
|
||||||
(termwidth - 1 - *underage_sum - *overage_separator_sum) / *num_overages
|
termwidth
|
||||||
|
.checked_sub(1)?
|
||||||
|
.checked_sub(*underage_sum)?
|
||||||
|
.checked_sub(*overage_separator_sum)?
|
||||||
|
.checked_div(*num_overages)
|
||||||
} else {
|
} else {
|
||||||
99999
|
Some(99999)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user