From 08bfc0362899f9854497e18b0b3d8386a009f646 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 27 Jun 2024 22:22:46 +0200 Subject: [PATCH] refactor(cli::printing): use Option for blockfmt_advanced Users might just need the cell String, not a colored one. --- members/libpt-cli/src/printing.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/members/libpt-cli/src/printing.rs b/members/libpt-cli/src/printing.rs index 615b6e9..2298c33 100644 --- a/members/libpt-cli/src/printing.rs +++ b/members/libpt-cli/src/printing.rs @@ -42,10 +42,10 @@ pub fn blockprint(content: impl ToString, color: Color) { pub fn blockfmt(content: impl ToString, color: Color) -> String { blockfmt_advanced( content, - color, + Some(color), presets::UTF8_BORDERS_ONLY, ContentArrangement::DynamicFullWidth, - CellAlignment::Center + CellAlignment::Center, ) } @@ -67,7 +67,7 @@ pub fn blockfmt(content: impl ToString, color: Color) -> String { /// "{}", /// blockfmt_advanced( /// "Hello world!".to_string(), -/// Color::Blue, +/// Some(Color::Blue), /// presets::UTF8_FULL, /// ContentArrangement::DynamicFullWidth, /// CellAlignment::Center @@ -86,20 +86,20 @@ pub fn blockfmt(content: impl ToString, color: Color) -> String { /// pub fn blockfmt_advanced( content: impl ToString, - color: Color, + color: Option, preset: &str, arrangement: ContentArrangement, - alignment: CellAlignment + alignment: CellAlignment, ) -> String { let mut table = Table::new(); table .load_preset(preset) .set_content_arrangement(arrangement) .add_row(vec![content.to_string()]); - table - .column_mut(0) - .unwrap() - .set_cell_alignment(alignment); + table.column_mut(0).unwrap().set_cell_alignment(alignment); - format!("{}", style(table).fg(color)) + match color { + Some(c) => format!("{}", style(table).fg(c)), + None => table.to_string(), + } }