use crate::*; use std::fs; pub struct Suggestion { pub display: BString, full: BString, } fn _path_completion(mut prefix: BString) -> io::Result> { 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(); 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(); if name.starts_with(&partial_entry) { sugs.push(Suggestion { display: name, full: entry.path().as_os_str().as_bytes().to_vec(), }); } } 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() } } }