use rustyline::error::ReadlineError; use rustyline::Editor; mod commandline; mod completer; mod prompt; fn main() -> Result<(), std::io::Error> { if let Ok(motd) = std::fs::read_to_string("/etc/motd") { print!("{}", motd) } let mut status = None; // exit status of last command // map of variables let hinter = completer::CommandHinter::new()?; let mut rl = Editor::::new(); rl.set_helper(Some(hinter)); 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::CommandLine::new(&line); match cmd.run(&prompt.home, status) { Ok(s) => status = s, Err(e) => eprintln!("{}", e), } } Err(ReadlineError::Interrupted) => { println!("CTRL-C"); continue; } Err(ReadlineError::Eof) => { println!("CTRL-D"); break 'repl; } Err(err) => { println!("Error: {:?}", err); break 'repl; } } } //rl.save_history("history.txt").unwrap(); Ok(()) }