项目作者: m-lima

项目描述 :
(Rust CLI line /rɪˈklaɪn/), a Rust line reader UTF-8 capable and with autosuggestions and autocompletions
高级语言: Rust
项目地址: git://github.com/m-lima/rucline.git
创建时间: 2020-04-09T10:17:37Z
项目社区:https://github.com/m-lima/rucline

开源协议:MIT License

下载


rucline

Github
MIT licensed
Cargo
Documentation

demo

Code for demo above available at examples/multiple.rs

Rucline, the Rust CLI Line reader, or simply “recline”, is a cross-platform, UTF-8 compatible
line reader that provides hooks for autocompletion and drop-down suggestion. It supports advanced
editing actions and hooks for customizing the line reader behavior making it more flexible
than simply reading from stdin.

Basic usage:

  1. use rucline::Outcome::Accepted;
  2. use rucline::prompt::{Builder, Prompt};
  3. if let Ok(Accepted(string)) = Prompt::from("What's you favorite website? ")
  4. // Add some tab completions (Optional)
  5. .suggester(vec![
  6. "https://www.rust-lang.org/",
  7. "https://docs.rs/",
  8. "https://crates.io/",
  9. ])
  10. //Block until value is ready
  11. .read_line()
  12. {
  13. println!("'{}' seems to be your favorite website", string);
  14. }

Actions

Rucline’s behavior can be customized and composed with use of actions.

There is a built-in set of default actions that will be executed upon user interaction.
These are meant to feel natural when coming from the default terminal, while also adding further
functionality and editing commands. For example, a few of the built-ins:

  • Tab: cycle through completions
  • Shift + Tab: cycle through completions in reverse
  • CTRL + W: delete the current word
  • CTRL + J: delete until the beginning of the word
  • CTRL + K: delete until the end of the word
  • CTRL + U: delete the whole line
  • CTRL + H: delete until the beggining of the line
  • CTRL + L: delete until the end of the line

See Action for the full default behavior specification

The default behavior can be customized by overriding user events with actions. Which
in turn can be serialized, stored, and loaded at run-time with the config-serde feature flag.

Overriding key bindings

  1. use rucline::Outcome::Accepted;
  2. use rucline::actions::{Action, Event, KeyBindings, KeyCode, Range};
  3. use rucline::prompt::{Builder, Prompt};
  4. let mut bindings = KeyBindings::new();
  5. // Accept the full suggestions if `right` is pressed
  6. bindings.insert(Event::from(KeyCode::Right), Action::Complete(Range::Line));
  7. if let Ok(Accepted(string)) = Prompt::from("What's you favorite website? ")
  8. // Add some likely values as completions
  9. .completer(vec![
  10. "https://www.rust-lang.org/",
  11. "https://docs.rs/",
  12. "https://crates.io/",
  13. ])
  14. // Set the new key bindings as an override
  15. .overrider(bindings)
  16. //Block until value is ready
  17. .read_line()
  18. {
  19. println!("'{}' seems to be your favorite website", string);
  20. }