feat(lineedit): add very basic readline
This commit is contained in:
parent
02f19d91ee
commit
a271fb2301
5 changed files with 40 additions and 1 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -84,6 +84,14 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oyster"
|
name = "oyster"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"oyster_lineedit",
|
||||||
|
"oyster_parser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oyster_lineedit"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oyster_parser"
|
name = "oyster_parser"
|
||||||
|
|
|
@ -4,3 +4,5 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
oyster_lineedit = { path = "../oyster_lineedit" }
|
||||||
|
oyster_parser = { path = "../oyster_parser" }
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
|
use oyster_lineedit::readline;
|
||||||
|
use oyster_parser::ast::Code;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
loop {
|
||||||
|
let prog = readline("> ").unwrap();
|
||||||
|
|
||||||
|
if prog.trim() == "exit" {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Code::try_from(prog.as_ref()).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
7
crates/oyster_lineedit/Cargo.toml
Normal file
7
crates/oyster_lineedit/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "oyster_lineedit"
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
doctest = false
|
11
crates/oyster_lineedit/src/lib.rs
Normal file
11
crates/oyster_lineedit/src/lib.rs
Normal 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)
|
||||||
|
}
|
Loading…
Reference in a new issue