refactor: Migrate from prettytable to comfy-table for output formatting

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 18:09:47 -03:00
parent d7f4724f26
commit 9f328a376f
5 changed files with 59 additions and 140 deletions

View File

@@ -5,9 +5,10 @@ use crate::modes::common::ColumnType;
use crate::modes::common::{size_column, string_column, OutputFormat};
use anyhow::{Result};
use log::debug;
use comfy_table::{Table, ContentArrangement, Cell, Color, Attribute};
use comfy_table::{Table, ContentArrangement, Cell, Row, Color, Attribute};
use comfy_table::presets::UTF8_FULL;
use comfy_table::modifiers::UTF8_ROUND_CORNERS;
use comfy_table::CellAlignment;
use serde::{Deserialize, Serialize};
use serde_json;
use serde_yaml;
@@ -84,7 +85,7 @@ pub fn mode_list(
let mut item_path = data_path.clone();
item_path.push(item.id.unwrap().to_string());
let mut table_row = Row::new(vec![]);
let mut table_row = Row::new();
for column in &settings.list_format {
let column_type = ColumnType::from_str(&column.name)
@@ -144,10 +145,10 @@ pub fn mode_list(
Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width));
match column.align {
crate::config::ColumnAlignment::Right => {
cell.align(Alignment::RIGHT);
cell = cell.alignment(CellAlignment::Right);
}
crate::config::ColumnAlignment::Left => {
cell.align(Alignment::LEFT);
cell = cell.alignment(CellAlignment::Left);
}
}
cell
@@ -190,11 +191,11 @@ pub fn mode_list(
None => {
let mut cell = match item_path.metadata() {
Ok(_) => Cell::new("Unknown")
.with_style(Attr::ForegroundColor(color::YELLOW))
.with_style(Attr::Bold),
.fg(Color::Yellow)
.add_attribute(Attribute::Bold),
Err(_) => Cell::new("Missing")
.with_style(Attr::ForegroundColor(color::RED))
.with_style(Attr::Bold),
.fg(Color::Red)
.add_attribute(Attribute::Bold),
};
match column.align {
crate::config::ColumnAlignment::Right => {
@@ -239,8 +240,8 @@ pub fn mode_list(
}
Err(_) => {
let mut cell = Cell::new("Missing")
.with_style(Attr::ForegroundColor(color::RED))
.with_style(Attr::Bold);
.fg(Color::Red)
.add_attribute(Attribute::Bold);
match column.align {
crate::config::ColumnAlignment::Right => {
cell.align(Alignment::RIGHT);
@@ -326,7 +327,7 @@ pub fn mode_list(
table.add_row(table_row);
}
table.printstd();
println!("{}", table);
Ok(())
}