fix: Truncate cell content to max 3 lines with ellipsis

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-08 18:45:38 -03:00
parent b41d710a35
commit 94fc538a50

View File

@@ -91,51 +91,72 @@ pub fn mode_list(
} }
} }
let mut cell = match column_type { let cell_content = match column_type {
ColumnType::Id => Cell::new(item.id.unwrap_or(0).to_string()), ColumnType::Id => item.id.unwrap_or(0).to_string(),
ColumnType::Time => Cell::new( ColumnType::Time => item.ts
item.ts .with_timezone(&chrono::Local)
.with_timezone(&chrono::Local) .format("%F %T")
.format("%F %T") .to_string(),
.to_string(),
),
ColumnType::Size => match item.size { ColumnType::Size => match item.size {
Some(size) => Cell::new(format_size( Some(size) => format_size(size as u64, settings.human_readable),
size as u64,
settings.human_readable,
)),
None => match item_path.metadata() { None => match item_path.metadata() {
Ok(_) => Cell::new("Unknown") Ok(_) => "Unknown".to_string(),
.fg(Color::Yellow) Err(_) => "Missing".to_string(),
.add_attribute(Attribute::Bold),
Err(_) => Cell::new("Missing")
.fg(Color::Red)
.add_attribute(Attribute::Bold),
}, },
}, },
ColumnType::Compression => Cell::new(item.compression.to_string()), ColumnType::Compression => item.compression.to_string(),
ColumnType::FileSize => match item_path.metadata() { ColumnType::FileSize => match item_path.metadata() {
Ok(metadata) => Cell::new(format_size( Ok(metadata) => format_size(metadata.len(), settings.human_readable),
metadata.len(), Err(_) => "Missing".to_string(),
settings.human_readable,
)),
Err(_) => Cell::new("Missing")
.fg(Color::Red)
.add_attribute(Attribute::Bold),
}, },
ColumnType::FilePath => Cell::new( ColumnType::FilePath => item_path.clone().into_os_string().into_string().unwrap(),
item_path.clone().into_os_string().into_string().unwrap(), ColumnType::Tags => tags.join(" "),
),
ColumnType::Tags => Cell::new(tags.join(" ")),
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) => Cell::new(meta_value.to_string()), Some(meta_value) => meta_value.to_string(),
None => Cell::new(""), None => "".to_string(),
}, },
None => Cell::new(""), None => "".to_string(),
}, },
}; };
// Truncate content to max 3 lines
let mut cell_lines: Vec<&str> = cell_content.split('\n').collect();
if cell_lines.len() > 3 {
cell_lines.truncate(3);
// Add ellipsis to the last line if we truncated
if let Some(last_line) = cell_lines.last_mut() {
let mut last_line = (*last_line).to_string();
if last_line.len() > 3 {
last_line.truncate(last_line.len() - 3);
}
last_line.push_str("...");
cell_lines[2] = Box::leak(last_line.into_boxed_str());
}
}
let truncated_content = cell_lines.join("\n");
let mut cell = Cell::new(truncated_content);
// Apply styling for specific cases
match column_type {
ColumnType::Size => {
if item.size.is_none() {
if item_path.metadata().is_ok() {
cell = cell.fg(Color::Yellow).add_attribute(Attribute::Bold);
} else {
cell = cell.fg(Color::Red).add_attribute(Attribute::Bold);
}
}
}
ColumnType::FileSize => {
if item_path.metadata().is_err() {
cell = cell.fg(Color::Red).add_attribute(Attribute::Bold);
}
}
_ => {}
}
// Apply alignment and max height // Apply alignment and max height
cell = match column.align { cell = match column.align {
crate::config::ColumnAlignment::Right => cell.set_alignment(CellAlignment::Right), crate::config::ColumnAlignment::Right => cell.set_alignment(CellAlignment::Right),