feat: add support for left/right alignment in list_format columns

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-16 13:42:12 -03:00
parent 21e8eb1d09
commit 65dd800526
2 changed files with 95 additions and 45 deletions

View File

@@ -119,56 +119,93 @@ pub fn mode_list(
}
let cell = match column_type {
ColumnType::Id => Cell::new_align(
&string_column(item.id.unwrap_or(0).to_string(), column_width),
Alignment::RIGHT,
),
ColumnType::Time => Cell::new(&string_column(
item.ts
.with_timezone(&chrono::Local)
.format("%F %T")
.to_string(),
column_width,
)),
ColumnType::Size => match item.size {
Some(size) => Cell::new_align(
&size_column(size as u64, settings.human_readable, column_width),
Alignment::RIGHT,
),
None => match item_path.metadata() {
Ok(_) => Cell::new_align("Unknown", Alignment::RIGHT)
.with_style(Attr::ForegroundColor(color::YELLOW))
.with_style(Attr::Bold),
Err(_) => Cell::new_align("Missing", Alignment::RIGHT)
.with_style(Attr::ForegroundColor(color::RED))
.with_style(Attr::Bold),
},
ColumnType::Id => {
let cell = Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width));
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::Time => {
let cell = Cell::new(&string_column(
item.ts
.with_timezone(&chrono::Local)
.format("%F %T")
.to_string(),
column_width,
));
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::Size => {
let cell = match item.size {
Some(size) => Cell::new(&size_column(size as u64, settings.human_readable, column_width)),
None => match item_path.metadata() {
Ok(_) => Cell::new("Unknown")
.with_style(Attr::ForegroundColor(color::YELLOW))
.with_style(Attr::Bold),
Err(_) => Cell::new("Missing")
.with_style(Attr::ForegroundColor(color::RED))
.with_style(Attr::Bold),
},
};
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::Compression => {
Cell::new(&string_column(item.compression.to_string(), column_width))
let cell = Cell::new(&string_column(item.compression.to_string(), column_width));
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::FileSize => match item_path.metadata() {
Ok(metadata) => Cell::new_align(
&size_column(metadata.len(), settings.human_readable, column_width),
Alignment::RIGHT,
),
Err(_) => Cell::new_align("Missing", Alignment::RIGHT)
.with_style(Attr::ForegroundColor(color::RED))
.with_style(Attr::Bold),
ColumnType::FileSize => {
let cell = match item_path.metadata() {
Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)),
Err(_) => Cell::new("Missing")
.with_style(Attr::ForegroundColor(color::RED))
.with_style(Attr::Bold),
};
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::FilePath => Cell::new(&string_column(
item_path.clone().into_os_string().into_string().unwrap(),
column_width,
)),
ColumnType::Tags => Cell::new(&string_column(tags.join(" "), column_width)),
ColumnType::Meta => match meta_name {
Some(meta_name) => match meta.get(meta_name) {
Some(meta_value) => {
Cell::new(&string_column(meta_value.to_string(), column_width))
}
ColumnType::FilePath => {
let cell = Cell::new(&string_column(
item_path.clone().into_os_string().into_string().unwrap(),
column_width,
));
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::Tags => {
let cell = Cell::new(&string_column(tags.join(" "), column_width));
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
ColumnType::Meta => {
let cell = match meta_name {
Some(meta_name) => match meta.get(meta_name) {
Some(meta_value) => {
Cell::new(&string_column(meta_value.to_string(), column_width))
}
None => Cell::new(""),
},
None => Cell::new(""),
},
None => Cell::new(""),
};
match column.align {
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
}
},
};
table_row.add_cell(cell);