fix: client --list uses list_format from config like local mode
Move apply_color/apply_table_attribute to common.rs for sharing. Add render_list_table_with_format() that takes ColumnConfig slice and pre-computed row values. Client list now renders columns based on settings.list_format, showing empty for columns where server data is unavailable (e.g. text_line_count, token_count).
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
/// including table, JSON, and YAML.
|
||||
use crate::config;
|
||||
use crate::modes::common::ColumnType;
|
||||
use crate::modes::common::{OutputFormat, format_size};
|
||||
use crate::modes::common::{OutputFormat, apply_color, apply_table_attribute, format_size};
|
||||
use crate::services::item_service::ItemService;
|
||||
use crate::services::types::ItemWithMeta;
|
||||
use anyhow::{Context, Result};
|
||||
@@ -63,88 +63,6 @@ struct ListItem {
|
||||
meta: std::collections::HashMap<String, String>,
|
||||
}
|
||||
|
||||
// Helper function to apply color to a cell.
|
||||
///
|
||||
/// This function converts the configuration color to a comfy-table Color and
|
||||
/// applies it to the cell as foreground or background color.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `cell` - The cell to modify.
|
||||
/// * `color` - The color from configuration to apply.
|
||||
/// * `is_foreground` - True for foreground color, false for background.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The modified cell with color applied.
|
||||
fn apply_color(mut cell: Cell, color: &crate::config::TableColor, is_foreground: bool) -> Cell {
|
||||
use crate::config::TableColor::*;
|
||||
use comfy_table::Color;
|
||||
|
||||
let comfy_color = match color {
|
||||
Black => Color::Black,
|
||||
Red => Color::Red,
|
||||
Green => Color::Green,
|
||||
Yellow => Color::Yellow,
|
||||
Blue => Color::Blue,
|
||||
Magenta => Color::Magenta,
|
||||
Cyan => Color::Cyan,
|
||||
White => Color::White,
|
||||
Gray => Color::Grey,
|
||||
DarkRed => Color::DarkRed,
|
||||
DarkGreen => Color::DarkGreen,
|
||||
DarkYellow => Color::DarkYellow,
|
||||
DarkBlue => Color::DarkBlue,
|
||||
DarkMagenta => Color::DarkMagenta,
|
||||
DarkCyan => Color::DarkCyan,
|
||||
Rgb(r, g, b) => Color::Rgb {
|
||||
r: *r,
|
||||
g: *g,
|
||||
b: *b,
|
||||
},
|
||||
};
|
||||
|
||||
if is_foreground {
|
||||
cell = cell.fg(comfy_color);
|
||||
} else {
|
||||
cell = cell.bg(comfy_color);
|
||||
}
|
||||
|
||||
cell
|
||||
}
|
||||
|
||||
// Helper function to apply attribute to a cell.
|
||||
///
|
||||
/// This function applies a single table attribute to the cell based on the
|
||||
/// configuration attribute type.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `cell` - The cell to modify.
|
||||
/// * `attribute` - The attribute from configuration to apply.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The modified cell with attribute applied.
|
||||
fn apply_attribute(mut cell: Cell, attribute: &crate::config::TableAttribute) -> Cell {
|
||||
use crate::config::TableAttribute::*;
|
||||
use comfy_table::Attribute;
|
||||
|
||||
match attribute {
|
||||
Bold => cell = cell.add_attribute(Attribute::Bold),
|
||||
Dim => cell = cell.add_attribute(Attribute::Dim),
|
||||
Italic => cell = cell.add_attribute(Attribute::Italic),
|
||||
Underlined => cell = cell.add_attribute(Attribute::Underlined),
|
||||
SlowBlink => cell = cell.add_attribute(Attribute::SlowBlink),
|
||||
RapidBlink => cell = cell.add_attribute(Attribute::RapidBlink),
|
||||
Reverse => cell = cell.add_attribute(Attribute::Reverse),
|
||||
Hidden => cell = cell.add_attribute(Attribute::Hidden),
|
||||
CrossedOut => cell = cell.add_attribute(Attribute::CrossedOut),
|
||||
}
|
||||
|
||||
cell
|
||||
}
|
||||
|
||||
/// Main list mode function.
|
||||
///
|
||||
/// This function handles the listing of items based on tags, applying formatting
|
||||
@@ -287,7 +205,7 @@ pub fn mode_list(
|
||||
}
|
||||
|
||||
for attribute in &column.attributes {
|
||||
cell = apply_attribute(cell, attribute);
|
||||
cell = apply_table_attribute(cell, attribute);
|
||||
}
|
||||
|
||||
// Apply padding if specified
|
||||
|
||||
Reference in New Issue
Block a user