From b656d9106b8db34913ff563258c6b17f3637ceff Mon Sep 17 00:00:00 2001 From: BakerNet Date: Sun, 29 Jun 2025 09:16:58 -0700 Subject: [PATCH] non-tty LsCommand --- src/app/terminal/fs_tools.rs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/app/terminal/fs_tools.rs b/src/app/terminal/fs_tools.rs index 98d2625..064746e 100644 --- a/src/app/terminal/fs_tools.rs +++ b/src/app/terminal/fs_tools.rs @@ -252,17 +252,41 @@ This version of ls only supports options 'a' and 'l'"# view! { {all_views} }.into_any() })) } else { - // For non-TTY output, just return simple text - // TODO - fix - not currently doing long format + // For non-TTY output, return text format let mut text_output = Vec::new(); + let is_multi = + dir_listings.len() > 1 || (!dir_listings.is_empty() && !file_items.is_empty()); + + // Handle file targets + if !file_items.is_empty() { + for item in &file_items { + if long_format { + text_output.push(format!("{} {}", item.node.long_meta_string(item.link_count), item.display_name)); + } else { + text_output.push(item.display_name.clone()); + } + } - for item in &file_items { - text_output.push(item.display_name.clone()); + if is_multi { + text_output.push("".to_string()); // Empty line separator + } } - for (_, items) in &dir_listings { + // Handle directory targets + for (i, (display_name, items)) in dir_listings.iter().enumerate() { + if is_multi { + if i > 0 { + text_output.push("".to_string()); // Empty line separator + } + text_output.push(format!("{}:", display_name)); + } + for item in items { - text_output.push(item.display_name.clone()); + if long_format { + text_output.push(format!("{} {}", item.node.long_meta_string(item.link_count), item.display_name)); + } else { + text_output.push(item.display_name.clone()); + } } }