mirror of
https://github.com/nushell/reedline.git
synced 2024-08-17 11:50:42 +03:00
Fix completion example in README/lib.rs (#497)
Adapted from examples added in #493
This commit is contained in:
parent
c08ce5ef7f
commit
5061d2288c
20
README.md
20
README.md
@ -120,7 +120,7 @@ Reedline::create().with_highlighter(Box::new(ExampleHighlighter::new(commands)))
|
||||
```rust
|
||||
// Create a reedline object with tab completions support
|
||||
|
||||
use reedline::{ColumnarMenu, DefaultCompleter, Reedline, ReedlineMenu};
|
||||
use reedline::{default_emacs_keybindings, ColumnarMenu, DefaultCompleter, Emacs, KeyCode, KeyModifiers, Reedline, ReedlineEvent, ReedlineMenu};
|
||||
|
||||
let commands = vec![
|
||||
"test".into(),
|
||||
@ -131,9 +131,23 @@ let commands = vec![
|
||||
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
|
||||
// Use the interactive menu to select options from the completer
|
||||
let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));
|
||||
// Set up the required keybindings
|
||||
let mut keybindings = default_emacs_keybindings();
|
||||
keybindings.add_binding(
|
||||
KeyModifiers::NONE,
|
||||
KeyCode::Tab,
|
||||
ReedlineEvent::UntilFound(vec![
|
||||
ReedlineEvent::Menu("completion_menu".to_string()),
|
||||
ReedlineEvent::MenuNext,
|
||||
]),
|
||||
);
|
||||
|
||||
let mut line_editor =
|
||||
Reedline::create().with_completer(completer).with_menu(ReedlineMenu::EngineCompleter(completion_menu));
|
||||
let edit_mode = Box::new(Emacs::new(keybindings));
|
||||
|
||||
let mut line_editor = Reedline::create()
|
||||
.with_completer(completer)
|
||||
.with_menu(ReedlineMenu::EngineCompleter(completion_menu))
|
||||
.with_edit_mode(edit_mode);
|
||||
```
|
||||
|
||||
### Integrate with `Hinter` for fish-style history autosuggestions
|
||||
|
@ -27,7 +27,7 @@ fn main() -> io::Result<()> {
|
||||
"hello world reedline".into(),
|
||||
"this is the reedline crate".into(),
|
||||
];
|
||||
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
|
||||
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands, 2));
|
||||
// Use the interactive menu to select options from the completer
|
||||
let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));
|
||||
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -96,7 +96,7 @@
|
||||
//! ```rust
|
||||
//! // Create a reedline object with tab completions support
|
||||
//!
|
||||
//! use reedline::{ColumnarMenu, DefaultCompleter, Reedline, ReedlineMenu};
|
||||
//! use reedline::{default_emacs_keybindings, ColumnarMenu, DefaultCompleter, Emacs, KeyCode, KeyModifiers, Reedline, ReedlineEvent, ReedlineMenu};
|
||||
//!
|
||||
//! let commands = vec![
|
||||
//! "test".into(),
|
||||
@ -107,9 +107,23 @@
|
||||
//! let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
|
||||
//! // Use the interactive menu to select options from the completer
|
||||
//! let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));
|
||||
//! // Set up the required keybindings
|
||||
//! let mut keybindings = default_emacs_keybindings();
|
||||
//! keybindings.add_binding(
|
||||
//! KeyModifiers::NONE,
|
||||
//! KeyCode::Tab,
|
||||
//! ReedlineEvent::UntilFound(vec![
|
||||
//! ReedlineEvent::Menu("completion_menu".to_string()),
|
||||
//! ReedlineEvent::MenuNext,
|
||||
//! ]),
|
||||
//! );
|
||||
//!
|
||||
//! let mut line_editor =
|
||||
//! Reedline::create().with_completer(completer).with_menu(ReedlineMenu::EngineCompleter(completion_menu));
|
||||
//! let edit_mode = Box::new(Emacs::new(keybindings));
|
||||
//!
|
||||
//! let mut line_editor = Reedline::create()
|
||||
//! .with_completer(completer)
|
||||
//! .with_menu(ReedlineMenu::EngineCompleter(completion_menu))
|
||||
//! .with_edit_mode(edit_mode);
|
||||
//! ```
|
||||
//!
|
||||
//! ## Integrate with [`Hinter`] for fish-style history autosuggestions
|
||||
|
Loading…
Reference in New Issue
Block a user