fix: Correctly handle string slices and no newline
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -245,17 +245,15 @@ pub fn mode_list(
|
||||
};
|
||||
|
||||
// Truncate content to max 3 lines
|
||||
let mut cell_lines: Vec<&str> = cell_content.split('\n').collect();
|
||||
let mut cell_lines: Vec<String> = cell_content.split('\n').map(|s| s.to_string()).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");
|
||||
@@ -286,15 +284,15 @@ pub fn mode_list(
|
||||
ColumnType::Size => {
|
||||
if item.size.is_none() {
|
||||
if item_path.metadata().is_ok() {
|
||||
cell = cell.fg(Color::Yellow).add_attribute(Attribute::Bold);
|
||||
cell = cell.fg(comfy_table::Color::Yellow).add_attribute(Attribute::Bold);
|
||||
} else {
|
||||
cell = cell.fg(Color::Red).add_attribute(Attribute::Bold);
|
||||
cell = cell.fg(comfy_table::Color::Red).add_attribute(Attribute::Bold);
|
||||
}
|
||||
}
|
||||
}
|
||||
ColumnType::FileSize => {
|
||||
if item_path.metadata().is_err() {
|
||||
cell = cell.fg(Color::Red).add_attribute(Attribute::Bold);
|
||||
cell = cell.fg(comfy_table::Color::Red).add_attribute(Attribute::Bold);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -371,4 +369,23 @@ fn show_list_structured(
|
||||
compression: item.compression,
|
||||
file_size,
|
||||
file_size_formatted,
|
||||
file_path: item_path.into_os_string().into_string
|
||||
file_path: item_path.into_os_string().into_string().unwrap_or_default(),
|
||||
tags,
|
||||
meta,
|
||||
};
|
||||
|
||||
list_items.push(list_item);
|
||||
}
|
||||
|
||||
match output_format {
|
||||
OutputFormat::Json => {
|
||||
println!("{}", serde_json::to_string_pretty(&list_items)?);
|
||||
}
|
||||
OutputFormat::Yaml => {
|
||||
println!("{}", serde_yaml::to_string(&list_items)?);
|
||||
}
|
||||
OutputFormat::Table => unreachable!(),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user