From 6ccea1872c14f621d012a9924307501b372ca68e Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 10 Sep 2025 12:17:01 -0300 Subject: [PATCH] fix: Correctly handle string slices and no newline Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) --- src/modes/list.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/modes/list.rs b/src/modes/list.rs index 8b5ab30..411e27f 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -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 = 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 \ No newline at end of file + 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(()) +}