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 {
|
let mut cell = match column_type {
|
||||||
ColumnType::Id => {
|
ColumnType::Id => Cell::new(item.id.unwrap_or(0).to_string()),
|
||||||
let mut cell = Cell::new(item.id.unwrap_or(0).to_string());
|
ColumnType::Time => Cell::new(
|
||||||
match column.align {
|
item.ts
|
||||||
crate::config::ColumnAlignment::Right => {
|
.with_timezone(&chrono::Local)
|
||||||
cell = cell.set_alignment(CellAlignment::Right);
|
.format("%F %T")
|
||||||
}
|
.to_string(),
|
||||||
crate::config::ColumnAlignment::Left => {
|
),
|
||||||
cell = cell.set_alignment(CellAlignment::Left);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cell
|
|
||||||
}
|
|
||||||
ColumnType::Time => {
|
|
||||||
let mut cell = 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 {
|
ColumnType::Size => match item.size {
|
||||||
Some(size) => {
|
Some(size) => Cell::new(format_size(
|
||||||
let mut cell = Cell::new(format_size(
|
size as u64,
|
||||||
size as u64,
|
settings.human_readable,
|
||||||
settings.human_readable,
|
)),
|
||||||
));
|
None => match item_path.metadata() {
|
||||||
match column.align {
|
Ok(_) => Cell::new("Unknown")
|
||||||
crate::config::ColumnAlignment::Right => {
|
.fg(Color::Yellow)
|
||||||
cell = cell.set_alignment(CellAlignment::Right);
|
.add_attribute(Attribute::Bold),
|
||||||
}
|
Err(_) => Cell::new("Missing")
|
||||||
crate::config::ColumnAlignment::Left => {
|
|
||||||
cell = cell.set_alignment(CellAlignment::Left);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cell
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let mut cell = 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::FileSize => match item_path.metadata() {
|
|
||||||
Ok(metadata) => {
|
|
||||||
let mut cell = 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")
|
|
||||||
.fg(Color::Red)
|
.fg(Color::Red)
|
||||||
.add_attribute(Attribute::Bold);
|
.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::FilePath => {
|
ColumnType::Compression => Cell::new(item.compression.to_string()),
|
||||||
let mut cell = Cell::new(
|
ColumnType::FileSize => match item_path.metadata() {
|
||||||
item_path.clone().into_os_string().into_string().unwrap(),
|
Ok(metadata) => Cell::new(format_size(
|
||||||
);
|
metadata.len(),
|
||||||
match column.align {
|
settings.human_readable,
|
||||||
crate::config::ColumnAlignment::Right => {
|
)),
|
||||||
cell = cell.set_alignment(CellAlignment::Right);
|
Err(_) => Cell::new("Missing")
|
||||||
}
|
.fg(Color::Red)
|
||||||
crate::config::ColumnAlignment::Left => {
|
.add_attribute(Attribute::Bold),
|
||||||
cell = cell.set_alignment(CellAlignment::Left);
|
},
|
||||||
}
|
ColumnType::FilePath => Cell::new(
|
||||||
}
|
item_path.clone().into_os_string().into_string().unwrap(),
|
||||||
cell
|
),
|
||||||
}
|
ColumnType::Tags => Cell::new(tags.join(" ")),
|
||||||
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::Meta => match meta_name {
|
ColumnType::Meta => match meta_name {
|
||||||
Some(meta_name) => match meta.get(meta_name) {
|
Some(meta_name) => match meta.get(meta_name) {
|
||||||
Some(meta_value) => {
|
Some(meta_value) => Cell::new(meta_value.to_string()),
|
||||||
let mut cell = Cell::new(meta_value.to_string());
|
None => 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 => {
|
|
||||||
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 => {
|
None => Cell::new(""),
|
||||||
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
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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_row.add_cell(cell);
|
||||||
}
|
}
|
||||||
table.add_row(table_row);
|
table.add_row(table_row);
|
||||||
|
|||||||
Reference in New Issue
Block a user