You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1000 B

  1. mod error;
  2. mod execute;
  3. mod parse;
  4. mod prompt;
  5. use crate::error::ShellError;
  6. use execute::interpret;
  7. use rustyline::error::ReadlineError;
  8. use rustyline::{Editor, Result};
  9. use crate::prompt::Prompt;
  10. fn main() -> Result<()> {
  11. let mut rl = Editor::<()>::new()?;
  12. let mut prompt = Prompt::new();
  13. loop {
  14. let readline = rl.readline(&prompt.get_prompt());
  15. match readline {
  16. Ok(line) => match interpret(&line) {
  17. Ok(_) => {}
  18. Err(ShellError::EmptyLine) => {
  19. continue;
  20. }
  21. Err(ShellError::Execute(err)) => {
  22. eprintln!("{}", err)
  23. }
  24. },
  25. Err(ReadlineError::Interrupted) => {
  26. break;
  27. }
  28. Err(ReadlineError::Eof) => {
  29. break;
  30. }
  31. Err(err) => {
  32. println!("Error: {:?}", err);
  33. break;
  34. }
  35. }
  36. }
  37. Ok(())
  38. }