nushell/crates/nu-cli/src/prompt.rs

211 lines
7.1 KiB
Rust
Raw Normal View History

overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
use crate::prompt_update::{
POST_PROMPT_MARKER, PRE_PROMPT_MARKER, VSCODE_POST_PROMPT_MARKER, VSCODE_PRE_PROMPT_MARKER,
};
use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
#[cfg(windows)]
use nu_utils::enable_vt_processing;
use reedline::{
DefaultPrompt, Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus,
PromptViMode,
2021-10-02 13:10:28 +00:00
};
use std::borrow::Cow;
2021-10-02 13:10:28 +00:00
/// Nushell prompt definition
#[derive(Clone)]
pub struct NushellPrompt {
overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
shell_integration_osc133: bool,
shell_integration_osc633: bool,
left_prompt_string: Option<String>,
right_prompt_string: Option<String>,
default_prompt_indicator: Option<String>,
default_vi_insert_prompt_indicator: Option<String>,
default_vi_normal_prompt_indicator: Option<String>,
default_multiline_indicator: Option<String>,
render_right_prompt_on_last_line: bool,
overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
engine_state: EngineState,
stack: Stack,
2021-10-02 13:10:28 +00:00
}
impl NushellPrompt {
overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
pub fn new(
shell_integration_osc133: bool,
shell_integration_osc633: bool,
engine_state: EngineState,
stack: Stack,
) -> NushellPrompt {
2021-10-02 13:10:28 +00:00
NushellPrompt {
overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
shell_integration_osc133,
shell_integration_osc633,
left_prompt_string: None,
right_prompt_string: None,
default_prompt_indicator: None,
default_vi_insert_prompt_indicator: None,
default_vi_normal_prompt_indicator: None,
default_multiline_indicator: None,
render_right_prompt_on_last_line: false,
overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
engine_state,
stack,
2021-10-02 13:10:28 +00:00
}
}
pub fn update_prompt_left(&mut self, prompt_string: Option<String>) {
self.left_prompt_string = prompt_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.render_right_prompt_on_last_line = render_right_prompt_on_last_line;
}
2021-10-02 13:10:28 +00:00
pub fn update_prompt_indicator(&mut self, prompt_indicator_string: Option<String>) {
self.default_prompt_indicator = prompt_indicator_string;
}
pub fn update_prompt_vi_insert(&mut self, prompt_vi_insert_string: Option<String>) {
self.default_vi_insert_prompt_indicator = prompt_vi_insert_string;
}
pub fn update_prompt_vi_normal(&mut self, prompt_vi_normal_string: Option<String>) {
2022-01-27 07:53:23 +00:00
self.default_vi_normal_prompt_indicator = prompt_vi_normal_string;
}
pub fn update_prompt_multiline(&mut self, prompt_multiline_indicator_string: Option<String>) {
self.default_multiline_indicator = prompt_multiline_indicator_string;
}
pub fn update_all_prompt_strings(
&mut self,
left_prompt_string: Option<String>,
right_prompt_string: Option<String>,
prompt_indicator_string: Option<String>,
prompt_multiline_indicator_string: Option<String>,
prompt_vi: (Option<String>, Option<String>),
render_right_prompt_on_last_line: bool,
) {
2022-01-27 07:53:23 +00:00
let (prompt_vi_insert_string, prompt_vi_normal_string) = prompt_vi;
2022-01-21 08:59:29 +00:00
self.left_prompt_string = left_prompt_string;
self.right_prompt_string = right_prompt_string;
self.default_prompt_indicator = prompt_indicator_string;
self.default_multiline_indicator = prompt_multiline_indicator_string;
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;
}
2021-10-02 13:10:28 +00:00
fn default_wrapped_custom_string(&self, str: String) -> String {
format!("({str})")
2021-10-02 13:10:28 +00:00
}
}
impl Prompt for NushellPrompt {
fn render_prompt_left(&self) -> Cow<str> {
#[cfg(windows)]
{
let _ = enable_vt_processing();
}
if let Some(prompt_string) = &self.left_prompt_string {
prompt_string.replace('\n', "\r\n").into()
} else {
let default = DefaultPrompt::default();
let prompt = default
.render_prompt_left()
.to_string()
Fix default prompt indicators (#9914) related to - https://github.com/nushell/nushell/pull/9907 # Description https://github.com/nushell/nushell/pull/9907 removed the front space from all `PROMPT_INDICATOR`s but this is not what the default behaviour of Nushell is, i.e. in `nu --no-config-file`. this PR - removes the space that is prepended by Nushell before the prompt indicator to match the `default_env.nu` - swaps INSERT and NORMAL in the Rust code to match the `:` and `>` respectively in `default_env.nu` ## :mag: try the changes > **Warning** > i had to comment out in my config all the `$env.PROMPT_INDICATOR... = ...` to avoid these variables to propagate to `cargo run -- -n` in either `cargo run -- -n` or `cargo run -- --config crates/nu-utils/src/sample_config/default_config.nu --env-config crates/nu-utils/src/sample_config/default_env.nu`, - see `/path/to/nushell>` as the prompt with the default `emacs` edit mode - run `$env.config.edit_mode = vi` - see `/path/to/nushell:` as the INSERT prompt in Vi mode - press Escape to go into NORMAL mode - see `/path/to/nushell>` as the NORMAL prompt in Vi mode - press I to go back into INSERT mode - see `/path/to/nushell:` as the INSERT prompt in Vi mode # User-Facing Changes the prompts in `nu --no-config-file` and `nu --config default_config.nu --env-config default_env.nu` should be the same :relieved: # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting
2023-08-04 16:47:46 +00:00
.replace('\n', "\r\n");
overhaul shell_integration to enable individual control over ansi escape sequences (#12629) # Description This PR overhauls the shell_integration system by allowing individual control over which ansi escape sequences are used. As we continue to broaden our support for more ansi escape sequences, we can't really have an all-or-nothing strategy. Some ansi escapes cause problems in certain operating systems or terminals. We should allow the user to choose which escapes they want. TODO: * Gather feedback * Should osc7, osc9_9 and osc633p be mutually exclusive? * Is the naming convention for these settings too nerdy osc2, osc7, etc? closes #11301 # User-Facing Changes shell_integration is no longer a boolean value. This is what is supported in the default_config.nu ```nushell shell_integration: { # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title osc2: true # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory osc7: true # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it osc8: true # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal osc9_9: false # osc133 is several escapes invented by Final Term which include the supported ones below. # 133;A - Mark prompt start # 133;B - Mark prompt end # 133;C - Mark pre-execution # 133;D;exit - Mark execution finished with exit code # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is osc133: true # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features # 633;A - Mark prompt start # 633;B - Mark prompt end # 633;C - Mark pre-execution # 633;D;exit - Mark execution finished with exit code # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal # and also helps with the run recent menu in vscode osc633: true # reset_application_mode is escape \x1b[?1l and was added to help ssh work better reset_application_mode: true } ``` # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2024-05-02 13:56:50 +00:00
if self.shell_integration_osc633 {
if self.stack.get_env_var(&self.engine_state, "TERM_PROGRAM")
== Some(Value::test_string("vscode"))
{
// We're in vscode and we have osc633 enabled
format!("{VSCODE_PRE_PROMPT_MARKER}{prompt}{VSCODE_POST_PROMPT_MARKER}").into()
} else {
// If we're in VSCode but we don't find the env var, just return the regular markers
format!("{PRE_PROMPT_MARKER}{prompt}{POST_PROMPT_MARKER}").into()
}
} else if self.shell_integration_osc133 {
fix shell integration markers (#11352) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> Fixes #11260 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Note: my issue description was a bit wrong. Issue one can't be reproduced without a config (`shell_integration` isn't on by default, so..), however the issue itself is still valid For issue 1, the default prompt needs to know about the `shell_integration` config, and the markers are added around the default prompt when that's on. For issue 2, this is actually related to transient prompts. When rendering, the markers weren't added like for normal prompts. After the fix the output do now contain the proper markers: Reproducing the minimum config here for convenience: ```nu $env.config = { show_banner: false shell_integration: true } # $env.PROMPT_COMMAND = {|| "> " } ``` For issue 1, the output looks like: ``` [2.3490236,"o","\u001b[?25l\u001b[21;1H\u001b[21;1H\u001b[J\u001b[38;5;10m\u001b]133;A\u001b\\/home/steven\u001b]133;B\u001b\\\u001b[38;5;14m\u001b[38;5;5m\u001b7\u001b[21;84H12/16/2023 03:31:58 PM\u001b8\u001b[0m\u001b[0m\u001b[1;36mecho\u001b[0m\u001b7\u001b8\u001b[?25h"] [2.5676293,"o","\u001b[6n"] [2.571353,"o","\u001b[?25l\u001b[21;1H\u001b[21;1H\u001b[J\u001b[38;5;10m\u001b]133;A\u001b\\\u001b]133;A\u001b\\/home/steven\u001b]133;B\u001b\\\u001b]133;B\u001b\\\u001b[38;5;14m\u001b[38;5;5m\u001b7\u001b[21;84H12/16/2023 03:31:59 PM\u001b8\u001b[0m\u001b[0m\u001b[1;36mecho\u001b[0m\u001b7\u001b8\u001b[?25h\u001b[21;1H\r\n\u001b[21;1H"] [2.571436,"o","\u001b[?2004l"] [2.5714657,"o","\u001b]133;C\u001b\\"] ``` in line 3, where enter is pressed, `133 A` and `B` are present. Same for issue 2 (uncomment the `PROMPT_COMMAND` line in the config): ``` [1.9585224,"o","\u001b[?25l\u001b[21;1H\u001b[21;1H\u001b[J\u001b[38;5;10m\u001b]133;A\u001b\\> \u001b]133;B\u001b\\\u001b[38;5;14m\u001b[38;5;5m\u001b7\u001b[21;84H12/16/2023 03:32:15 PM\u001b8\u001b[0m\u001b[0m\u001b[1;36mecho\u001b[0m\u001b7\u001b8\u001b[?25h"] [2.453972,"o","\u001b[6n"] [2.4585786,"o","\u001b[?25l\u001b[21;1H\u001b[21;1H\u001b[J\u001b[38;5;10m\u001b]133;A\u001b\\\u001b]133;A\u001b\\> \u001b]133;B\u001b\\\u001b]133;B\u001b\\\u001b[38;5;14m\u001b[38;5;5m\u001b7\u001b[21;84H12/16/2023 03:32:15 PM\u001b8\u001b[0m\u001b[0m\u001b[1;36mecho\u001b[0m\u001b7\u001b8\u001b[?25h\u001b[21;1H\r\n\u001b[21;1H\u001b[?2004l\u001b]133;C\u001b\\\r\n\u001b]133;D;0\u001b\\\u001b]7;file://Aostro-5468/home/steven\u001b\\\u001b]2;~\u0007\u001b[?1l"] [2.4669976,"o","\u001b[?2004h\u001b[6n"] [2.4703515,"o","\u001b[6n"] [2.4736586,"o","\u001b[?25l\u001b[21;1H\u001b[21;1H\u001b[J\u001b[38;5;10m\u001b]133;A\u001b\\> \u001b]133;B\u001b\\\u001b[38;5;14m\u001b[38;5;5m\u001b7\u001b[21;84H12/16/2023 03:32:15 PM\u001b8\u001b[0m\u001b[0m\u001b7\u001b8\u001b[?25h"] ``` # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> None user facing changes other than that prompt markers are working # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-12-17 02:12:34 +00:00
format!("{PRE_PROMPT_MARKER}{prompt}{POST_PROMPT_MARKER}").into()
} else {
prompt.into()
}
}
}
fn render_prompt_right(&self) -> Cow<str> {
if let Some(prompt_string) = &self.right_prompt_string {
prompt_string.replace('\n', "\r\n").into()
2022-01-04 19:49:04 +00:00
} else {
let default = DefaultPrompt::default();
2022-01-27 07:53:23 +00:00
default
.render_prompt_right()
.to_string()
.replace('\n', "\r\n")
2022-01-27 07:53:23 +00:00
.into()
2022-01-04 19:49:04 +00:00
}
2021-10-02 13:10:28 +00:00
}
fn render_prompt_indicator(&self, edit_mode: PromptEditMode) -> Cow<str> {
match edit_mode {
PromptEditMode::Default => match &self.default_prompt_indicator {
2023-01-21 13:47:00 +00:00
Some(indicator) => indicator,
None => "> ",
2023-01-21 13:47:00 +00:00
}
.into(),
PromptEditMode::Emacs => match &self.default_prompt_indicator {
2023-01-21 13:47:00 +00:00
Some(indicator) => indicator,
None => "> ",
2023-01-21 13:47:00 +00:00
}
.into(),
2021-10-02 13:10:28 +00:00
PromptEditMode::Vi(vi_mode) => match vi_mode {
PromptViMode::Normal => match &self.default_vi_normal_prompt_indicator {
2023-01-21 13:47:00 +00:00
Some(indicator) => indicator,
Fix default prompt indicators (#9914) related to - https://github.com/nushell/nushell/pull/9907 # Description https://github.com/nushell/nushell/pull/9907 removed the front space from all `PROMPT_INDICATOR`s but this is not what the default behaviour of Nushell is, i.e. in `nu --no-config-file`. this PR - removes the space that is prepended by Nushell before the prompt indicator to match the `default_env.nu` - swaps INSERT and NORMAL in the Rust code to match the `:` and `>` respectively in `default_env.nu` ## :mag: try the changes > **Warning** > i had to comment out in my config all the `$env.PROMPT_INDICATOR... = ...` to avoid these variables to propagate to `cargo run -- -n` in either `cargo run -- -n` or `cargo run -- --config crates/nu-utils/src/sample_config/default_config.nu --env-config crates/nu-utils/src/sample_config/default_env.nu`, - see `/path/to/nushell>` as the prompt with the default `emacs` edit mode - run `$env.config.edit_mode = vi` - see `/path/to/nushell:` as the INSERT prompt in Vi mode - press Escape to go into NORMAL mode - see `/path/to/nushell>` as the NORMAL prompt in Vi mode - press I to go back into INSERT mode - see `/path/to/nushell:` as the INSERT prompt in Vi mode # User-Facing Changes the prompts in `nu --no-config-file` and `nu --config default_config.nu --env-config default_env.nu` should be the same :relieved: # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting
2023-08-04 16:47:46 +00:00
None => "> ",
},
PromptViMode::Insert => match &self.default_vi_insert_prompt_indicator {
2023-01-21 13:47:00 +00:00
Some(indicator) => indicator,
Fix default prompt indicators (#9914) related to - https://github.com/nushell/nushell/pull/9907 # Description https://github.com/nushell/nushell/pull/9907 removed the front space from all `PROMPT_INDICATOR`s but this is not what the default behaviour of Nushell is, i.e. in `nu --no-config-file`. this PR - removes the space that is prepended by Nushell before the prompt indicator to match the `default_env.nu` - swaps INSERT and NORMAL in the Rust code to match the `:` and `>` respectively in `default_env.nu` ## :mag: try the changes > **Warning** > i had to comment out in my config all the `$env.PROMPT_INDICATOR... = ...` to avoid these variables to propagate to `cargo run -- -n` in either `cargo run -- -n` or `cargo run -- --config crates/nu-utils/src/sample_config/default_config.nu --env-config crates/nu-utils/src/sample_config/default_env.nu`, - see `/path/to/nushell>` as the prompt with the default `emacs` edit mode - run `$env.config.edit_mode = vi` - see `/path/to/nushell:` as the INSERT prompt in Vi mode - press Escape to go into NORMAL mode - see `/path/to/nushell>` as the NORMAL prompt in Vi mode - press I to go back into INSERT mode - see `/path/to/nushell:` as the INSERT prompt in Vi mode # User-Facing Changes the prompts in `nu --no-config-file` and `nu --config default_config.nu --env-config default_env.nu` should be the same :relieved: # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting
2023-08-04 16:47:46 +00:00
None => ": ",
},
2023-01-21 13:47:00 +00:00
}
.into(),
2021-10-02 13:10:28 +00:00
PromptEditMode::Custom(str) => self.default_wrapped_custom_string(str).into(),
}
}
fn render_prompt_multiline_indicator(&self) -> Cow<str> {
match &self.default_multiline_indicator {
2023-01-21 13:47:00 +00:00
Some(indicator) => indicator,
None => "::: ",
}
2023-01-21 13:47:00 +00:00
.into()
2021-10-02 13:10:28 +00:00
}
fn render_prompt_history_search_indicator(
&self,
history_search: PromptHistorySearch,
) -> Cow<str> {
let prefix = match history_search.status {
PromptHistorySearchStatus::Passing => "",
PromptHistorySearchStatus::Failing => "failing ",
};
Cow::Owned(format!(
"({}reverse-search: {})",
prefix, history_search.term
))
}
fn right_prompt_on_last_line(&self) -> bool {
self.render_right_prompt_on_last_line
}
2021-10-02 13:10:28 +00:00
}