Skip to content

Commit

Permalink
extracted tty styling to function
Browse files Browse the repository at this point in the history
Signed-off-by: roee88 <roee88@gmail.com>
  • Loading branch information
roee88 committed Aug 11, 2021
1 parent 58306c0 commit 39369ec
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/utils/formatting/content_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = String>,
) -> Vec<String> {
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.
Expand Down

0 comments on commit 39369ec

Please sign in to comment.