Updated rustyline to 6.0.0. Added completion_mode config (#1289)

* Updated rustyline to 6.0.0. Added completion_mode config

* Formatted completion_mode config
This commit is contained in:
Jacob Gonzalez 2020-01-27 14:41:17 +11:00 committed by Jonathan Turner
parent af51a0e6f0
commit f8be1becf2
6 changed files with 36 additions and 19 deletions

4
Cargo.lock generated
View file

@ -3372,9 +3372,9 @@ dependencies = [
[[package]] [[package]]
name = "rustyline" name = "rustyline"
version = "5.0.6" version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a23cb19702a8d6afb6edb3c842386e680d4883760e0df74e6848e23c2a87a635" checksum = "de64be8eecbe428b6924f1d8430369a01719fbb182c26fa431ddbb0a95f5315d"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"dirs 2.0.2", "dirs 2.0.2",

View file

@ -61,7 +61,7 @@ nu-macros = { version = "0.8.0", path = "./crates/nu-macros" }
query_interface = "0.3.5" query_interface = "0.3.5"
typetag = "0.1.4" typetag = "0.1.4"
rustyline = "5.0.6" rustyline = "6.0.0"
chrono = { version = "0.4.10", features = ["serde"] } chrono = { version = "0.4.10", features = ["serde"] }
derive-new = "0.5.8" derive-new = "0.5.8"
prettytable-rs = "0.8.0" prettytable-rs = "0.8.0"

View file

@ -192,13 +192,14 @@ Here we use the variable `$it` to refer to the value being piped to the external
Nu has early support for configuring the shell. It currently supports the following settings: Nu has early support for configuring the shell. It currently supports the following settings:
| Variable | Type | Description | | Variable | Type | Description |
| ------------- | ------------- | ----- | | --------------- | -------------------- | -------------------------------------------------------------- |
| path | table of strings | PATH to use to find binaries | | path | table of strings | PATH to use to find binaries |
| env | row | the environment variables to pass to external commands | | env | row | the environment variables to pass to external commands |
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses | | ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
| table_mode | "light" or other | enable lightweight or normal tables | | table_mode | "light" or other | enable lightweight or normal tables |
| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode | | edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode |
| completion_mode | "circular" or "list" | changes completion type to "circular" (default) or "list" mode |
To set one of these variables, you can use `config --set`. For example: To set one of these variables, you can use `config --set`. For example:

View file

@ -29,13 +29,14 @@ Syntax: `config {flags}`
### Variables ### Variables
| Variable | Type | Description | | Variable | Type | Description |
| ---------- | ---------------- | ------------------------------------------------------- | | --------------- | -------------------- | -------------------------------------------------------------- |
| path | table of strings | PATH to use to find binaries | | path | table of strings | PATH to use to find binaries |
| env | row | the environment variables to pass to external commands | | env | row | the environment variables to pass to external commands |
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses | | ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
| table_mode | "light" or other | enable lightweight or normal tables | | table_mode | "light" or other | enable lightweight or normal tables |
| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode | | edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode |
| completion_mode | "circular" or "list" | changes completion type to "circular" (default) or "list" mode |
## Examples ## Examples

View file

@ -18,8 +18,8 @@ use nu_protocol::{Signature, UntaggedValue, Value};
use log::{debug, log_enabled, trace}; use log::{debug, log_enabled, trace};
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::{ use rustyline::{
self, config::Configurer, config::EditMode, At, Cmd, ColorMode, Config, Editor, KeyPress, self, config::Configurer, config::EditMode, At, Cmd, ColorMode, CompletionType, Config, Editor,
Movement, Word, KeyPress, Movement, Word,
}; };
use std::error::Error; use std::error::Error;
use std::io::{BufRead, BufReader, Write}; use std::io::{BufRead, BufReader, Write};
@ -419,6 +419,17 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
rl.set_edit_mode(edit_mode); rl.set_edit_mode(edit_mode);
let completion_mode = config::config(Tag::unknown())?
.get("completion_mode")
.map(|s| match s.value.expect_string() {
"list" => CompletionType::List,
"circular" => CompletionType::Circular,
_ => CompletionType::Circular,
})
.unwrap_or(CompletionType::Circular);
rl.set_completion_type(completion_mode);
let colored_prompt = { let colored_prompt = {
#[cfg(feature = "starship-prompt")] #[cfg(feature = "starship-prompt")]
{ {

View file

@ -204,3 +204,7 @@ impl Painter {
} }
impl rustyline::Helper for Helper {} impl rustyline::Helper for Helper {}
// Use default validator for normal single line behaviour
// In the future we can implement this for custom multi-line support
impl rustyline::validate::Validator for Helper {}