refactor: Migrate table display from prettytable to comfytable

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 17:57:38 -03:00
parent f9c4b709ad
commit 007f5e2377
2 changed files with 90 additions and 101 deletions

View File

@@ -43,27 +43,30 @@ use crate::modes::common::OutputFormat;
use crate::config;
use serde_json;
use serde_yaml;
use prettytable::row;
use prettytable::{Attr, Cell, Row, Table};
use prettytable::format::consts::{FORMAT_BOX_CHARS, FORMAT_NO_BORDER_LINE_SEPARATOR};
use comfytable::{ComfyTable, ContentArrangement, Row, Cell, Alignment};
use comfytable::presets::UTF8_FULL;
use comfytable::modifiers::UTF8_ROUND_CORNERS;
use crate::meta_plugin::{MetaPluginType, get_meta_plugin};
use crate::common::status::{MetaPluginInfo, CompressionInfo};
use prettytable::color;
fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String, MetaPluginInfo>) -> Table {
let mut meta_plugin_table = Table::new();
fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String, MetaPluginInfo>) -> ComfyTable {
let mut meta_plugin_table = ComfyTable::new();
if std::io::stdout().is_terminal() {
meta_plugin_table.set_format(*FORMAT_BOX_CHARS);
meta_plugin_table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS);
} else {
meta_plugin_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
meta_plugin_table.set_content_arrangement(ContentArrangement::Dynamic);
}
meta_plugin_table.set_titles(row!(
b->"Plugin Name",
b->"Options",
b->"Outputs"));
meta_plugin_table.set_header(vec![
Cell::new("Plugin Name").add_attribute(comfytable::Attribute::Bold),
Cell::new("Options").add_attribute(comfytable::Attribute::Bold),
Cell::new("Outputs").add_attribute(comfytable::Attribute::Bold),
]);
// Sort meta plugin info by plugin name
let mut sorted_meta_plugin_info: Vec<&MetaPluginInfo> = meta_plugin_info.values().collect();
@@ -107,67 +110,73 @@ fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String,
output_keys.join("\n")
};
meta_plugin_table.add_row(Row::new(vec![
Cell::new(&info.meta_name),
Cell::new(&options_str),
Cell::new(&outputs_display),
]));
meta_plugin_table.add_row(vec![
info.meta_name.clone(),
options_str,
outputs_display,
]);
}
meta_plugin_table
}
fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> Table {
let mut compression_table = Table::new();
fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> ComfyTable {
let mut compression_table = ComfyTable::new();
if std::io::stdout().is_terminal() {
compression_table.set_format(*FORMAT_BOX_CHARS);
compression_table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS);
} else {
compression_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
compression_table.set_content_arrangement(ContentArrangement::Dynamic);
}
compression_table.set_titles(row!(
b->"Type",
b->"Found",
b->"Enabled",
b->"Binary",
b->"Compress",
b->"Decompress"));
compression_table.set_header(vec![
Cell::new("Type").add_attribute(comfytable::Attribute::Bold),
Cell::new("Found").add_attribute(comfytable::Attribute::Bold),
Cell::new("Enabled").add_attribute(comfytable::Attribute::Bold),
Cell::new("Binary").add_attribute(comfytable::Attribute::Bold),
Cell::new("Compress").add_attribute(comfytable::Attribute::Bold),
Cell::new("Decompress").add_attribute(comfytable::Attribute::Bold),
]);
for info in compression_info {
compression_table.add_row(Row::new(vec![
Cell::new(&info.compression_type),
compression_table.add_row(vec![
info.compression_type.clone(),
match info.found {
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)),
true => Cell::new("Yes").fg(comfytable::Color::Green),
false => Cell::new("No").fg(comfytable::Color::Red),
},
match info.default {
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
true => Cell::new("Yes").fg(comfytable::Color::Green),
false => Cell::new("No"),
},
match info.binary.as_str() {
"<INTERNAL>" => Cell::new(&info.binary).with_style(Attr::ForegroundColor(color::BRIGHT_BLACK)),
"<INTERNAL>" => Cell::new(&info.binary).fg(comfytable::Color::DarkGrey),
_ => Cell::new(&info.binary),
},
Cell::new(&info.compress),
Cell::new(&info.decompress),
]));
info.compress.clone(),
info.decompress.clone(),
]);
}
compression_table
}
fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterPluginInfo>) -> Table {
let mut filter_plugin_table = Table::new();
fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterPluginInfo>) -> ComfyTable {
let mut filter_plugin_table = ComfyTable::new();
if std::io::stdout().is_terminal() {
filter_plugin_table.set_format(*FORMAT_BOX_CHARS);
filter_plugin_table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS);
} else {
filter_plugin_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
filter_plugin_table.set_content_arrangement(ContentArrangement::Dynamic);
}
filter_plugin_table.set_titles(row!(
b->"Plugin Name",
b->"Options",
b->"Description"));
filter_plugin_table.set_header(vec![
Cell::new("Plugin Name").add_attribute(comfytable::Attribute::Bold),
Cell::new("Options").add_attribute(comfytable::Attribute::Bold),
Cell::new("Description").add_attribute(comfytable::Attribute::Bold),
]);
// Sort plugins by name
let mut sorted_plugins: Vec<_> = filter_plugins.iter().collect();
@@ -243,20 +252,20 @@ fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterP
.to_string()
};
filter_plugin_table.add_row(Row::new(vec![
Cell::new(&plugin_info.name),
Cell::new(&options_str),
Cell::new(&plugin_info.description),
]));
filter_plugin_table.add_row(vec![
plugin_info.name.clone(),
options_str,
plugin_info.description.clone(),
]);
}
// If no filter plugins are available, add a row indicating that
if filter_plugins.is_empty() {
filter_plugin_table.add_row(Row::new(vec![
Cell::new("No filter plugins available"),
Cell::new("{}"),
Cell::new(""),
]));
filter_plugin_table.add_row(vec![
"No filter plugins available",
"{}",
"",
]);
}
filter_plugin_table