From fb80e9c1cd4c2dcbb2d2ba1e2be8c7e19b9f0ce1 Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Thu, 5 Mar 2026 23:54:56 +0100 Subject: very buggy beginning of tab completion --- src/completion.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/completion.rs') diff --git a/src/completion.rs b/src/completion.rs index 63ac866..cb030a1 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -6,7 +6,7 @@ pub struct Suggestion { full: BString, } -pub fn _path_completion(mut prefix: BString) -> io::Result> { +fn _path_completion(mut prefix: BString) -> io::Result> { let mut partial_entry = BString::new(); while let Some(c) = prefix.last().cloned() { if c == b'/' { @@ -19,6 +19,10 @@ pub fn _path_completion(mut prefix: BString) -> io::Result> { let mut sugs = Vec::new(); + if prefix.is_empty() { + prefix.push(b'.'); + } + for entry in fs::read_dir(OsStr::from_bytes(&prefix))? { let entry = entry?; let name = entry.file_name().as_bytes().to_vec(); @@ -32,3 +36,13 @@ pub fn _path_completion(mut prefix: BString) -> io::Result> { Ok(sugs) } + +pub fn path_completion(prefix: BString) -> Vec { + match _path_completion(prefix) { + Ok(suggestions) => suggestions, + Err(err) => { + println!("path completion failed: {err:?}\r"); + Vec::new() + } + } +} -- cgit v1.2.3