Skip to content

Latest commit

 

History

History
79 lines (57 loc) · 2.07 KB

README.md

File metadata and controls

79 lines (57 loc) · 2.07 KB

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 = Box::new(DefaultPrompt::default());

loop {
    let sig = line_editor.read_line(prompt.clone()).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: