Struct reedline::Reedline [−][src]
pub struct Reedline { /* fields omitted */ }
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
A builder to include the 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::{DefaultCompleter, DefaultHinter, 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_hinter(Box::new(
DefaultHinter::default()
.with_completer(completer) // or .with_history()
// .with_inside_line()
.with_style(Style::new().italic().fg(Color::LightGray)),
));
pub fn with_completion_action_handler(
self,
tab_handler: Box<dyn ComplationActionHandler>
) -> Reedline
pub fn with_completion_action_handler(
self,
tab_handler: Box<dyn ComplationActionHandler>
) -> Reedline
A builder to configure the completion action handler to use in your instance of the reedline engine
Example
// Create a reedline object with tab completions support
use std::io;
use reedline::{DefaultCompleter, DefaultCompletionActionHandler, 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_completion_action_handler(Box::new(
DefaultCompletionActionHandler::default().with_completer(completer),
));
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::{DefaultHighlighter, 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(DefaultHighlighter::new(commands)));
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");
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));
A builder which configures the edit mode for your instance of the Reedline engine
Returns the corresponding expected prompt style for the given edit mode
Output the complete History
chronologically with numbering to the terminal
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.
Writes msg
to the terminal with a following carriage return and newline
Goes to the beginning of the next line
Also works in raw mode
Clear the screen by printing enough whitespace to start the prompt or other output back at the first line of the terminal.