fix: add align field to ColumnConfig and fix cell creation functions
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -197,11 +197,11 @@ impl Settings {
|
|||||||
if settings.list_format.is_empty() {
|
if settings.list_format.is_empty() {
|
||||||
debug!("CONFIG: Setting default list_format");
|
debug!("CONFIG: Setting default list_format");
|
||||||
settings.list_format = vec![
|
settings.list_format = vec![
|
||||||
ColumnConfig { name: "id".to_string(), label: "id".to_string() },
|
ColumnConfig { name: "id".to_string(), label: "id".to_string(), align: ColumnAlignment::Left },
|
||||||
ColumnConfig { name: "time".to_string(), label: "time".to_string() },
|
ColumnConfig { name: "time".to_string(), label: "time".to_string(), align: ColumnAlignment::Left },
|
||||||
ColumnConfig { name: "size".to_string(), label: "size".to_string() },
|
ColumnConfig { name: "size".to_string(), label: "size".to_string(), align: ColumnAlignment::Left },
|
||||||
ColumnConfig { name: "tags".to_string(), label: "tags".to_string() },
|
ColumnConfig { name: "tags".to_string(), label: "tags".to_string(), align: ColumnAlignment::Left },
|
||||||
ColumnConfig { name: "meta:hostname".to_string(), label: "hostname".to_string() },
|
ColumnConfig { name: "meta:hostname".to_string(), label: "hostname".to_string(), align: ColumnAlignment::Left },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,91 +120,121 @@ pub fn mode_list(
|
|||||||
|
|
||||||
let cell = match column_type {
|
let cell = match column_type {
|
||||||
ColumnType::Id => {
|
ColumnType::Id => {
|
||||||
let cell = Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width));
|
|
||||||
match column.align {
|
match column.align {
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
crate::config::ColumnAlignment::Right => Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width)).align(Alignment::RIGHT),
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
crate::config::ColumnAlignment::Left => Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width)).align(Alignment::LEFT),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::Time => {
|
ColumnType::Time => {
|
||||||
let cell = Cell::new(&string_column(
|
match column.align {
|
||||||
|
crate::config::ColumnAlignment::Right => Cell::new(&string_column(
|
||||||
item.ts
|
item.ts
|
||||||
.with_timezone(&chrono::Local)
|
.with_timezone(&chrono::Local)
|
||||||
.format("%F %T")
|
.format("%F %T")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
column_width,
|
column_width,
|
||||||
));
|
)).align(Alignment::RIGHT),
|
||||||
match column.align {
|
crate::config::ColumnAlignment::Left => Cell::new(&string_column(
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
item.ts
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
.with_timezone(&chrono::Local)
|
||||||
|
.format("%F %T")
|
||||||
|
.to_string(),
|
||||||
|
column_width,
|
||||||
|
)).align(Alignment::LEFT),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::Size => {
|
ColumnType::Size => {
|
||||||
let cell = match item.size {
|
match column.align {
|
||||||
Some(size) => Cell::new(&size_column(size as u64, settings.human_readable, column_width)),
|
crate::config::ColumnAlignment::Right => match item.size {
|
||||||
|
Some(size) => Cell::new(&size_column(size as u64, settings.human_readable, column_width)).align(Alignment::RIGHT),
|
||||||
None => match item_path.metadata() {
|
None => match item_path.metadata() {
|
||||||
Ok(_) => Cell::new("Unknown")
|
Ok(_) => Cell::new("Unknown")
|
||||||
.with_style(Attr::ForegroundColor(color::YELLOW))
|
.with_style(Attr::ForegroundColor(color::YELLOW))
|
||||||
.with_style(Attr::Bold),
|
.with_style(Attr::Bold)
|
||||||
|
.align(Alignment::RIGHT),
|
||||||
Err(_) => Cell::new("Missing")
|
Err(_) => Cell::new("Missing")
|
||||||
.with_style(Attr::ForegroundColor(color::RED))
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
.with_style(Attr::Bold),
|
.with_style(Attr::Bold)
|
||||||
|
.align(Alignment::RIGHT),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
crate::config::ColumnAlignment::Left => match item.size {
|
||||||
|
Some(size) => Cell::new(&size_column(size as u64, settings.human_readable, column_width)).align(Alignment::LEFT),
|
||||||
|
None => match item_path.metadata() {
|
||||||
|
Ok(_) => Cell::new("Unknown")
|
||||||
|
.with_style(Attr::ForegroundColor(color::YELLOW))
|
||||||
|
.with_style(Attr::Bold)
|
||||||
|
.align(Alignment::LEFT),
|
||||||
|
Err(_) => Cell::new("Missing")
|
||||||
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
|
.with_style(Attr::Bold)
|
||||||
|
.align(Alignment::LEFT),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
|
||||||
match column.align {
|
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::Compression => {
|
ColumnType::Compression => {
|
||||||
let cell = Cell::new(&string_column(item.compression.to_string(), column_width));
|
|
||||||
match column.align {
|
match column.align {
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
crate::config::ColumnAlignment::Right => Cell::new(&string_column(item.compression.to_string(), column_width)).align(Alignment::RIGHT),
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
crate::config::ColumnAlignment::Left => Cell::new(&string_column(item.compression.to_string(), column_width)).align(Alignment::LEFT),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::FileSize => {
|
ColumnType::FileSize => {
|
||||||
let cell = match item_path.metadata() {
|
match column.align {
|
||||||
Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)),
|
crate::config::ColumnAlignment::Right => match item_path.metadata() {
|
||||||
|
Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)).align(Alignment::RIGHT),
|
||||||
Err(_) => Cell::new("Missing")
|
Err(_) => Cell::new("Missing")
|
||||||
.with_style(Attr::ForegroundColor(color::RED))
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
.with_style(Attr::Bold),
|
.with_style(Attr::Bold)
|
||||||
};
|
.align(Alignment::RIGHT),
|
||||||
match column.align {
|
},
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
crate::config::ColumnAlignment::Left => match item_path.metadata() {
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
Ok(metadata) => Cell::new(&size_column(metadata.len(), settings.human_readable, column_width)).align(Alignment::LEFT),
|
||||||
|
Err(_) => Cell::new("Missing")
|
||||||
|
.with_style(Attr::ForegroundColor(color::RED))
|
||||||
|
.with_style(Attr::Bold)
|
||||||
|
.align(Alignment::LEFT),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::FilePath => {
|
ColumnType::FilePath => {
|
||||||
let cell = Cell::new(&string_column(
|
match column.align {
|
||||||
|
crate::config::ColumnAlignment::Right => Cell::new(&string_column(
|
||||||
item_path.clone().into_os_string().into_string().unwrap(),
|
item_path.clone().into_os_string().into_string().unwrap(),
|
||||||
column_width,
|
column_width,
|
||||||
));
|
)).align(Alignment::RIGHT),
|
||||||
match column.align {
|
crate::config::ColumnAlignment::Left => Cell::new(&string_column(
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
item_path.clone().into_os_string().into_string().unwrap(),
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
column_width,
|
||||||
|
)).align(Alignment::LEFT),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::Tags => {
|
ColumnType::Tags => {
|
||||||
let cell = Cell::new(&string_column(tags.join(" "), column_width));
|
|
||||||
match column.align {
|
match column.align {
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
crate::config::ColumnAlignment::Right => Cell::new(&string_column(tags.join(" "), column_width)).align(Alignment::RIGHT),
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
crate::config::ColumnAlignment::Left => Cell::new(&string_column(tags.join(" "), column_width)).align(Alignment::LEFT),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ColumnType::Meta => {
|
ColumnType::Meta => {
|
||||||
let cell = match meta_name {
|
match column.align {
|
||||||
|
crate::config::ColumnAlignment::Right => 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(&string_column(meta_value.to_string(), column_width))
|
Cell::new(&string_column(meta_value.to_string(), column_width)).align(Alignment::RIGHT)
|
||||||
}
|
}
|
||||||
None => Cell::new(""),
|
None => Cell::new("").align(Alignment::RIGHT),
|
||||||
|
},
|
||||||
|
None => Cell::new("").align(Alignment::RIGHT),
|
||||||
|
},
|
||||||
|
crate::config::ColumnAlignment::Left => match meta_name {
|
||||||
|
Some(meta_name) => match meta.get(meta_name) {
|
||||||
|
Some(meta_value) => {
|
||||||
|
Cell::new(&string_column(meta_value.to_string(), column_width)).align(Alignment::LEFT)
|
||||||
|
}
|
||||||
|
None => Cell::new("").align(Alignment::LEFT),
|
||||||
|
},
|
||||||
|
None => Cell::new("").align(Alignment::LEFT),
|
||||||
},
|
},
|
||||||
None => Cell::new(""),
|
|
||||||
};
|
|
||||||
match column.align {
|
|
||||||
crate::config::ColumnAlignment::Right => cell.align(Alignment::RIGHT),
|
|
||||||
crate::config::ColumnAlignment::Left => cell.align(Alignment::LEFT),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user