Module rustyline

Interactive line editor for CLI applications.


rustyline is a Rust implementation of readline, providing line editing, history, and completion for interactive command-line programs. It supports Emacs and Vi keybinding modes, persistent file-based history, and extensible completion and validation through helper traits.

The main type is DefaultEditor, which reads lines from the terminal with editing support.

Examples

Reading lines in a loop with history:

use rustyline::DefaultEditor;
use rustyline::error::ReadlineError;

let mut rl = DefaultEditor::new().unwrap();

loop {
    match rl.readline(">> ") {
        Ok(line) => {
            rl.add_history_entry(&line).unwrap();
            println!("You said: {}", line);
        }
        Err(ReadlineError::Interrupted) => {
            println!("Ctrl-C");
            break;
        }
        Err(ReadlineError::Eof) => {
            println!("Ctrl-D");
            break;
        }
        Err(err) => {
            eprintln!("Error: {:?}", err);
            break;
        }
    }
}

Modules

Structs

Traits

Type Aliases