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:
@@ -9,6 +9,16 @@ use crate::args::{Args};
|
|||||||
pub struct ColumnConfig {
|
pub struct ColumnConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub align: ColumnAlignment,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum ColumnAlignment {
|
||||||
|
#[default]
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> serde::Deserialize<'de> for ColumnConfig {
|
impl<'de> serde::Deserialize<'de> for ColumnConfig {
|
||||||
@@ -20,6 +30,8 @@ impl<'de> serde::Deserialize<'de> for ColumnConfig {
|
|||||||
struct Helper {
|
struct Helper {
|
||||||
name: String,
|
name: String,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
align: ColumnAlignment,
|
||||||
}
|
}
|
||||||
|
|
||||||
let helper = Helper::deserialize(deserializer)?;
|
let helper = Helper::deserialize(deserializer)?;
|
||||||
@@ -28,6 +40,7 @@ impl<'de> serde::Deserialize<'de> for ColumnConfig {
|
|||||||
Ok(ColumnConfig {
|
Ok(ColumnConfig {
|
||||||
name: helper.name,
|
name: helper.name,
|
||||||
label,
|
label,
|
||||||
|
align: helper.align,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,56 +119,93 @@ pub fn mode_list(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cell = match column_type {
|
let cell = match column_type {
|
||||||
ColumnType::Id => Cell::new_align(
|
ColumnType::Id => {
|
||||||
&string_column(item.id.unwrap_or(0).to_string(), column_width),
|
let cell = Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width));
|
||||||
Alignment::RIGHT,
|
match column.align {
|
||||||
),
|
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
||||||
ColumnType::Time => Cell::new(&string_column(
|
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
||||||
item.ts
|
}
|
||||||
.with_timezone(&chrono::Local)
|
},
|
||||||
.format("%F %T")
|
ColumnType::Time => {
|
||||||
.to_string(),
|
let cell = Cell::new(&string_column(
|
||||||
column_width,
|
item.ts
|
||||||
)),
|
.with_timezone(&chrono::Local)
|
||||||
ColumnType::Size => match item.size {
|
.format("%F %T")
|
||||||
Some(size) => Cell::new_align(
|
.to_string(),
|
||||||
&size_column(size as u64, settings.human_readable, column_width),
|
column_width,
|
||||||
Alignment::RIGHT,
|
));
|
||||||
),
|
match column.align {
|
||||||
None => match item_path.metadata() {
|
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
||||||
Ok(_) => Cell::new_align("Unknown", Alignment::RIGHT)
|
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
||||||
.with_style(Attr::ForegroundColor(color::YELLOW))
|
}
|
||||||
.with_style(Attr::Bold),
|
},
|
||||||
Err(_) => Cell::new_align("Missing", Alignment::RIGHT)
|
ColumnType::Size => {
|
||||||
.with_style(Attr::ForegroundColor(color::RED))
|
let cell = match item.size {
|
||||||
.with_style(Attr::Bold),
|
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 => {
|
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() {
|
ColumnType::FileSize => {
|
||||||
Ok(metadata) => Cell::new_align(
|
let cell = match item_path.metadata() {
|
||||||
&size_column(metadata.len(), settings.human_readable, column_width),
|
Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)),
|
||||||
Alignment::RIGHT,
|
Err(_) => Cell::new("Missing")
|
||||||
),
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
Err(_) => Cell::new_align("Missing", Alignment::RIGHT)
|
.with_style(Attr::Bold),
|
||||||
.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(
|
ColumnType::FilePath => {
|
||||||
item_path.clone().into_os_string().into_string().unwrap(),
|
let cell = Cell::new(&string_column(
|
||||||
column_width,
|
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 {
|
match column.align {
|
||||||
Some(meta_name) => match meta.get(meta_name) {
|
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
||||||
Some(meta_value) => {
|
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
||||||
Cell::new(&string_column(meta_value.to_string(), column_width))
|
}
|
||||||
}
|
},
|
||||||
|
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(""),
|
||||||
},
|
};
|
||||||
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);
|
table_row.add_cell(cell);
|
||||||
|
|||||||
Reference in New Issue
Block a user