Crates.io | rucline |
lib.rs | rucline |
version | 0.4.0 |
source | src |
created_at | 2020-04-12 21:08:39.450717 |
updated_at | 2020-10-21 16:31:32.681131 |
description | A cross-platform, UTF-8 aware, autocompletion capable, tab suggestion supporting, color rendering line reader you can 'recline' on. |
homepage | |
repository | https://github.com/m-lima/rucline |
max_upload_size | |
id | 229458 |
size | 176,678 |
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 tab suggestion. It supports advanced
editing actions
and hooks for customizing the line reader behavior making it more flexible
than simply reading from stdin
.
use rucline::Outcome::Accepted;
use rucline::prompt::{Builder, Prompt};
if let Ok(Accepted(string)) = Prompt::from("What's you favorite website? ")
// Add some tab completions (Optional)
.suggester(vec![
"https://www.rust-lang.org/",
"https://docs.rs/",
"https://crates.io/",
])
//Block until value is ready
.read_line()
{
println!("'{}' seems to be your favorite website", string);
}
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 completionsShift
+ Tab
: cycle through completions in reverseCTRL
+ W
: delete the current wordCTRL
+ J
: delete until the beginning of the wordCTRL
+ K
: delete until the end of the wordCTRL
+ U
: delete the whole lineCTRL
+ H
: delete until the beggining of the lineCTRL
+ L
: delete until the end of the lineSee
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.
use rucline::Outcome::Accepted;
use rucline::actions::{Action, Event, KeyBindings, KeyCode, Range};
use rucline::prompt::{Builder, Prompt};
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(Accepted(string)) = Prompt::from("What's you favorite website? ")
// Add some likely values as completions
.completer(vec![
"https://www.rust-lang.org/",
"https://docs.rs/",
"https://crates.io/",
])
// Set the new key bindings as an override
.overrider(bindings)
//Block until value is ready
.read_line()
{
println!("'{}' seems to be your favorite website", string);
}