A readline replacement written in Rust

GitHub Crates.io docs.rs CI status Discord Twitch Status

Introduction

Reedline is a project to create a readline-style crate for Rust that supports many of the modern conveniences of CLIs, including syntax highlighting, completions, multiline support, Unicode support, and more.

Examples

Basic example

```rust,no_run // Create a default reedline object to handle user input

use reedline::{DefaultPrompt, Reedline, Signal};

fn main() { let mut line_editor = Reedline::create()?; let prompt = DefaultPrompt::default();

loop {
    let sig = line_editor.read_line(&prompt).unwrap();
    match sig {
        Signal::Success(buffer) => {
            println!("We processed: {}", buffer);
        }
        Signal::CtrlD | Signal::CtrlC => {
            line_editor.print_crlf().unwrap();
            break;
        }
        Signal::CtrlL => {
            line_editor.clear_screen().unwrap();
        }
    }
}

} ```

Integrate with custom Keybindings

```rust,no_run // Configure reedline with custom keybindings

//Cargo.toml // [dependencies] // crossterm = "*"

use { crossterm::event::{KeyCode, KeyModifiers}, reedline::{defaultemacskeybindings, EditCommand, Reedline}, };

let mut keybindings = defaultemacskeybindings(); keybindings.add_binding( KeyModifiers::ALT, KeyCode::Char('m'), vec![EditCommand::BackspaceWord], );

let mut lineeditor = Reedline::create()?.withkeybindings(keybindings); ```

Integrate with custom History

```rust,no_run // Create a reedline object with history support, including history size limits

use reedline::{FileBackedHistory, Reedline};

let history = Box::new( FileBackedHistory::withfile(5, "history.txt".into()) .expect("Error configuring history with file"), ); let mut lineeditor = Reedline::create()? .with_history(history) .expect("Error configuring reedline with history"); ```

Integrate with custom Highlighter

```rust,no_run // Create a reedline object with highlighter support

use reedline::{DefaultHighlighter, Reedline};

let commands = vec![ "test".into(), "hello world".into(), "hello world reedline".into(), "this is the reedline crate".into(), ]; let mut lineeditor = Reedline::create()?.withhighlighter(Box::new(DefaultHighlighter::new(commands))); ```

Integrate with custom Tab-Handler

```rust,no_run // Create a reedline object with tab completions support

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::newwithwordlen(commands.clone(), 2));

let mut lineeditor = Reedline::create()?.withcompletionactionhandler(Box::new( DefaultCompletionActionHandler::default().with_completer(completer), )); ```

Integrate with custom Hinter

```rust,no_run // Create a reedline object with in-line hint support

//Cargo.toml // [dependencies] // nu-ansi-term = "*"

use { nuansiterm::{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::newwithwordlen(commands.clone(), 2));

let mut lineeditor = Reedline::create()?.withhinter(Box::new( DefaultHinter::default() .withcompleter(completer) // or .withhistory() // .withinsideline() .with_style(Style::new().italic().fg(Color::LightGray)), )); ```

Integrate with custom line completion Validator

```rust,no_run // Create a reedline object with line completion validation support

use reedline::{DefaultValidator, Reedline};

let validator = Box::new(DefaultValidator);

let mut lineeditor = Reedline::create()?.withvalidator(validator); ```

Integrate with custom Edit Mode

```rust,no_run // Create a reedline object with custom edit mode

use reedline::{EditMode, Reedline};

let mut lineeditor = Reedline::create()?.withedit_mode( EditMode::ViNormal, // or EditMode::Emacs or EditMode::ViInsert ); ```

Are we prompt yet? (Development status)

This crate is currently under active development in JT's live-coding streams. If you want to see a feature, jump by the streams, file an issue or contribute a PR!

For a more detailed roadmap check out TODO.txt.

Join the vision discussion in the vision milestone list by contributing suggestions or voting.

Alternatives

For currently more mature Rust line editing check out: