refactor: Consolidate cell alignment logic in modes::list
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -91,182 +91,56 @@ pub fn mode_list(
|
||||
}
|
||||
}
|
||||
|
||||
let cell = match column_type {
|
||||
ColumnType::Id => {
|
||||
let mut cell = Cell::new(item.id.unwrap_or(0).to_string());
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
ColumnType::Time => {
|
||||
let mut cell = Cell::new(
|
||||
let mut cell = match column_type {
|
||||
ColumnType::Id => Cell::new(item.id.unwrap_or(0).to_string()),
|
||||
ColumnType::Time => Cell::new(
|
||||
item.ts
|
||||
.with_timezone(&chrono::Local)
|
||||
.format("%F %T")
|
||||
.to_string(),
|
||||
);
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
),
|
||||
ColumnType::Size => match item.size {
|
||||
Some(size) => {
|
||||
let mut cell = Cell::new(format_size(
|
||||
Some(size) => Cell::new(format_size(
|
||||
size as u64,
|
||||
settings.human_readable,
|
||||
));
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
None => {
|
||||
let mut cell = match item_path.metadata() {
|
||||
)),
|
||||
None => match item_path.metadata() {
|
||||
Ok(_) => Cell::new("Unknown")
|
||||
.fg(Color::Yellow)
|
||||
.add_attribute(Attribute::Bold),
|
||||
Err(_) => Cell::new("Missing")
|
||||
.fg(Color::Red)
|
||||
.add_attribute(Attribute::Bold),
|
||||
};
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
},
|
||||
ColumnType::Compression => {
|
||||
let mut cell = Cell::new(item.compression.to_string());
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
},
|
||||
ColumnType::Compression => Cell::new(item.compression.to_string()),
|
||||
ColumnType::FileSize => match item_path.metadata() {
|
||||
Ok(metadata) => {
|
||||
let mut cell = Cell::new(format_size(
|
||||
Ok(metadata) => Cell::new(format_size(
|
||||
metadata.len(),
|
||||
settings.human_readable,
|
||||
));
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
Err(_) => {
|
||||
let mut cell = Cell::new("Missing")
|
||||
)),
|
||||
Err(_) => Cell::new("Missing")
|
||||
.fg(Color::Red)
|
||||
.add_attribute(Attribute::Bold);
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
.add_attribute(Attribute::Bold),
|
||||
},
|
||||
ColumnType::FilePath => {
|
||||
let mut cell = Cell::new(
|
||||
ColumnType::FilePath => Cell::new(
|
||||
item_path.clone().into_os_string().into_string().unwrap(),
|
||||
);
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
ColumnType::Tags => {
|
||||
let mut cell = Cell::new(tags.join(" "));
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
),
|
||||
ColumnType::Tags => Cell::new(tags.join(" ")),
|
||||
ColumnType::Meta => match meta_name {
|
||||
Some(meta_name) => match meta.get(meta_name) {
|
||||
Some(meta_value) => {
|
||||
let mut cell = Cell::new(meta_value.to_string());
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
None => {
|
||||
let mut cell = Cell::new("");
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
Some(meta_value) => Cell::new(meta_value.to_string()),
|
||||
None => Cell::new(""),
|
||||
},
|
||||
None => {
|
||||
let mut cell = Cell::new("");
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
}
|
||||
crate::config::ColumnAlignment::Left => {
|
||||
cell = cell.set_alignment(CellAlignment::Left);
|
||||
}
|
||||
}
|
||||
cell
|
||||
}
|
||||
None => Cell::new(""),
|
||||
},
|
||||
};
|
||||
|
||||
// Apply alignment in one place
|
||||
cell = match column.align {
|
||||
crate::config::ColumnAlignment::Right => cell.set_alignment(CellAlignment::Right),
|
||||
crate::config::ColumnAlignment::Left => cell.set_alignment(CellAlignment::Left),
|
||||
};
|
||||
table_row.add_cell(cell);
|
||||
}
|
||||
table.add_row(table_row);
|
||||
|
||||
Reference in New Issue
Block a user