feat: Add comprehensive table styling options

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 19:02:33 -03:00
parent c9c3e2eb7e
commit 0ab5c93845
3 changed files with 242 additions and 8 deletions

View File

@@ -27,6 +27,59 @@ struct ListItem {
meta: std::collections::HashMap<String, String>,
}
// Helper function to apply color to a cell
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
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
}
pub fn mode_list(
cmd: &mut clap::Command,
settings: &config::Settings,
@@ -52,14 +105,7 @@ pub fn mode_list(
return show_list_structured(items_with_meta, data_path, settings, output_format);
}
let mut table = Table::new();
table
.load_preset(NOTHING)
.set_content_arrangement(ContentArrangement::Dynamic);
if !stdout().is_terminal() {
table.force_no_tty();
}
let mut table = crate::modes::common::create_table_with_config(&settings.table_config);
// Create header row
let mut header_cells = Vec::new();
@@ -138,6 +184,25 @@ pub fn mode_list(
let mut cell = Cell::new(truncated_content);
// Apply column-specific styling
if let Some(fg_color) = &column.fg_color {
cell = apply_color(cell, fg_color, true);
}
if let Some(bg_color) = &column.bg_color {
cell = apply_color(cell, bg_color, false);
}
for attribute in &column.attributes {
cell = apply_attribute(cell, attribute);
}
// Apply padding if specified
if let Some((left_padding, right_padding)) = column.padding {
// Note: comfy-table doesn't directly support padding, so we'd need to handle this
// by adding spaces to the content, or use a different approach
}
// Apply styling for specific cases
match column_type {
ColumnType::Size => {