https://github.com/m-lima/rucline
(Rust CLI line /rɪˈklaɪn/), a Rust line reader UTF-8 capable and with autosuggestions and autocompletions
https://github.com/m-lima/rucline
autocompletions rust rust-cli
Last synced: 3 months ago
JSON representation
(Rust CLI line /rɪˈklaɪn/), a Rust line reader UTF-8 capable and with autosuggestions and autocompletions
- Host: GitHub
- URL: https://github.com/m-lima/rucline
- Owner: m-lima
- License: mit
- Created: 2020-04-09T10:17:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-20T18:49:10.000Z (almost 3 years ago)
- Last Synced: 2025-01-30T08:08:03.005Z (12 months ago)
- Topics: autocompletions, rust, rust-cli
- Language: Rust
- Homepage:
- Size: 218 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rucline
[](https://github.com/m-lima/rucline/actions?workflow=build)
[](LICENSE)
[](https://crates.io/crates/rucline)
[](https://docs.rs/rucline)

> Code for demo above available at [examples/multiple.rs](../../blob/master/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:
```rust
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);
}
```
## 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`][`actions`] 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
```rust
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);
}
```
[`actions`]: ../../blob/master/src/actions.rs
[`events`]: ../../blob/master/src/actions.rs