pub struct Reedline { /* private fields */ }
Expand description

Line editor engine

Example usage

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

Create a new Reedline engine with a local History that is not synchronized to a file.

Return the previously generated history session id

A builder to include a Hinter in your instance of the Reedline engine

Example
//Cargo.toml
//[dependencies]
//nu-ansi-term = "*"
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)),
));

Remove current Hinter

A builder to configure the tab completion

Example
// Create a reedline object with tab completions support

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);

Turn on quick completions. These completions will auto-select if the completer ever narrows down to a single entry.

Turn on partial completions. These completions will fill the buffer with the smallest common string from all the options

A builder which enables or disables the use of ansi coloring in the prompt and in the command line syntax highlighting.

A builder that configures the highlighter for your instance of the Reedline engine

Example
// Create a reedline object with highlighter support

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)));

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 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);

A builder that configures the validator for your instance of the Reedline engine

Example
// Create a reedline object with validator support

use reedline::{DefaultValidator, Reedline};

let mut line_editor =
Reedline::create().with_validator(Box::new(DefaultValidator));

A builder that configures the text editor used to edit the line buffer

Example
// Create a reedline object with vim as editor

use reedline::{DefaultValidator, Reedline};

let mut line_editor =
Reedline::create().with_buffer_editor("vim".into(), "nu".into());

Remove the current Validator

A builder which configures the edit mode for your instance of the Reedline engine

A builder that appends a menu to the engine

A builder that clears the list of menus added to the engine

Returns the corresponding expected prompt style for the given edit mode

Output the complete History chronologically with numbering to the terminal

Read-only view of the history

Update the underlying History to/from disk

Check if any commands have been run.

When no commands have been run, calling Self::update_last_command_context does not make sense and is guaranteed to fail with a “No command run” error.

update the last history item with more information

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.

Returns the current contents of the input buffer.

Clear the screen by printing enough whitespace to start the prompt or other output back at the first line of the terminal.

Clear the screen and the scollback buffer of the terminal

Executes EditCommand actions by modifying the internal state appropriately. Does not output itself.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.