[−][src]Crate rucline
Rucline (Rust CLI line /rɪˈklaɪn/) is a cross-platform, UTF-8 aware, advanced edtigin, autocompletion capable, tab suggestion supporting line reader you can "recline" on.
It provides advanced editing actions
for user input and customization of the line
reader.
It uses crossterm
as a backend to provide cross-platform support, and provides advanced
Basic usage:
use rucline::completion; use rucline::Prompt; if let Ok(Some(string)) = Prompt::new() // Add a prompt question .prompt("What's you favorite website? ") // Add some likely values as completions .completer(completion::Basic::new(&[ "https://www.rust-lang.org/", "https://docs.rs/", "https://crates.io/", ])) // Add some tab completions .suggester(completion::Basic::new(&[ "https://www.startpage.com/", "https://www.google.com/", ])) //Block until value is ready .read_line() { println!("'{}' seems to be your favorite website", string); }
Actions
Rucline allow advanced actions
for interacting with the Prompt
, but it
comes built-in with useful behavior. For example, a few of the build-ins:
Tab
: cycle through completionsShift
+Tab
: cycle through completions in reverseCTRL
+W
: delete the current workCTRL
+J
: delete the beginning of the wordCTRL
+K
: delete the end of the wordCTRL
+U
: delete the lineCTRL
+H
: delete the beggining of the lineCTRL
+L
: delete the end of the line
See Action
for the full default behavior
The behavior can be customized by overriding user events
with actions
. Which
in turn can be serialized, stored, and loaded at run-time.
Overriding key bindings
use rucline::{completion, Prompt}; use rucline::key_bindings::{Action, Event, KeyBindings, Range}; use crossterm::event::KeyCode; let mut bindings = KeyBindings::new(); // Accept the full suggestions if `right` is pressed bindings.insert(Event::from(KeyCode::Right), Action::Complete(Range::Line)); if let Ok(Some(string)) = Prompt::new() // Create a bold prompt .prompt("What's you favorite website? ") // Add some likely values as completions .completer(completion::Basic::new(&[ "https://www.rust-lang.org/", "https://docs.rs/", "https://crates.io/", ])) // Override the `right` key to always fill the full suggestions line .bindings(bindings) //Block until value is ready .read_line() { println!("'{}' seems to be your favorite website", string); }
Re-exports
pub use prompt::Prompt; |
Modules
completion | Provides completion methods for |
key_bindings | Provides mappings and actions to change the behavior of |
prompt |
Enums
ErrorKind | Wrapper for all errors that can occur in |