pub struct Reedline { /* private fields */ }
Expand description
Line editor engine
Example usage
use std::io;
use reedline::{Reedline, Signal, DefaultPrompt};
let mut line_editor = Reedline::create()?;
let prompt = DefaultPrompt::default();
let out = line_editor.read_line(&prompt).unwrap();
match out {
Signal::Success(content) => {
// process content
}
_ => {
eprintln!("Entry aborted!");
}
}
Implementations
sourceimpl Reedline
impl Reedline
sourcepub fn with_hinter(self, hinter: Box<dyn Hinter>) -> Self
pub fn with_hinter(self, hinter: Box<dyn Hinter>) -> Self
A builder to include a Hinter
in your instance of the Reedline engine
Example
//Cargo.toml
//[dependencies]
//nu-ansi-term = "*"
use std::io;
use {
nu_ansi_term::{Color, Style},
reedline::{DefaultHinter, Reedline},
};
let mut line_editor = Reedline::create()?.with_hinter(Box::new(
DefaultHinter::default()
.with_style(Style::new().italic().fg(Color::LightGray)),
));
sourcepub fn with_completer(self, completer: Box<dyn Completer>) -> Self
pub fn with_completer(self, completer: Box<dyn Completer>) -> Self
A builder to configure the tab completion
Example
// Create a reedline object with tab completions support
use std::io;
use reedline::{DefaultCompleter, Reedline};
let commands = vec![
"test".into(),
"hello world".into(),
"hello world reedline".into(),
"this is the reedline crate".into(),
];
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
let mut line_editor = Reedline::create()?.with_completer(completer);
sourcepub fn with_quick_completions(self, quick_completions: bool) -> Self
pub fn with_quick_completions(self, quick_completions: bool) -> Self
Turn on quick completions. These completions will auto-select if the completer ever narrows down to a single entry.
sourcepub fn with_partial_completions(self, partial_completions: bool) -> Self
pub fn with_partial_completions(self, partial_completions: bool) -> Self
Turn on partial completions. These completions will fill the buffer with the smallest common string from all the options
sourcepub fn with_ansi_colors(self, use_ansi_coloring: bool) -> Self
pub fn with_ansi_colors(self, use_ansi_coloring: bool) -> Self
A builder which enables or disables the use of ansi coloring in the prompt and in the command line syntax highlighting.
sourcepub fn with_animation(self, repaint: bool) -> Self
pub fn with_animation(self, repaint: bool) -> Self
A builder which enables or disables animations/automatic repainting of prompt.
If repaint
is true, every second the prompt will be repainted and the clock updates
sourcepub fn with_highlighter(self, highlighter: Box<dyn Highlighter>) -> Self
pub fn with_highlighter(self, highlighter: Box<dyn Highlighter>) -> Self
A builder that configures the highlighter for your instance of the Reedline engine
Example
// Create a reedline object with highlighter support
use std::io;
use reedline::{ExampleHighlighter, Reedline};
let commands = vec![
"test".into(),
"hello world".into(),
"hello world reedline".into(),
"this is the reedline crate".into(),
];
let mut line_editor =
Reedline::create()?.with_highlighter(Box::new(ExampleHighlighter::new(commands)));
sourcepub fn with_history(self, history: Box<dyn History>) -> Result<Reedline>
pub fn with_history(self, history: Box<dyn History>) -> Result<Reedline>
A builder which configures the history for your instance of the Reedline engine
Example
// Create a reedline object with history support, including history size limits
use std::io;
use reedline::{FileBackedHistory, Reedline};
let history = Box::new(
FileBackedHistory::with_file(5, "history.txt".into())
.expect("Error configuring history with file"),
);
let mut line_editor = Reedline::create()?
.with_history(history)
.expect("Error configuring reedline with history");
sourcepub fn with_validator(self, validator: Box<dyn Validator>) -> Self
pub fn with_validator(self, validator: Box<dyn Validator>) -> Self
A builder that configures the validator for your instance of the Reedline engine
Example
// Create a reedline object with validator support
use std::io;
use reedline::{DefaultValidator, Reedline};
let mut line_editor =
Reedline::create()?.with_validator(Box::new(DefaultValidator));
sourcepub fn with_edit_mode(self, edit_mode: Box<dyn EditMode>) -> Self
pub fn with_edit_mode(self, edit_mode: Box<dyn EditMode>) -> Self
A builder which configures the edit mode for your instance of the Reedline engine
A builder that appends a menu to the engine
sourcepub fn prompt_edit_mode(&self) -> PromptEditMode
pub fn prompt_edit_mode(&self) -> PromptEditMode
Returns the corresponding expected prompt style for the given edit mode
sourcepub fn print_history(&mut self) -> Result<()>
pub fn print_history(&mut self) -> Result<()>
Output the complete History
chronologically with numbering to the terminal
sourcepub fn read_line(&mut self, prompt: &dyn Prompt) -> Result<Signal>
pub fn read_line(&mut self, prompt: &dyn Prompt) -> Result<Signal>
Wait for input and provide the user with a specified Prompt
.
Returns a crossterm::Result
in which the Err
type is crossterm::ErrorKind
to distinguish I/O errors and the Ok
variant wraps a Signal
which
handles user inputs.
sourcepub fn clear_screen(&mut self) -> Result<()>
pub fn clear_screen(&mut self) -> Result<()>
Clear the screen by printing enough whitespace to start the prompt or other output back at the first line of the terminal.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Reedline
impl Send for Reedline
impl !Sync for Reedline
impl Unpin for Reedline
impl !UnwindSafe for Reedline
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more