Fix examples in README based on lib.rs (#496)

The first two README examples became rotten and were out of sync with
the doctested version from the `lib.rs`
This commit is contained in:
Stefan Holderbach 2022-10-16 23:20:35 +02:00 committed by GitHub
parent f949f560f7
commit c08ce5ef7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 38 deletions

View File

@ -37,22 +37,22 @@ For the full documentation visit <https://docs.rs/reedline>. The examples should
// Create a default reedline object to handle user input
use reedline::{DefaultPrompt, Reedline, Signal};
use std::io;
fn main() -> io::Result<()> {
let mut line_editor = Reedline::create()?;
let prompt = DefaultPrompt::default();
let mut line_editor = Reedline::create();
let prompt = DefaultPrompt::default();
loop {
let sig = line_editor.read_line(&prompt)?;
loop {
let sig = line_editor.read_line(&prompt);
match sig {
Signal::Success(buffer) => {
Ok(Signal::Success(buffer)) => {
println!("We processed: {}", buffer);
}
Signal::CtrlD | Signal::CtrlC => {
Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => {
println!("\nAborted!");
break Ok(());
break;
}
x => {
println!("Event: {:?}", x);
}
}
}
@ -69,17 +69,18 @@ fn main() -> io::Result<()> {
use {
crossterm::event::{KeyCode, KeyModifiers},
reedline::{default_emacs_keybindings, EditCommand, Reedline},
reedline::{default_emacs_keybindings, EditCommand, Reedline, Emacs, ReedlineEvent},
};
let mut keybindings = default_emacs_keybindings();
keybindings.add_binding(
KeyModifiers::ALT,
KeyCode::Char('m'),
vec![EditCommand::BackspaceWord],
ReedlineEvent::Edit(vec![EditCommand::BackspaceWord]),
);
let edit_mode = Box::new(Emacs::new(keybindings));
let mut line_editor = Reedline::create().with_keybindings(keybindings);
let mut line_editor = Reedline::create().with_edit_mode(edit_mode);
```
### Integrate with `History`