fix: all tables respect table_config from settings
Extract shared render_item_info_table() and render_list_table() in modes/common.rs. Update client/info, client/list, client/status, info, status, and status_plugins to use create_table_with_config with settings.table_config instead of hardcoded presets. Previously only local --list used table_config; all other tables (client modes, status, status-plugins) ignored it.
This commit is contained in:
@@ -337,26 +337,8 @@ pub fn trim_lines_end(s: &str) -> String {
|
||||
/// let mut table = create_table(true);
|
||||
/// table.add_row(vec!["Header1", "Header2"]);
|
||||
/// ```
|
||||
pub fn create_table(use_styling: bool) -> Table {
|
||||
let mut table = Table::new();
|
||||
table.set_content_arrangement(ContentArrangement::Dynamic);
|
||||
|
||||
if use_styling {
|
||||
if std::io::stdout().is_terminal() {
|
||||
table
|
||||
.load_preset(comfy_table::presets::UTF8_FULL)
|
||||
.apply_modifier(comfy_table::modifiers::UTF8_SOLID_INNER_BORDERS);
|
||||
} else {
|
||||
table.load_preset(comfy_table::presets::ASCII_FULL);
|
||||
}
|
||||
} else {
|
||||
table.load_preset(comfy_table::presets::NOTHING);
|
||||
}
|
||||
|
||||
if !std::io::stdout().is_terminal() {
|
||||
table.force_no_tty();
|
||||
}
|
||||
table
|
||||
pub fn create_table(_use_styling: bool) -> Table {
|
||||
create_table_with_config(&crate::config::TableConfig::default())
|
||||
}
|
||||
|
||||
/// Creates a table configured from application table settings.
|
||||
@@ -447,3 +429,88 @@ pub fn create_table_with_config(table_config: &crate::config::TableConfig) -> Ta
|
||||
|
||||
table
|
||||
}
|
||||
|
||||
/// Display data for a single item's detail view (used by --info).
|
||||
pub struct DisplayItemInfo {
|
||||
pub id: i64,
|
||||
pub timestamp: String,
|
||||
pub path: String,
|
||||
pub stream_size: String,
|
||||
pub compression: String,
|
||||
pub file_size: String,
|
||||
pub tags: Vec<String>,
|
||||
pub metadata: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
/// Display data for a single list row (used by --list).
|
||||
pub struct DisplayListItem {
|
||||
pub id: i64,
|
||||
pub time: String,
|
||||
pub size: String,
|
||||
pub compression: String,
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
/// Renders item detail table. Shared by local and client info modes.
|
||||
pub fn render_item_info_table(info: &DisplayItemInfo, table_config: &config::TableConfig) {
|
||||
use comfy_table::{Attribute, Cell};
|
||||
|
||||
let mut table = create_table_with_config(table_config);
|
||||
|
||||
table.add_row(vec![
|
||||
Cell::new("ID").add_attribute(Attribute::Bold),
|
||||
Cell::new(info.id.to_string()),
|
||||
]);
|
||||
table.add_row(vec![
|
||||
Cell::new("Time").add_attribute(Attribute::Bold),
|
||||
Cell::new(&info.timestamp),
|
||||
]);
|
||||
table.add_row(vec![
|
||||
Cell::new("Size").add_attribute(Attribute::Bold),
|
||||
Cell::new(&info.stream_size),
|
||||
]);
|
||||
table.add_row(vec![
|
||||
Cell::new("Compression").add_attribute(Attribute::Bold),
|
||||
Cell::new(&info.compression),
|
||||
]);
|
||||
table.add_row(vec![
|
||||
Cell::new("Tags").add_attribute(Attribute::Bold),
|
||||
Cell::new(info.tags.join(" ")),
|
||||
]);
|
||||
|
||||
for (key, value) in &info.metadata {
|
||||
table.add_row(vec![
|
||||
Cell::new(format!("Meta: {key}")).add_attribute(Attribute::Bold),
|
||||
Cell::new(value),
|
||||
]);
|
||||
}
|
||||
|
||||
println!("{}", trim_lines_end(&table.trim_fmt()));
|
||||
}
|
||||
|
||||
/// Renders list table. Shared by local and client list modes.
|
||||
pub fn render_list_table(items: &[DisplayListItem], table_config: &config::TableConfig) {
|
||||
use comfy_table::{Attribute, Cell};
|
||||
|
||||
let mut table = create_table_with_config(table_config);
|
||||
|
||||
table.set_header(vec![
|
||||
Cell::new("ID").add_attribute(Attribute::Bold),
|
||||
Cell::new("Time").add_attribute(Attribute::Bold),
|
||||
Cell::new("Size").add_attribute(Attribute::Bold),
|
||||
Cell::new("Compression").add_attribute(Attribute::Bold),
|
||||
Cell::new("Tags").add_attribute(Attribute::Bold),
|
||||
]);
|
||||
|
||||
for item in items {
|
||||
table.add_row(vec![
|
||||
item.id.to_string(),
|
||||
item.time.clone(),
|
||||
item.size.clone(),
|
||||
item.compression.clone(),
|
||||
item.tags.join(" "),
|
||||
]);
|
||||
}
|
||||
|
||||
println!("{}", trim_lines_end(&table.trim_fmt()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user