initial commit
This commit is contained in:
17
rdraught-cli/Cargo.toml
Normal file
17
rdraught-cli/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "rdraught-cli"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "rustyline-test"
|
||||
path = "src/rustyline-test.rs"
|
||||
|
||||
[dependencies]
|
||||
#reedline = "0.40"
|
||||
rustyline = {version = "16.0", default-features = false }
|
33
rdraught-cli/src/rustyline-test.rs
Normal file
33
rdraught-cli/src/rustyline-test.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use rustyline::error::ReadlineError;
|
||||
use rustyline::{DefaultEditor, Result};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// `()` can be used when no completer is required
|
||||
let mut rl = DefaultEditor::new()?;
|
||||
/* if rl.load_history("history.txt").is_err() {
|
||||
println!("No previous history.");
|
||||
} */
|
||||
loop {
|
||||
let readline = rl.readline(">> ");
|
||||
match readline {
|
||||
Ok(line) => {
|
||||
rl.add_history_entry(line.as_str())?;
|
||||
println!("Line: {}", line);
|
||||
}
|
||||
Err(ReadlineError::Interrupted) => {
|
||||
println!("CTRL-C");
|
||||
break;
|
||||
}
|
||||
Err(ReadlineError::Eof) => {
|
||||
println!("CTRL-D");
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Error: {:?}", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// rl.save_history("history.txt").unwrap();
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user