feat(lineedit): add very basic readline

This commit is contained in:
buffet 2022-08-28 12:55:09 +00:00
parent 02f19d91ee
commit a271fb2301
5 changed files with 40 additions and 1 deletions

8
Cargo.lock generated
View file

@ -84,6 +84,14 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "oyster"
version = "0.1.0"
dependencies = [
"oyster_lineedit",
"oyster_parser",
]
[[package]]
name = "oyster_lineedit"
version = "0.0.0"
[[package]]
name = "oyster_parser"

View file

@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
oyster_lineedit = { path = "../oyster_lineedit" }
oyster_parser = { path = "../oyster_parser" }

View file

@ -1,3 +1,14 @@
use oyster_lineedit::readline;
use oyster_parser::ast::Code;
fn main() {
println!("Hello, world!");
loop {
let prog = readline("> ").unwrap();
if prog.trim() == "exit" {
break;
}
Code::try_from(prog.as_ref()).unwrap();
}
}

View file

@ -0,0 +1,7 @@
[package]
name = "oyster_lineedit"
version = "0.0.0"
edition = "2021"
[lib]
doctest = false

View file

@ -0,0 +1,11 @@
use std::io::{self, Write};
pub fn readline(prompt: &str) -> Result<String, io::Error> {
print!("{}", prompt);
io::stdout().flush()?;
let mut buf = String::new();
io::stdin().read_line(&mut buf)?;
Ok(buf)
}