https://github.com/odd12258053/interaction
Interaction is a minimal and a simple readline library for Rust.
https://github.com/odd12258053/interaction
cli crates multi readline readline-library rust
Last synced: 8 months ago
JSON representation
Interaction is a minimal and a simple readline library for Rust.
- Host: GitHub
- URL: https://github.com/odd12258053/interaction
- Owner: odd12258053
- License: mit
- Created: 2021-01-12T10:12:59.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-17T12:24:02.000Z (about 5 years ago)
- Last Synced: 2025-06-03T06:00:34.951Z (9 months ago)
- Topics: cli, crates, multi, readline, readline-library, rust
- Language: Rust
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Interaction

[](https://crates.io/crates/interaction)
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`:
```toml
[dependencies]
interaction = "0.3.4"
```
Or, if you installed [cargo-edit](https://github.com/killercup/cargo-edit), you run this command:
```sh
$ cargo add interaction
```
# Example
```rust
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;
}
}
}
}
```