#readline #cli

interaction

Interaction is a minimal and a simple readline library for Rust

5 releases

0.3.4 Jan 17, 2021
0.3.3 Jan 13, 2021
0.2.0 Jan 13, 2021
0.1.0 Jan 12, 2021

#144 in Command-line interface

Download history 5/week @ 2021-02-27 7/week @ 2021-03-06 14/week @ 2021-03-20 14/week @ 2021-03-27 14/week @ 2021-04-03 14/week @ 2021-04-10 4/week @ 2021-04-17 8/week @ 2021-04-24 7/week @ 2021-05-01 1/week @ 2021-05-08 7/week @ 2021-05-15 7/week @ 2021-06-05

57 downloads per month

MIT license

26KB
570 lines

Interaction

Crates.io Crates.io

Interaction is a minimal and a simple readline library for Rust.

Features

  • Single line editing mode
  • Multi line editing mode
  • Key bindings
  • History
  • Completion

Usage

Add this in your Cargo.toml:

[dependencies]
interaction = "0.3.4"

Or, if you installed cargo-edit, you run this command:

$ cargo add interaction

Example

use interaction::InteractionBuilder;
use std::io;

fn main() {
    let history_file = "./.example_history";
    let mut inter = InteractionBuilder::new()
        .prompt_str(";;>")
        .history_limit(5)
        .completion(|_input, completions| {
            completions.push(b"foo".to_vec());
            completions.push(b"bar".to_vec());
        })
        .load_history(history_file)
        .unwrap()
        .build();
    loop {
        match inter.line() {
            Ok(input) => {
                // write any code.
            }
            Err(e) if e.kind() == io::ErrorKind::Interrupted => {
                inter.save_history(history_file).unwrap();
                break;
            }
            Err(_) => {
                break;
            }
        }
    }
}

Dependencies

~105KB