From bb00c5adc5b89b43baf1bf3c7aa7baffe5bec38f Mon Sep 17 00:00:00 2001 From: Denys Rybalka Date: Thu, 3 Oct 2024 10:20:43 +0200 Subject: [PATCH] Distinguish dirs visually in file_browser --- helix-term/src/ui/mod.rs | 16 ++++++++-------- helix-term/src/ui/picker.rs | 10 ++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 62c9fb9121fa0..2c105aba5a253 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -273,10 +273,12 @@ pub fn file_browser(root: PathBuf) -> Result { let columns = [PickerColumn::new( "path", |item: &PathBuf, root: &PathBuf| { - item.strip_prefix(root) - .unwrap_or(item) - .to_string_lossy() - .into() + let name = item.strip_prefix(root).unwrap_or(item).to_string_lossy(); + if item.is_dir() { + format!("{}/", name).into() + } else { + name.into() + } }, )]; let picker = Picker::new( @@ -316,11 +318,10 @@ fn directory_content(path: &Path) -> Result, std::io::Error> { let mut dirs = Vec::new(); let mut files = Vec::new(); for entry in std::fs::read_dir(path)?.flatten() { - let entry_path = entry.path(); if entry.path().is_dir() { - dirs.push(entry_path); + dirs.push(entry.path()); } else { - files.push(entry_path); + files.push(entry.path()); } } dirs.sort(); @@ -328,7 +329,6 @@ fn directory_content(path: &Path) -> Result, std::io::Error> { let mut content = Vec::new(); if path.parent().is_some() { - log::warn!("{}", path.to_string_lossy()); content.insert(0, path.join("..")); } content.extend(dirs); diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 5afc1f537391f..4cb3e80f1e67b 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -555,8 +555,14 @@ impl Picker { let files = super::directory_content(&path)?; let file_names: Vec<_> = files .iter() - .filter_map(|file| file.file_name()) - .map(|name| name.to_string_lossy().into_owned()) + .filter_map(|file| { + let name = file.file_name()?.to_string_lossy(); + if file.is_dir() { + Some(format!("{}/", name)) + } else { + Some(name.into_owned()) + } + }) .collect(); Ok(CachedPreview::Directory(file_names)) } else if metadata.is_file() {