项目作者: odd12258053

项目描述 :
Interaction is a minimal and a simple readline library for Rust.
高级语言: Rust
项目地址: git://github.com/odd12258053/interaction.git
创建时间: 2021-01-12T10:12:59Z
项目社区:https://github.com/odd12258053/interaction

开源协议:MIT License

下载


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:

  1. [dependencies]
  2. interaction = "0.3.4"

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

  1. $ cargo add interaction

Example

  1. use interaction::InteractionBuilder;
  2. use std::io;
  3. fn main() {
  4. let history_file = "./.example_history";
  5. let mut inter = InteractionBuilder::new()
  6. .prompt_str(";;>")
  7. .history_limit(5)
  8. .completion(|_input, completions| {
  9. completions.push(b"foo".to_vec());
  10. completions.push(b"bar".to_vec());
  11. })
  12. .load_history(history_file)
  13. .unwrap()
  14. .build();
  15. loop {
  16. match inter.line() {
  17. Ok(input) => {
  18. // write any code.
  19. }
  20. Err(e) if e.kind() == io::ErrorKind::Interrupted => {
  21. inter.save_history(history_file).unwrap();
  22. break;
  23. }
  24. Err(_) => {
  25. break;
  26. }
  27. }
  28. }
  29. }