Skip to content

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

License

Notifications You must be signed in to change notification settings

odd12258053/interaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
            }
        }
    }
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages