From bf257b5ff324f98ade311183c109b64e807f6ecf Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 8 Sep 2025 18:19:10 -0300 Subject: [PATCH] refactor: Improve comfy_table usage and consistency Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/modes/info.rs | 13 ++++++------ src/modes/list.rs | 13 ++++++------ src/modes/status.rs | 40 +++++++++++++++++++------------------ src/modes/status_plugins.rs | 39 +++++++++++++++++++----------------- 4 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/modes/info.rs b/src/modes/info.rs index 0ada778..e3a333c 100644 --- a/src/modes/info.rs +++ b/src/modes/info.rs @@ -69,12 +69,13 @@ fn show_item( let item_tags: Vec = item_with_meta.tags.iter().map(|t| t.name.clone()).collect(); let mut table = Table::new(); - if std::io::stdout().is_terminal() { - table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - table.set_content_arrangement(ContentArrangement::Dynamic); + table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !std::io::stdout().is_terminal() { + table.force_no_tty(); } // Add all the rows diff --git a/src/modes/list.rs b/src/modes/list.rs index c0f56b4..7c28e26 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -62,12 +62,13 @@ pub fn mode_list( debug!("Terminal width: {}", term_width); let mut table = Table::new(); - if stdout().is_terminal() { - table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - table.set_content_arrangement(ContentArrangement::Dynamic); + table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !stdout().is_terminal() { + table.force_no_tty(); } // Create header row diff --git a/src/modes/status.rs b/src/modes/status.rs index 924b8af..324ff73 100644 --- a/src/modes/status.rs +++ b/src/modes/status.rs @@ -19,13 +19,13 @@ use crate::meta_plugin::get_meta_plugin; fn build_path_table(path_info: &PathInfo) -> Table { let mut path_table = Table::new(); - - if std::io::stdout().is_terminal() { - path_table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - path_table.set_content_arrangement(ContentArrangement::Dynamic); + path_table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !std::io::stdout().is_terminal() { + path_table.force_no_tty(); } path_table.set_header(vec![ @@ -42,12 +42,13 @@ fn build_path_table(path_info: &PathInfo) -> Table { fn build_config_table(settings: &config::Settings) -> Table { let mut config_table = Table::new(); - if std::io::stdout().is_terminal() { - config_table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - config_table.set_content_arrangement(ContentArrangement::Dynamic); + config_table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !std::io::stdout().is_terminal() { + config_table.force_no_tty(); } config_table.set_header(vec![ @@ -82,12 +83,13 @@ fn build_meta_plugins_configured_table(status_info: &StatusInfo) -> Option) -> Table { let mut meta_plugin_table = Table::new(); - if std::io::stdout().is_terminal() { - meta_plugin_table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - meta_plugin_table.set_content_arrangement(ContentArrangement::Dynamic); + meta_plugin_table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !std::io::stdout().is_terminal() { + meta_plugin_table.force_no_tty(); } meta_plugin_table.set_header(vec![ @@ -121,12 +122,13 @@ fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap) -> Table { let mut compression_table = Table::new(); - if std::io::stdout().is_terminal() { - compression_table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - compression_table.set_content_arrangement(ContentArrangement::Dynamic); + compression_table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !std::io::stdout().is_terminal() { + compression_table.force_no_tty(); } compression_table.set_header(vec![ @@ -160,12 +162,13 @@ fn build_compression_table(compression_info: &Vec) -> Table { fn build_filter_plugin_table(filter_plugins: &Vec) -> Table { let mut filter_plugin_table = Table::new(); - if std::io::stdout().is_terminal() { - filter_plugin_table - .load_preset(UTF8_FULL) - .apply_modifier(UTF8_ROUND_CORNERS); - } else { - filter_plugin_table.set_content_arrangement(ContentArrangement::Dynamic); + filter_plugin_table + .load_preset(UTF8_FULL) + .apply_modifier(UTF8_ROUND_CORNERS) + .set_content_arrangement(ContentArrangement::Dynamic); + + if !std::io::stdout().is_terminal() { + filter_plugin_table.force_no_tty(); } filter_plugin_table.set_header(vec![