diff options
Diffstat (limited to 'src/completion.rs')
| -rw-r--r-- | src/completion.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/completion.rs b/src/completion.rs new file mode 100644 index 0000000..63ac866 --- /dev/null +++ b/src/completion.rs @@ -0,0 +1,34 @@ +use crate::*; +use std::fs; + +pub struct Suggestion { + pub display: BString, + full: BString, +} + +pub fn _path_completion(mut prefix: BString) -> io::Result<Vec<Suggestion>> { + let mut partial_entry = BString::new(); + while let Some(c) = prefix.last().cloned() { + if c == b'/' { + break; + } + partial_entry.push(c); + prefix.pop(); + } + partial_entry.reverse(); + + let mut sugs = Vec::new(); + + for entry in fs::read_dir(OsStr::from_bytes(&prefix))? { + let entry = entry?; + let name = entry.file_name().as_bytes().to_vec(); + if name.starts_with(&partial_entry) { + sugs.push(Suggestion { + display: name, + full: entry.path().as_os_str().as_bytes().to_vec(), + }); + } + } + + Ok(sugs) +} |
