use rustyline::error::ReadlineError; use rustyline::Editor; mod parser; mod prompt; fn main() { match std::fs::read_to_string("/etc/motd") { Ok(motd) => print!("{}", motd), Err(_) => {} } let prompt = prompt::Prompt::new().unwrap(); let mut cwd = std::env::current_dir().unwrap(); let mut status: Option = None; // `()` can be used when no completer is required let mut rl = Editor::<()>::new(); /*if rl.load_history("history.txt").is_err() { println!("No previous history."); }*/ 'repl: loop { let readline = rl.readline(&prompt.print(&cwd)); match readline { Ok(line) => { rl.add_history_entry(line.as_str()); let i = parser::tokenize(&line); match i.run(&prompt.home, &mut cwd, &status) { Ok(parser::command::RunResult::Command(s)) => status = Some(s), Ok(parser::command::RunResult::Builtin) => {} 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(); }