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:
@@ -16,75 +16,55 @@ use crate::common::status::PathInfo;
|
|||||||
use crate::meta_plugin::MetaPluginType;
|
use crate::meta_plugin::MetaPluginType;
|
||||||
use crate::meta_plugin::get_meta_plugin;
|
use crate::meta_plugin::get_meta_plugin;
|
||||||
|
|
||||||
fn build_path_table(path_info: &PathInfo) -> Table {
|
fn build_path_table(path_info: &PathInfo) -> ComfyTable {
|
||||||
let mut path_table = Table::new();
|
let mut path_table = ComfyTable::new();
|
||||||
|
|
||||||
if std::io::stdout().is_terminal() {
|
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 {
|
} else {
|
||||||
path_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
|
path_table.set_content_arrangement(ContentArrangement::Dynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
path_table.set_titles(Row::new(vec![
|
path_table.set_header(vec![
|
||||||
Cell::new("Type").with_style(Attr::Bold),
|
Cell::new("Type").add_attribute(comfytable::Attribute::Bold),
|
||||||
Cell::new("Path").with_style(Attr::Bold),
|
Cell::new("Path").add_attribute(comfytable::Attribute::Bold),
|
||||||
]));
|
]);
|
||||||
|
|
||||||
path_table.add_row(Row::new(vec![
|
path_table.add_row(vec!["Data", &path_info.data]);
|
||||||
Cell::new("Data"),
|
path_table.add_row(vec!["Database", &path_info.database]);
|
||||||
Cell::new(&path_info.data),
|
|
||||||
]));
|
|
||||||
|
|
||||||
path_table.add_row(Row::new(vec![
|
|
||||||
Cell::new("Database"),
|
|
||||||
Cell::new(&path_info.database),
|
|
||||||
]));
|
|
||||||
|
|
||||||
path_table
|
path_table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn build_config_table(settings: &config::Settings) -> Table {
|
fn build_config_table(settings: &config::Settings) -> ComfyTable {
|
||||||
let mut config_table = Table::new();
|
let mut config_table = ComfyTable::new();
|
||||||
if std::io::stdout().is_terminal() {
|
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 {
|
} else {
|
||||||
config_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
|
config_table.set_content_arrangement(ContentArrangement::Dynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
config_table.set_titles(Row::new(vec![
|
config_table.set_header(vec![
|
||||||
Cell::new("Setting").with_style(Attr::Bold),
|
Cell::new("Setting").add_attribute(comfytable::Attribute::Bold),
|
||||||
Cell::new("Value").with_style(Attr::Bold),
|
Cell::new("Value").add_attribute(comfytable::Attribute::Bold),
|
||||||
]));
|
]);
|
||||||
|
|
||||||
// Add relevant configuration settings
|
// Add relevant configuration settings
|
||||||
config_table.add_row(Row::new(vec![
|
config_table.add_row(vec!["Directory", &settings.dir.to_string_lossy()]);
|
||||||
Cell::new("Directory"),
|
config_table.add_row(vec!["Human Readable", &settings.human_readable.to_string()]);
|
||||||
Cell::new(&settings.dir.to_string_lossy()),
|
config_table.add_row(vec!["Quiet", &settings.quiet.to_string()]);
|
||||||
]));
|
|
||||||
|
|
||||||
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()),
|
|
||||||
]));
|
|
||||||
|
|
||||||
if let Some(output_format) = &settings.output_format {
|
if let Some(output_format) = &settings.output_format {
|
||||||
config_table.add_row(Row::new(vec![
|
config_table.add_row(vec!["Output Format", output_format]);
|
||||||
Cell::new("Output Format"),
|
|
||||||
Cell::new(output_format),
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(compression) = settings.compression() {
|
if let Some(compression) = settings.compression() {
|
||||||
config_table.add_row(Row::new(vec![
|
config_table.add_row(vec!["Compression", &compression]);
|
||||||
Cell::new("Compression"),
|
|
||||||
Cell::new(&compression),
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config_table
|
config_table
|
||||||
|
|||||||
@@ -43,27 +43,30 @@ use crate::modes::common::OutputFormat;
|
|||||||
use crate::config;
|
use crate::config;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_yaml;
|
use serde_yaml;
|
||||||
use prettytable::row;
|
use comfytable::{ComfyTable, ContentArrangement, Row, Cell, Alignment};
|
||||||
use prettytable::{Attr, Cell, Row, Table};
|
use comfytable::presets::UTF8_FULL;
|
||||||
use prettytable::format::consts::{FORMAT_BOX_CHARS, FORMAT_NO_BORDER_LINE_SEPARATOR};
|
use comfytable::modifiers::UTF8_ROUND_CORNERS;
|
||||||
|
|
||||||
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};
|
||||||
use prettytable::color;
|
use prettytable::color;
|
||||||
|
|
||||||
|
|
||||||
fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String, MetaPluginInfo>) -> Table {
|
fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String, MetaPluginInfo>) -> ComfyTable {
|
||||||
let mut meta_plugin_table = Table::new();
|
let mut meta_plugin_table = ComfyTable::new();
|
||||||
if std::io::stdout().is_terminal() {
|
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 {
|
} 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!(
|
meta_plugin_table.set_header(vec![
|
||||||
b->"Plugin Name",
|
Cell::new("Plugin Name").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Options",
|
Cell::new("Options").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Outputs"));
|
Cell::new("Outputs").add_attribute(comfytable::Attribute::Bold),
|
||||||
|
]);
|
||||||
|
|
||||||
// Sort meta plugin info by plugin name
|
// Sort meta plugin info by plugin name
|
||||||
let mut sorted_meta_plugin_info: Vec<&MetaPluginInfo> = meta_plugin_info.values().collect();
|
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")
|
output_keys.join("\n")
|
||||||
};
|
};
|
||||||
|
|
||||||
meta_plugin_table.add_row(Row::new(vec![
|
meta_plugin_table.add_row(vec![
|
||||||
Cell::new(&info.meta_name),
|
info.meta_name.clone(),
|
||||||
Cell::new(&options_str),
|
options_str,
|
||||||
Cell::new(&outputs_display),
|
outputs_display,
|
||||||
]));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
meta_plugin_table
|
meta_plugin_table
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> Table {
|
fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> ComfyTable {
|
||||||
let mut compression_table = Table::new();
|
let mut compression_table = ComfyTable::new();
|
||||||
if std::io::stdout().is_terminal() {
|
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 {
|
} else {
|
||||||
compression_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
|
compression_table.set_content_arrangement(ContentArrangement::Dynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
compression_table.set_titles(row!(
|
compression_table.set_header(vec![
|
||||||
b->"Type",
|
Cell::new("Type").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Found",
|
Cell::new("Found").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Enabled",
|
Cell::new("Enabled").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Binary",
|
Cell::new("Binary").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Compress",
|
Cell::new("Compress").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Decompress"));
|
Cell::new("Decompress").add_attribute(comfytable::Attribute::Bold),
|
||||||
|
]);
|
||||||
|
|
||||||
for info in compression_info {
|
for info in compression_info {
|
||||||
compression_table.add_row(Row::new(vec![
|
compression_table.add_row(vec![
|
||||||
Cell::new(&info.compression_type),
|
info.compression_type.clone(),
|
||||||
match info.found {
|
match info.found {
|
||||||
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
|
true => Cell::new("Yes").fg(comfytable::Color::Green),
|
||||||
false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)),
|
false => Cell::new("No").fg(comfytable::Color::Red),
|
||||||
},
|
},
|
||||||
match info.default {
|
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"),
|
false => Cell::new("No"),
|
||||||
},
|
},
|
||||||
match info.binary.as_str() {
|
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.binary),
|
||||||
},
|
},
|
||||||
Cell::new(&info.compress),
|
info.compress.clone(),
|
||||||
Cell::new(&info.decompress),
|
info.decompress.clone(),
|
||||||
]));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
compression_table
|
compression_table
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterPluginInfo>) -> Table {
|
fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterPluginInfo>) -> ComfyTable {
|
||||||
let mut filter_plugin_table = Table::new();
|
let mut filter_plugin_table = ComfyTable::new();
|
||||||
if std::io::stdout().is_terminal() {
|
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 {
|
} 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!(
|
filter_plugin_table.set_header(vec![
|
||||||
b->"Plugin Name",
|
Cell::new("Plugin Name").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Options",
|
Cell::new("Options").add_attribute(comfytable::Attribute::Bold),
|
||||||
b->"Description"));
|
Cell::new("Description").add_attribute(comfytable::Attribute::Bold),
|
||||||
|
]);
|
||||||
|
|
||||||
// Sort plugins by name
|
// Sort plugins by name
|
||||||
let mut sorted_plugins: Vec<_> = filter_plugins.iter().collect();
|
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()
|
.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
filter_plugin_table.add_row(Row::new(vec![
|
filter_plugin_table.add_row(vec![
|
||||||
Cell::new(&plugin_info.name),
|
plugin_info.name.clone(),
|
||||||
Cell::new(&options_str),
|
options_str,
|
||||||
Cell::new(&plugin_info.description),
|
plugin_info.description.clone(),
|
||||||
]));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no filter plugins are available, add a row indicating that
|
// If no filter plugins are available, add a row indicating that
|
||||||
if filter_plugins.is_empty() {
|
if filter_plugins.is_empty() {
|
||||||
filter_plugin_table.add_row(Row::new(vec![
|
filter_plugin_table.add_row(vec![
|
||||||
Cell::new("No filter plugins available"),
|
"No filter plugins available",
|
||||||
Cell::new("{}"),
|
"{}",
|
||||||
Cell::new(""),
|
"",
|
||||||
]));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
filter_plugin_table
|
filter_plugin_table
|
||||||
|
|||||||
Reference in New Issue
Block a user