From ebca840d91e81c070800e39cea07325d25b4fc54 Mon Sep 17 00:00:00 2001 From: nibon7 Date: Sun, 23 Oct 2022 22:18:26 +0800 Subject: [PATCH] Add support to render right prompt on last line of the prompt (#6781) * Add support to render right prompt on last line of the prompt * reset reedline to main branch * update reedline to fix right prompt to be rendered correctly * reset reedline to main branch again --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- crates/nu-cli/Cargo.toml | 2 +- crates/nu-cli/src/prompt.rs | 16 +++++++++++++++- crates/nu-cli/src/prompt_update.rs | 1 + crates/nu-command/Cargo.toml | 2 +- crates/nu-protocol/src/config.rs | 9 +++++++++ .../nu-utils/src/sample_config/default_config.nu | 1 + 8 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cd194ef1b..9674caaf17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4072,7 +4072,7 @@ dependencies = [ [[package]] name = "reedline" version = "0.13.0" -source = "git+https://github.com/dandavison/reedline.git?branch=tab-inline-completion#5211f420e803ad8ea0479084155576b6d13ca40f" +source = "git+https://github.com/nushell/reedline.git?branch=main#39e6bc8eb3324b560479d097c7ab42d1ba45ec90" dependencies = [ "chrono", "crossterm 0.24.0", diff --git a/Cargo.toml b/Cargo.toml index 89045ef606..304c9cd55f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ nu-system = { path = "./crates/nu-system", version = "0.70.1" } nu-table = { path = "./crates/nu-table", version = "0.70.1" } nu-term-grid = { path = "./crates/nu-term-grid", version = "0.70.1" } nu-utils = { path = "./crates/nu-utils", version = "0.70.1" } -reedline = { git = "https://github.com/dandavison/reedline.git", branch="tab-inline-completion", features = ["bashisms", "sqlite"]} +reedline = { version = "0.13.0", features = ["bashisms", "sqlite"]} rayon = "1.5.1" is_executable = "1.0.1" @@ -130,4 +130,4 @@ path = "src/main.rs" # To use a development version of a dependency please use a global override here # changing versions in each sub-crate of the workspace is tedious [patch.crates-io] -# reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" } +reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" } diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index ec139cb070..94631f80bb 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -20,7 +20,7 @@ nu-protocol = { path = "../nu-protocol", version = "0.70.1" } nu-utils = { path = "../nu-utils", version = "0.70.1" } nu-ansi-term = "0.46.0" nu-color-config = { path = "../nu-color-config", version = "0.70.1" } -reedline = { git = "https://github.com/dandavison/reedline.git", branch="tab-inline-completion", features = ["bashisms", "sqlite"]} +reedline = { version = "0.13.0", features = ["bashisms", "sqlite"]} atty = "0.2.14" chrono = "0.4.21" diff --git a/crates/nu-cli/src/prompt.rs b/crates/nu-cli/src/prompt.rs index d2340e0492..17b6c65322 100644 --- a/crates/nu-cli/src/prompt.rs +++ b/crates/nu-cli/src/prompt.rs @@ -17,6 +17,7 @@ pub struct NushellPrompt { default_vi_insert_prompt_indicator: Option, default_vi_normal_prompt_indicator: Option, default_multiline_indicator: Option, + render_right_prompt_on_last_line: bool, } impl Default for NushellPrompt { @@ -34,6 +35,7 @@ impl NushellPrompt { default_vi_insert_prompt_indicator: None, default_vi_normal_prompt_indicator: None, default_multiline_indicator: None, + render_right_prompt_on_last_line: false, } } @@ -41,8 +43,13 @@ impl NushellPrompt { self.left_prompt_string = prompt_string; } - pub fn update_prompt_right(&mut self, prompt_string: Option) { + pub fn update_prompt_right( + &mut self, + prompt_string: Option, + render_right_prompt_on_last_line: bool, + ) { self.right_prompt_string = prompt_string; + self.render_right_prompt_on_last_line = render_right_prompt_on_last_line; } pub fn update_prompt_indicator(&mut self, prompt_indicator_string: Option) { @@ -68,6 +75,7 @@ impl NushellPrompt { prompt_indicator_string: Option, prompt_multiline_indicator_string: Option, prompt_vi: (Option, Option), + render_right_prompt_on_last_line: bool, ) { let (prompt_vi_insert_string, prompt_vi_normal_string) = prompt_vi; @@ -78,6 +86,8 @@ impl NushellPrompt { self.default_vi_insert_prompt_indicator = prompt_vi_insert_string; self.default_vi_normal_prompt_indicator = prompt_vi_normal_string; + + self.render_right_prompt_on_last_line = render_right_prompt_on_last_line; } fn default_wrapped_custom_string(&self, str: String) -> String { @@ -162,4 +172,8 @@ impl Prompt for NushellPrompt { prefix, history_search.term )) } + + fn right_prompt_on_last_line(&self) -> bool { + self.render_right_prompt_on_last_line + } } diff --git a/crates/nu-cli/src/prompt_update.rs b/crates/nu-cli/src/prompt_update.rs index 1adefd96c6..c1ff23f1bf 100644 --- a/crates/nu-cli/src/prompt_update.rs +++ b/crates/nu-cli/src/prompt_update.rs @@ -128,6 +128,7 @@ pub(crate) fn update_prompt<'prompt>( prompt_indicator_string, prompt_multiline_string, (prompt_vi_insert_string, prompt_vi_normal_string), + config.render_right_prompt_on_last_line, ); let ret_val = nu_prompt as &dyn Prompt; diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 984c31d8f2..fbc4ece19c 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -88,7 +88,7 @@ unicode-segmentation = "1.8.0" url = "2.2.1" uuid = { version = "1.1.2", features = ["v4"] } which = { version = "4.3.0", optional = true } -reedline = { git = "https://github.com/dandavison/reedline.git", branch="tab-inline-completion", features = ["bashisms", "sqlite"]} +reedline = { version = "0.13.0", features = ["bashisms", "sqlite"]} wax = { version = "0.5.0", features = ["diagnostics"] } rusqlite = { version = "0.28.0", features = ["bundled"], optional = true } sqlparser = { version = "0.23.0", features = ["serde"], optional = true } diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index bf5f5574eb..45a2456597 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -84,6 +84,7 @@ pub struct Config { pub trim_strategy: TrimStrategy, pub show_banner: bool, pub show_clickable_links_in_ls: bool, + pub render_right_prompt_on_last_line: bool, } impl Default for Config { @@ -121,6 +122,7 @@ impl Default for Config { trim_strategy: TRIM_STRATEGY_DEFAULT, show_banner: true, show_clickable_links_in_ls: true, + render_right_prompt_on_last_line: false, } } } @@ -431,6 +433,13 @@ impl Value { eprintln!("$config.show_clickable_links_in_ls is not a bool") } } + "render_right_prompt_on_last_line" => { + if let Ok(b) = value.as_bool() { + config.render_right_prompt_on_last_line = b; + } else { + eprintln!("$config.render_right_prompt_on_last_line is not a bool") + } + } x => { eprintln!("$config.{} is an unknown config setting", x) } diff --git a/crates/nu-utils/src/sample_config/default_config.nu b/crates/nu-utils/src/sample_config/default_config.nu index b8e0ec8969..a9e15f2a37 100644 --- a/crates/nu-utils/src/sample_config/default_config.nu +++ b/crates/nu-utils/src/sample_config/default_config.nu @@ -278,6 +278,7 @@ let-env config = { } show_banner: true # true or false to enable or disable the banner show_clickable_links_in_ls: true # true or false to enable or disable clickable links in the ls listing. your terminal has to support links. + render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt. hooks: { pre_prompt: [{