diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index b7d48c4f61..4cf9508a85 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -555,6 +555,13 @@ pub async fn cli() -> Result<(), Box> { rl.set_edit_mode(edit_mode); + let key_timeout = config::config(Tag::unknown())? + .get("key_timeout") + .map(|s| s.value.expect_int()) + .unwrap_or(1); + + rl.set_keyseq_timeout(key_timeout as i32); + let completion_mode = config::config(Tag::unknown())? .get("completion_mode") .map(|s| match s.value.expect_string() { diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index 286ae4cb7f..202637a0d6 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -20,6 +20,7 @@ use indexmap::IndexMap; use nu_errors::ShellError; use nu_source::{AnchorLocation, HasSpan, Span, Spanned, Tag}; use num_bigint::BigInt; +use num_traits::ToPrimitive; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use std::time::SystemTime; @@ -122,6 +123,19 @@ impl UntaggedValue { } } + /// Expect this value to be an integer and return it + pub fn expect_int(&self) -> i64 { + let big_int = match self { + UntaggedValue::Primitive(Primitive::Int(int)) => Some(int), + _ => None, + }; + + match big_int.and_then(|i| i.to_i64()) { + Some(i) => i, + _ => panic!("expect_int assumes that the value must be a integer"), + } + } + /// Helper for creating row values pub fn row(entries: IndexMap) -> UntaggedValue { UntaggedValue::Row(entries.into()) diff --git a/docs/commands/config.md b/docs/commands/config.md index 1cc3781297..8e1880f375 100644 --- a/docs/commands/config.md +++ b/docs/commands/config.md @@ -29,14 +29,15 @@ Syntax: `config {flags}` ### Variables -| Variable | Type | Description | -| --------------- | -------------------- | -------------------------------------------------------------- | -| path | table of strings | PATH to use to find binaries | -| env | row | the environment variables to pass to external commands | -| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses | -| table_mode | "light" or other | enable lightweight or normal tables | -| 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 | +| Variable | Type | Description | +| --------------- | ---------------------- | -------------------------------------------------------------- | +| path | table of strings | PATH to use to find binaries | +| env | row | the environment variables to pass to external commands | +| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses | +| table_mode | "light" or other | enable lightweight or normal tables | +| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode | +| key_timeout | integer (milliseconds) | vi: the delay to wait for a longer key sequence after ESC | +| completion_mode | "circular" or "list" | changes completion type to "circular" (default) or "list" mode | ## Examples