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

@@ -16,75 +16,55 @@ use crate::common::status::PathInfo;
use crate::meta_plugin::MetaPluginType;
use crate::meta_plugin::get_meta_plugin;
fn build_path_table(path_info: &PathInfo) -> Table {
let mut path_table = Table::new();
fn build_path_table(path_info: &PathInfo) -> ComfyTable {
let mut path_table = ComfyTable::new();
if std::io::stdout().is_terminal() {
path_table.set_format(get_format_box_chars_no_border_line_separator());
path_table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS);
} else {
path_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
path_table.set_content_arrangement(ContentArrangement::Dynamic);
}
path_table.set_titles(Row::new(vec![
Cell::new("Type").with_style(Attr::Bold),
Cell::new("Path").with_style(Attr::Bold),
]));
path_table.set_header(vec![
Cell::new("Type").add_attribute(comfytable::Attribute::Bold),
Cell::new("Path").add_attribute(comfytable::Attribute::Bold),
]);
path_table.add_row(Row::new(vec![
Cell::new("Data"),
Cell::new(&path_info.data),
]));
path_table.add_row(Row::new(vec![
Cell::new("Database"),
Cell::new(&path_info.database),
]));
path_table.add_row(vec!["Data", &path_info.data]);
path_table.add_row(vec!["Database", &path_info.database]);
path_table
}
fn build_config_table(settings: &config::Settings) -> Table {
let mut config_table = Table::new();
fn build_config_table(settings: &config::Settings) -> ComfyTable {
let mut config_table = ComfyTable::new();
if std::io::stdout().is_terminal() {
config_table.set_format(get_format_box_chars_no_border_line_separator());
config_table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS);
} else {
config_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
config_table.set_content_arrangement(ContentArrangement::Dynamic);
}
config_table.set_titles(Row::new(vec![
Cell::new("Setting").with_style(Attr::Bold),
Cell::new("Value").with_style(Attr::Bold),
]));
config_table.set_header(vec![
Cell::new("Setting").add_attribute(comfytable::Attribute::Bold),
Cell::new("Value").add_attribute(comfytable::Attribute::Bold),
]);
// Add relevant configuration settings
config_table.add_row(Row::new(vec![
Cell::new("Directory"),
Cell::new(&settings.dir.to_string_lossy()),
]));
config_table.add_row(Row::new(vec![
Cell::new("Human Readable"),
Cell::new(&settings.human_readable.to_string()),
]));
config_table.add_row(Row::new(vec![
Cell::new("Quiet"),
Cell::new(&settings.quiet.to_string()),
]));
config_table.add_row(vec!["Directory", &settings.dir.to_string_lossy()]);
config_table.add_row(vec!["Human Readable", &settings.human_readable.to_string()]);
config_table.add_row(vec!["Quiet", &settings.quiet.to_string()]);
if let Some(output_format) = &settings.output_format {
config_table.add_row(Row::new(vec![
Cell::new("Output Format"),
Cell::new(output_format),
]));
config_table.add_row(vec!["Output Format", output_format]);
}
if let Some(compression) = settings.compression() {
config_table.add_row(Row::new(vec![
Cell::new("Compression"),
Cell::new(&compression),
]));
config_table.add_row(vec!["Compression", &compression]);
}
config_table

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