From e6d053696437aa9f38b62195d190feef466c3408 Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Mon, 16 Jan 2023 19:00:58 +0100 Subject: [PATCH] feat: implement basic read-eval-print loop --- src/main.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..ab28964 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,30 @@ -fn main() { - println!("Hello, world!"); -} +use rustyline::error::ReadlineError; +use rustyline::{Editor, Result}; + +fn main() -> Result<()> { + let mut rl = Editor::<()>::new()?; + + loop { + let readline = rl.readline("ยป "); + + match readline { + Ok(line) => { + println!("Line: {}", line); + }, + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break + }, + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break + }, + Err(err) => { + println!("Error: {:?}", err); + break + } + } + } + + Ok(()) +} \ No newline at end of file