refactor: Unify table styling with comfy-table in status and list modes

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-08 18:07:58 -03:00
parent cba4566cdd
commit d7f4724f26
3 changed files with 36 additions and 32 deletions

View File

@@ -5,8 +5,9 @@ use crate::modes::common::ColumnType;
use crate::modes::common::{size_column, string_column, OutputFormat}; use crate::modes::common::{size_column, string_column, OutputFormat};
use anyhow::{Result}; use anyhow::{Result};
use log::debug; use log::debug;
use prettytable::format::Alignment; use comfy_table::{Table, ContentArrangement, Cell, Color, Attribute};
use prettytable::{color, row, Attr, Cell, Row, Table}; use comfy_table::presets::UTF8_FULL;
use comfy_table::modifiers::UTF8_ROUND_CORNERS;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json; use serde_json;
use serde_yaml; use serde_yaml;
@@ -60,15 +61,20 @@ pub fn mode_list(
debug!("Terminal width: {}", term_width); debug!("Terminal width: {}", term_width);
let mut table = Table::new(); let mut table = Table::new();
table.set_format(*prettytable::format::consts::FORMAT_CLEAN); if stdout().is_terminal() {
table
let mut title_row = row!(); .load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS);
for column in &settings.list_format { } else {
title_row.add_cell(Cell::new(&column.label).with_style(Attr::Bold)); table.set_content_arrangement(ContentArrangement::Dynamic);
} }
table.set_titles(title_row); // Create header row
let mut header_cells = Vec::new();
for column in &settings.list_format {
header_cells.push(Cell::new(&column.label).add_attribute(Attribute::Bold));
}
table.set_header(header_cells);
for item_with_meta in items_with_meta { for item_with_meta in items_with_meta {
let tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect(); let tags: Vec<String> = item_with_meta.tags.iter().map(|t| t.name.clone()).collect();

View File

@@ -9,10 +9,9 @@ use crate::config;
use crate::common::status::StatusInfo; use crate::common::status::StatusInfo;
use serde_json; use serde_json;
use serde_yaml; use serde_yaml;
use comfy_table::{Table, ContentArrangement, Cell, Color}; use comfy_table::{Table, ContentArrangement, Cell, Color, Attribute};
use comfy_table::presets::UTF8_FULL; use comfy_table::presets::UTF8_FULL;
use comfy_table::modifiers::UTF8_ROUND_CORNERS; use comfy_table::modifiers::UTF8_ROUND_CORNERS;
use comfy_table::TableComponent;
use crate::common::status::PathInfo; use crate::common::status::PathInfo;
use crate::meta_plugin::MetaPluginType; use crate::meta_plugin::MetaPluginType;
@@ -30,8 +29,8 @@ fn build_path_table(path_info: &PathInfo) -> Table {
} }
path_table.set_header(vec![ path_table.set_header(vec![
Cell::new("Type").add_attribute(comfy_table::Attribute::Bold), Cell::new("Type").add_attribute(Attribute::Bold),
Cell::new("Path").add_attribute(comfy_table::Attribute::Bold), Cell::new("Path").add_attribute(Attribute::Bold),
]); ]);
path_table.add_row(vec!["Data", &path_info.data]); path_table.add_row(vec!["Data", &path_info.data]);
@@ -52,8 +51,8 @@ fn build_config_table(settings: &config::Settings) -> Table {
} }
config_table.set_header(vec![ config_table.set_header(vec![
Cell::new("Setting").add_attribute(comfy_table::Attribute::Bold), Cell::new("Setting").add_attribute(Attribute::Bold),
Cell::new("Value").add_attribute(comfy_table::Attribute::Bold), Cell::new("Value").add_attribute(Attribute::Bold),
]); ]);
// Add relevant configuration settings // Add relevant configuration settings
@@ -92,9 +91,9 @@ fn build_meta_plugins_configured_table(status_info: &StatusInfo) -> Option<Table
} }
table.set_header(vec![ table.set_header(vec![
Cell::new("Plugin Name").add_attribute(comfy_table::Attribute::Bold), Cell::new("Plugin Name").add_attribute(Attribute::Bold),
Cell::new("Options").add_attribute(comfy_table::Attribute::Bold), Cell::new("Options").add_attribute(Attribute::Bold),
Cell::new("Outputs").add_attribute(comfy_table::Attribute::Bold), Cell::new("Outputs").add_attribute(Attribute::Bold),
]); ]);
for plugin_config in sorted_meta_plugins { for plugin_config in sorted_meta_plugins {

View File

@@ -43,10 +43,9 @@ use crate::modes::common::OutputFormat;
use crate::config; use crate::config;
use serde_json; use serde_json;
use serde_yaml; use serde_yaml;
use comfy_table::{Table, ContentArrangement, Cell, Color}; use comfy_table::{Table, ContentArrangement, Cell, Color, Attribute};
use comfy_table::presets::UTF8_FULL; use comfy_table::presets::UTF8_FULL;
use comfy_table::modifiers::UTF8_ROUND_CORNERS; use comfy_table::modifiers::UTF8_ROUND_CORNERS;
use comfy_table::TableComponent;
use crate::meta_plugin::{MetaPluginType, get_meta_plugin}; use crate::meta_plugin::{MetaPluginType, get_meta_plugin};
use crate::common::status::{MetaPluginInfo, CompressionInfo}; use crate::common::status::{MetaPluginInfo, CompressionInfo};
@@ -63,9 +62,9 @@ fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String,
} }
meta_plugin_table.set_header(vec![ meta_plugin_table.set_header(vec![
Cell::new("Plugin Name").add_attribute(comfy_table::Attribute::Bold), Cell::new("Plugin Name").add_attribute(Attribute::Bold),
Cell::new("Options").add_attribute(comfy_table::Attribute::Bold), Cell::new("Options").add_attribute(Attribute::Bold),
Cell::new("Outputs").add_attribute(comfy_table::Attribute::Bold), Cell::new("Outputs").add_attribute(Attribute::Bold),
]); ]);
// Sort meta plugin info by plugin name // Sort meta plugin info by plugin name
@@ -131,12 +130,12 @@ fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> Table {
} }
compression_table.set_header(vec![ compression_table.set_header(vec![
Cell::new("Type").add_attribute(comfy_table::Attribute::Bold), Cell::new("Type").add_attribute(Attribute::Bold),
Cell::new("Found").add_attribute(comfy_table::Attribute::Bold), Cell::new("Found").add_attribute(Attribute::Bold),
Cell::new("Enabled").add_attribute(comfy_table::Attribute::Bold), Cell::new("Enabled").add_attribute(Attribute::Bold),
Cell::new("Binary").add_attribute(comfy_table::Attribute::Bold), Cell::new("Binary").add_attribute(Attribute::Bold),
Cell::new("Compress").add_attribute(comfy_table::Attribute::Bold), Cell::new("Compress").add_attribute(Attribute::Bold),
Cell::new("Decompress").add_attribute(comfy_table::Attribute::Bold), Cell::new("Decompress").add_attribute(Attribute::Bold),
]); ]);
for info in compression_info { for info in compression_info {
@@ -173,9 +172,9 @@ fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterP
} }
filter_plugin_table.set_header(vec![ filter_plugin_table.set_header(vec![
Cell::new("Plugin Name").add_attribute(comfy_table::Attribute::Bold), Cell::new("Plugin Name").add_attribute(Attribute::Bold),
Cell::new("Options").add_attribute(comfy_table::Attribute::Bold), Cell::new("Options").add_attribute(Attribute::Bold),
Cell::new("Description").add_attribute(comfy_table::Attribute::Bold), Cell::new("Description").add_attribute(Attribute::Bold),
]); ]);
// Sort plugins by name // Sort plugins by name