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
This commit is contained in:
nibon7 2022-10-23 22:18:26 +08:00 committed by GitHub
parent 17b2bcc125
commit ebca840d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 6 deletions

2
Cargo.lock generated
View File

@ -4072,7 +4072,7 @@ dependencies = [
[[package]] [[package]]
name = "reedline" name = "reedline"
version = "0.13.0" 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 = [ dependencies = [
"chrono", "chrono",
"crossterm 0.24.0", "crossterm 0.24.0",

View File

@ -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-table = { path = "./crates/nu-table", version = "0.70.1" }
nu-term-grid = { path = "./crates/nu-term-grid", 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" } 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" rayon = "1.5.1"
is_executable = "1.0.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 # 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 # changing versions in each sub-crate of the workspace is tedious
[patch.crates-io] [patch.crates-io]
# reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" } reedline = { git = "https://github.com/nushell/reedline.git", branch = "main" }

View File

@ -20,7 +20,7 @@ nu-protocol = { path = "../nu-protocol", version = "0.70.1" }
nu-utils = { path = "../nu-utils", version = "0.70.1" } nu-utils = { path = "../nu-utils", version = "0.70.1" }
nu-ansi-term = "0.46.0" nu-ansi-term = "0.46.0"
nu-color-config = { path = "../nu-color-config", version = "0.70.1" } 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" atty = "0.2.14"
chrono = "0.4.21" chrono = "0.4.21"

View File

@ -17,6 +17,7 @@ pub struct NushellPrompt {
default_vi_insert_prompt_indicator: Option<String>, default_vi_insert_prompt_indicator: Option<String>,
default_vi_normal_prompt_indicator: Option<String>, default_vi_normal_prompt_indicator: Option<String>,
default_multiline_indicator: Option<String>, default_multiline_indicator: Option<String>,
render_right_prompt_on_last_line: bool,
} }
impl Default for NushellPrompt { impl Default for NushellPrompt {
@ -34,6 +35,7 @@ impl NushellPrompt {
default_vi_insert_prompt_indicator: None, default_vi_insert_prompt_indicator: None,
default_vi_normal_prompt_indicator: None, default_vi_normal_prompt_indicator: None,
default_multiline_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; self.left_prompt_string = prompt_string;
} }
pub fn update_prompt_right(&mut self, prompt_string: Option<String>) { pub fn update_prompt_right(
&mut self,
prompt_string: Option<String>,
render_right_prompt_on_last_line: bool,
) {
self.right_prompt_string = prompt_string; 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<String>) { pub fn update_prompt_indicator(&mut self, prompt_indicator_string: Option<String>) {
@ -68,6 +75,7 @@ impl NushellPrompt {
prompt_indicator_string: Option<String>, prompt_indicator_string: Option<String>,
prompt_multiline_indicator_string: Option<String>, prompt_multiline_indicator_string: Option<String>,
prompt_vi: (Option<String>, Option<String>), prompt_vi: (Option<String>, Option<String>),
render_right_prompt_on_last_line: bool,
) { ) {
let (prompt_vi_insert_string, prompt_vi_normal_string) = prompt_vi; 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_insert_prompt_indicator = prompt_vi_insert_string;
self.default_vi_normal_prompt_indicator = prompt_vi_normal_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 { fn default_wrapped_custom_string(&self, str: String) -> String {
@ -162,4 +172,8 @@ impl Prompt for NushellPrompt {
prefix, history_search.term prefix, history_search.term
)) ))
} }
fn right_prompt_on_last_line(&self) -> bool {
self.render_right_prompt_on_last_line
}
} }

View File

@ -128,6 +128,7 @@ pub(crate) fn update_prompt<'prompt>(
prompt_indicator_string, prompt_indicator_string,
prompt_multiline_string, prompt_multiline_string,
(prompt_vi_insert_string, prompt_vi_normal_string), (prompt_vi_insert_string, prompt_vi_normal_string),
config.render_right_prompt_on_last_line,
); );
let ret_val = nu_prompt as &dyn Prompt; let ret_val = nu_prompt as &dyn Prompt;

View File

@ -88,7 +88,7 @@ unicode-segmentation = "1.8.0"
url = "2.2.1" url = "2.2.1"
uuid = { version = "1.1.2", features = ["v4"] } uuid = { version = "1.1.2", features = ["v4"] }
which = { version = "4.3.0", optional = true } 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"] } wax = { version = "0.5.0", features = ["diagnostics"] }
rusqlite = { version = "0.28.0", features = ["bundled"], optional = true } rusqlite = { version = "0.28.0", features = ["bundled"], optional = true }
sqlparser = { version = "0.23.0", features = ["serde"], optional = true } sqlparser = { version = "0.23.0", features = ["serde"], optional = true }

View File

@ -84,6 +84,7 @@ pub struct Config {
pub trim_strategy: TrimStrategy, pub trim_strategy: TrimStrategy,
pub show_banner: bool, pub show_banner: bool,
pub show_clickable_links_in_ls: bool, pub show_clickable_links_in_ls: bool,
pub render_right_prompt_on_last_line: bool,
} }
impl Default for Config { impl Default for Config {
@ -121,6 +122,7 @@ impl Default for Config {
trim_strategy: TRIM_STRATEGY_DEFAULT, trim_strategy: TRIM_STRATEGY_DEFAULT,
show_banner: true, show_banner: true,
show_clickable_links_in_ls: 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") 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 => { x => {
eprintln!("$config.{} is an unknown config setting", x) eprintln!("$config.{} is an unknown config setting", x)
} }

View File

@ -278,6 +278,7 @@ let-env config = {
} }
show_banner: true # true or false to enable or disable the banner 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. 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: { hooks: {
pre_prompt: [{ pre_prompt: [{