From 39369ec927cf41ba1a6eeeb2bd2e73607d6e21af Mon Sep 17 00:00:00 2001 From: roee88 Date: Wed, 11 Aug 2021 15:07:06 +0300 Subject: [PATCH] extracted tty styling to function Signed-off-by: roee88 --- src/utils/formatting/content_format.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/utils/formatting/content_format.rs b/src/utils/formatting/content_format.rs index 9d60bbe..9b03318 100644 --- a/src/utils/formatting/content_format.rs +++ b/src/utils/formatting/content_format.rs @@ -124,17 +124,27 @@ pub fn format_row( .iter() .map(|line| align_line(line.to_string(), info, cell)); - // Style the cell if necessary + // Apply tty styling for this cell. #[cfg(feature = "tty")] + let cell_lines = apply_tty_styling(table, cell, cell_lines).into_iter(); + + temp_row_content.push(cell_lines.collect()); + } + + #[cfg(feature = "tty")] + /// A small wrapper around the top-level cell styling logic. It's only used to have a clear + /// separation of our tty styling logic for the `tty` feature flag. + fn apply_tty_styling( + table: &Table, + cell: &Cell, + cell_lines: impl Iterator, + ) -> Vec { if table.should_style() { let cell_lines = cell_lines.map(|line| style_line(line, cell)); - temp_row_content.push(cell_lines.collect()); + cell_lines.collect() } else { - temp_row_content.push(cell_lines.collect()); + cell_lines.collect() } - - #[cfg(not(feature = "tty"))] - temp_row_content.push(cell_lines.collect()); } // Right now, we have a different structure than desired.