mirror of
https://github.com/nushell/reedline.git
synced 2024-09-11 15:55:50 +03:00
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:
parent
f949f560f7
commit
c08ce5ef7f
43
README.md
43
README.md
@ -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
|
// Create a default reedline object to handle user input
|
||||||
|
|
||||||
use reedline::{DefaultPrompt, Reedline, Signal};
|
use reedline::{DefaultPrompt, Reedline, Signal};
|
||||||
use std::io;
|
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
let mut line_editor = Reedline::create();
|
||||||
let mut line_editor = Reedline::create()?;
|
let prompt = DefaultPrompt::default();
|
||||||
let prompt = DefaultPrompt::default();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let sig = line_editor.read_line(&prompt)?;
|
let sig = line_editor.read_line(&prompt);
|
||||||
match sig {
|
match sig {
|
||||||
Signal::Success(buffer) => {
|
Ok(Signal::Success(buffer)) => {
|
||||||
println!("We processed: {}", buffer);
|
println!("We processed: {}", buffer);
|
||||||
}
|
}
|
||||||
Signal::CtrlD | Signal::CtrlC => {
|
Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => {
|
||||||
println!("\nAborted!");
|
println!("\nAborted!");
|
||||||
break Ok(());
|
break;
|
||||||
}
|
}
|
||||||
|
x => {
|
||||||
|
println!("Event: {:?}", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,22 +64,23 @@ fn main() -> io::Result<()> {
|
|||||||
// Configure reedline with custom keybindings
|
// Configure reedline with custom keybindings
|
||||||
|
|
||||||
//Cargo.toml
|
//Cargo.toml
|
||||||
// [dependencies]
|
// [dependencies]
|
||||||
// crossterm = "*"
|
// crossterm = "*"
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crossterm::event::{KeyCode, KeyModifiers},
|
crossterm::event::{KeyCode, KeyModifiers},
|
||||||
reedline::{default_emacs_keybindings, EditCommand, Reedline},
|
reedline::{default_emacs_keybindings, EditCommand, Reedline, Emacs, ReedlineEvent},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut keybindings = default_emacs_keybindings();
|
let mut keybindings = default_emacs_keybindings();
|
||||||
keybindings.add_binding(
|
keybindings.add_binding(
|
||||||
KeyModifiers::ALT,
|
KeyModifiers::ALT,
|
||||||
KeyCode::Char('m'),
|
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`
|
### Integrate with `History`
|
||||||
|
34
src/lib.rs
34
src/lib.rs
@ -15,24 +15,24 @@
|
|||||||
//!
|
//!
|
||||||
//! use reedline::{DefaultPrompt, Reedline, Signal};
|
//! use reedline::{DefaultPrompt, Reedline, Signal};
|
||||||
//!
|
//!
|
||||||
//! let mut line_editor = Reedline::create();
|
//! let mut line_editor = Reedline::create();
|
||||||
//! let prompt = DefaultPrompt::default();
|
//! let prompt = DefaultPrompt::default();
|
||||||
//!
|
//!
|
||||||
//! loop {
|
//! loop {
|
||||||
//! let sig = line_editor.read_line(&prompt);
|
//! let sig = line_editor.read_line(&prompt);
|
||||||
//! match sig {
|
//! match sig {
|
||||||
//! Ok(Signal::Success(buffer)) => {
|
//! Ok(Signal::Success(buffer)) => {
|
||||||
//! println!("We processed: {}", buffer);
|
//! println!("We processed: {}", buffer);
|
||||||
//! }
|
//! }
|
||||||
//! Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => {
|
//! Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => {
|
||||||
//! println!("\nAborted!");
|
//! println!("\nAborted!");
|
||||||
//! break;
|
//! break;
|
||||||
//! }
|
//! }
|
||||||
//! x => {
|
//! x => {
|
||||||
//! println!("Event: {:?}", x);
|
//! println!("Event: {:?}", x);
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//! ## Integrate with custom keybindings
|
//! ## Integrate with custom keybindings
|
||||||
//!
|
//!
|
||||||
|
Loading…
Reference in New Issue
Block a user