diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index ca5dc00..118d2e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,31 +2,36 @@ use rustyline::error::ReadlineError; use rustyline::Editor; mod commandline; -use commandline::CommandLine; +mod completer; mod prompt; -fn main() -> Result<(), std::io::Error>{ +fn main() -> Result<(), std::io::Error> { if let Ok(motd) = std::fs::read_to_string("/etc/motd") { print!("{}", motd) } - // TODO: [completer] `()` can be used when no completer is required - let mut rl = Editor::<()>::new(); - let prompt = prompt::Prompt::new()?; + let mut status = None; // exit status of last command + // map of variables + + let hinter = completer::CommandHinter::new()?; + let mut rl = Editor::<completer::CommandHinter>::new(); + rl.set_helper(Some(hinter)); - let mut status = None; // exit status of last command - // map of variables + let prompt = prompt::Prompt::new()?; /*if rl.load_history("history.txt").is_err() { println!("No previous history."); }*/ 'repl: loop { + let cwd = std::env::current_dir()?; + rl.helper_mut().unwrap().set_cwd(&cwd); + match rl.readline(&prompt.print()) { Ok(line) => { rl.add_history_entry(line.as_str()); - let cmd = CommandLine::new(&line); + let cmd = commandline::CommandLine::new(&line); match cmd.run(&prompt.home, status) { Ok(s) => status = s, Err(e) => eprintln!("{}", e), |