A readline replacement written in Rust
Go to file
JT ad33d8e0f3
Add more support for vi (#59)
* Add more support for vi

* Fix doctests
2021-06-17 11:27:12 +12:00
.github/workflows Let's try adding a ci (#24) 2021-03-17 14:03:17 +13:00
assets/sample_docs syntax highlighting fileio (#56) 2021-06-16 08:02:29 +12:00
src Add more support for vi (#59) 2021-06-17 11:27:12 +12:00
.gitignore Implement primitive word-jumping 2021-03-01 08:36:19 +01:00
Cargo.lock syntax highlighting fileio (#56) 2021-06-16 08:02:29 +12:00
Cargo.toml syntax highlighting fileio (#56) 2021-06-16 08:02:29 +12:00
LICENSE Initial commit 2021-02-28 22:42:07 +13:00
README.md Add vi mode (#57) 2021-06-15 11:03:57 +12:00
TODO.txt Add more support for vi (#59) 2021-06-17 11:27:12 +12:00

A readline replacement written in Rust

Example (Simple REPL)

// Create a default reedline to handle user input

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

let mut line_editor = Reedline::new();
let prompt = DefaultPrompt::default();

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

Keybindings

// Configure reedline with custom keybindings

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

let mut line_editor = Reedline::new()
    .with_keybindings(keybindings);

History

// Create a reedline with history support, including history size limits

let mut line_editor = Reedline::new()
    .with_history("history.txt", 5)?

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!

  • Basic unicode grapheme aware cursor editing.
  • Configurable prompt
  • Basic EMACS-style editing shortcuts.
  • Advanced multiline unicode aware editing.
  • Configurable keybindings.
  • Basic system integration with clipboard or optional stored history file.
  • Content aware highlighting or validation.
  • Autocompletion.

For a more detailed roadmap check out TODO.txt.

Alternatives

For currently more mature Rust line editing check out: