diff --git a/crates/nu-table/src/table.rs b/crates/nu-table/src/table.rs index 6c0336f029..d7222e673d 100644 --- a/crates/nu-table/src/table.rs +++ b/crates/nu-table/src/table.rs @@ -475,7 +475,8 @@ fn draw_table( truncate_table(&mut table, &t.config, width, termwidth); table_set_border_header(&mut table, head, &t.config); - table_to_string(table, termwidth) + let string = table.to_string(); + Some(string) } fn set_styles(table: &mut Table, styles: Styles, structure: &TableStructure) { @@ -531,18 +532,6 @@ fn set_indent(table: &mut Table, indent: TableIndent) { table.with(Padding::new(indent.left, indent.right, 0, 0)); } -fn table_to_string(table: Table, termwidth: usize) -> Option { - // Note: this is a "safe" path; presumable it must never happen cause we must made all the checks already - // TODO: maybe remove it? I think so? - let total_width = table.total_width(); - if total_width > termwidth { - None - } else { - let content = table.to_string(); - Some(content) - } -} - struct WidthCtrl { width: WidthEstimation, trim_strategy: TrimStrategy, @@ -915,7 +904,9 @@ fn truncate_columns_by_content( widths.push(trailing_column_width); width += trailing_column_width; - if widths.len() == 1 { + let has_only_trail = widths.len() == 1; + let is_enough_space = width <= termwidth; + if has_only_trail || !is_enough_space { // nothing to show anyhow return WidthEstimation::new(widths_original, vec![], width, false, true); }