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,
|
|
|
|
};
|
2022-07-11 21:01:49 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
use nu_utils::enable_vt_processing;
|
Add `command_prelude` module (#12291)
# Description
When implementing a `Command`, one must also import all the types
present in the function signatures for `Command`. This makes it so that
we often import the same set of types in each command implementation
file. E.g., something like this:
```rust
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
ShellError, Signature, Span, Type, Value,
};
```
This PR adds the `nu_engine::command_prelude` module which contains the
necessary and commonly used types to implement a `Command`:
```rust
// command_prelude.rs
pub use crate::CallExt;
pub use nu_protocol::{
ast::{Call, CellPath},
engine::{Command, EngineState, Stack},
record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, IntoSpanned,
PipelineData, Record, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
```
This should reduce the boilerplate needed to implement a command and
also gives us a place to track the breadth of the `Command` API. I tried
to be conservative with what went into the prelude modules, since it
might be hard/annoying to remove items from the prelude in the future.
Let me know if something should be included or excluded.
2024-03-26 21:17:30 +00:00
|
|
|
use reedline::{
|
|
|
|
DefaultPrompt, Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus,
|
|
|
|
PromptViMode,
|
2021-10-02 13:10:28 +00:00
|
|
|
};
|
Add `command_prelude` module (#12291)
# Description
When implementing a `Command`, one must also import all the types
present in the function signatures for `Command`. This makes it so that
we often import the same set of types in each command implementation
file. E.g., something like this:
```rust
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData,
ShellError, Signature, Span, Type, Value,
};
```
This PR adds the `nu_engine::command_prelude` module which contains the
necessary and commonly used types to implement a `Command`:
```rust
// command_prelude.rs
pub use crate::CallExt;
pub use nu_protocol::{
ast::{Call, CellPath},
engine::{Command, EngineState, Stack},
record, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, IntoSpanned,
PipelineData, Record, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
};
```
This should reduce the boilerplate needed to implement a command and
also gives us a place to track the breadth of the `Command` API. I tried
to be conservative with what went into the prelude modules, since it
might be hard/annoying to remove items from the prelude in the future.
Let me know if something should be included or excluded.
2024-03-26 21:17:30 +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,
|
2022-01-06 12:57:55 +00:00
|
|
|
left_prompt_string: Option<String>,
|
|
|
|
right_prompt_string: Option<String>,
|
2022-03-31 05:22:55 +00:00
|
|
|
default_prompt_indicator: Option<String>,
|
|
|
|
default_vi_insert_prompt_indicator: Option<String>,
|
|
|
|
default_vi_normal_prompt_indicator: Option<String>,
|
|
|
|
default_multiline_indicator: Option<String>,
|
2022-10-23 14:18:26 +00:00
|
|
|
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,
|
2022-01-06 12:57:55 +00:00
|
|
|
left_prompt_string: None,
|
|
|
|
right_prompt_string: None,
|
2022-03-31 05:22:55 +00:00
|
|
|
default_prompt_indicator: None,
|
|
|
|
default_vi_insert_prompt_indicator: None,
|
|
|
|
default_vi_normal_prompt_indicator: None,
|
|
|
|
default_multiline_indicator: None,
|
2022-10-23 14:18:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-15 17:58:32 +00:00
|
|
|
pub fn update_prompt_left(&mut self, prompt_string: Option<String>) {
|
|
|
|
self.left_prompt_string = prompt_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_prompt_right(
|
2022-10-23 14:18:26 +00:00
|
|
|
&mut self,
|
2023-12-15 17:58:32 +00:00
|
|
|
prompt_string: Option<String>,
|
2022-10-23 14:18:26 +00:00
|
|
|
render_right_prompt_on_last_line: bool,
|
|
|
|
) {
|
2023-12-15 17:58:32 +00:00
|
|
|
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
|
|
|
|
2023-12-15 17:58:32 +00:00
|
|
|
pub fn update_prompt_indicator(&mut self, prompt_indicator_string: Option<String>) {
|
2022-01-01 22:53:16 +00:00
|
|
|
self.default_prompt_indicator = prompt_indicator_string;
|
2023-12-15 17:58:32 +00:00
|
|
|
}
|
2022-01-01 22:53:16 +00:00
|
|
|
|
2023-12-15 17:58:32 +00:00
|
|
|
pub fn update_prompt_vi_insert(&mut self, prompt_vi_insert_string: Option<String>) {
|
2022-01-01 22:53:16 +00:00
|
|
|
self.default_vi_insert_prompt_indicator = prompt_vi_insert_string;
|
2023-12-15 17:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2023-12-15 17:58:32 +00:00
|
|
|
}
|
2022-01-01 22:53:16 +00:00
|
|
|
|
2023-12-15 17:58:32 +00:00
|
|
|
pub fn update_prompt_multiline(&mut self, prompt_multiline_indicator_string: Option<String>) {
|
|
|
|
self.default_multiline_indicator = prompt_multiline_indicator_string;
|
2022-01-01 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
2023-12-15 17:58:32 +00:00
|
|
|
pub fn update_all_prompt_strings(
|
2022-01-01 22:53:16 +00:00
|
|
|
&mut self,
|
2022-01-06 12:57:55 +00:00
|
|
|
left_prompt_string: Option<String>,
|
|
|
|
right_prompt_string: Option<String>,
|
2022-03-31 05:22:55 +00:00
|
|
|
prompt_indicator_string: Option<String>,
|
|
|
|
prompt_multiline_indicator_string: Option<String>,
|
|
|
|
prompt_vi: (Option<String>, Option<String>),
|
2022-10-23 14:18:26 +00:00
|
|
|
render_right_prompt_on_last_line: bool,
|
2022-01-01 22:53:16 +00:00
|
|
|
) {
|
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
|
|
|
|
2023-12-15 17:58:32 +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;
|
2022-10-23 14:18:26 +00:00
|
|
|
|
|
|
|
self.render_right_prompt_on_last_line = render_right_prompt_on_last_line;
|
2022-01-01 22:53:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-02 13:10:28 +00:00
|
|
|
fn default_wrapped_custom_string(&self, str: String) -> String {
|
2023-01-30 01:37:54 +00:00
|
|
|
format!("({str})")
|
2021-10-02 13:10:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Prompt for NushellPrompt {
|
2022-01-06 12:57:55 +00:00
|
|
|
fn render_prompt_left(&self) -> Cow<str> {
|
2022-07-11 21:01:49 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
let _ = enable_vt_processing();
|
|
|
|
}
|
|
|
|
|
2022-05-10 21:33:18 +00:00
|
|
|
if let Some(prompt_string) = &self.left_prompt_string {
|
|
|
|
prompt_string.replace('\n', "\r\n").into()
|
2022-01-06 12:57:55 +00:00
|
|
|
} else {
|
2023-01-13 20:37:39 +00:00
|
|
|
let default = DefaultPrompt::default();
|
2023-05-08 18:00:44 +00:00
|
|
|
let prompt = default
|
2022-05-10 21:33:18 +00:00
|
|
|
.render_prompt_left()
|
|
|
|
.to_string()
|
2023-08-04 16:47:46 +00:00
|
|
|
.replace('\n', "\r\n");
|
2023-05-08 18:00:44 +00:00
|
|
|
|
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()
|
|
|
|
}
|
2022-05-10 21:33:18 +00:00
|
|
|
}
|
2022-01-06 12:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn render_prompt_right(&self) -> Cow<str> {
|
|
|
|
if let Some(prompt_string) = &self.right_prompt_string {
|
2022-02-24 19:02:28 +00:00
|
|
|
prompt_string.replace('\n', "\r\n").into()
|
2022-01-04 19:49:04 +00:00
|
|
|
} else {
|
2023-01-13 20:37:39 +00:00
|
|
|
let default = DefaultPrompt::default();
|
2022-01-27 07:53:23 +00:00
|
|
|
default
|
|
|
|
.render_prompt_right()
|
|
|
|
.to_string()
|
2022-02-24 19:02:28 +00:00
|
|
|
.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 {
|
2022-03-31 05:22:55 +00:00
|
|
|
PromptEditMode::Default => match &self.default_prompt_indicator {
|
2023-01-21 13:47:00 +00:00
|
|
|
Some(indicator) => indicator,
|
Make the default prompt play nice with basic fonts (#8080)
# Description
This commit changes the `PROMPT_INDICATOR` and
`PROMPT_INDICATOR_VI_NORMAL` in the default_env and sample_login files.
It also changes its missing fallback in the prompt.rs file.
This has the intention of making the default prompt friendlier when
dealing with basic terminals that may not support displaying a huge
range of the Unicode standard, or users who don't want to get out of
their way to install custom fonts for their terminals. It's also
nicer/more balanced on the eyes, to me, and brings it in line with the
logo of nushell `nu>`.
# User-Facing Changes
New installations of nushell will have > as the default prompt
indicator, and running `config reset` will also change it. This might be
confusing for a few seconds, it could be minor enough that it just feels
slightly off. Anyone who has, for some reason, unset the
PROMPT_INDICATOR variable, or set it to $nothing, will also receive the
`>` treatment.
Users running on basic terminals (like cmd.exe on Windows 10) should no
longer face font issues with the default basic prompt.
# Drawbacks
The Unicode arrow is pretty cool. And it predates many of us. Maybe it's
worth keeping. One argument I could see, and mildly disagree with, is
that it might make users lean towards installing a modern font for their
terminal which will would have good consequences in the future.
2023-03-02 00:59:32 +00:00
|
|
|
None => "> ",
|
2023-01-21 13:47:00 +00:00
|
|
|
}
|
|
|
|
.into(),
|
2022-03-31 05:22:55 +00:00
|
|
|
PromptEditMode::Emacs => match &self.default_prompt_indicator {
|
2023-01-21 13:47:00 +00:00
|
|
|
Some(indicator) => indicator,
|
Make the default prompt play nice with basic fonts (#8080)
# Description
This commit changes the `PROMPT_INDICATOR` and
`PROMPT_INDICATOR_VI_NORMAL` in the default_env and sample_login files.
It also changes its missing fallback in the prompt.rs file.
This has the intention of making the default prompt friendlier when
dealing with basic terminals that may not support displaying a huge
range of the Unicode standard, or users who don't want to get out of
their way to install custom fonts for their terminals. It's also
nicer/more balanced on the eyes, to me, and brings it in line with the
logo of nushell `nu>`.
# User-Facing Changes
New installations of nushell will have > as the default prompt
indicator, and running `config reset` will also change it. This might be
confusing for a few seconds, it could be minor enough that it just feels
slightly off. Anyone who has, for some reason, unset the
PROMPT_INDICATOR variable, or set it to $nothing, will also receive the
`>` treatment.
Users running on basic terminals (like cmd.exe on Windows 10) should no
longer face font issues with the default basic prompt.
# Drawbacks
The Unicode arrow is pretty cool. And it predates many of us. Maybe it's
worth keeping. One argument I could see, and mildly disagree with, is
that it might make users lean towards installing a modern font for their
terminal which will would have good consequences in the future.
2023-03-02 00:59:32 +00:00
|
|
|
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 {
|
2022-03-31 05:22:55 +00:00
|
|
|
PromptViMode::Normal => match &self.default_vi_normal_prompt_indicator {
|
2023-01-21 13:47:00 +00:00
|
|
|
Some(indicator) => indicator,
|
2023-08-04 16:47:46 +00:00
|
|
|
None => "> ",
|
2022-03-31 05:22:55 +00:00
|
|
|
},
|
|
|
|
PromptViMode::Insert => match &self.default_vi_insert_prompt_indicator {
|
2023-01-21 13:47:00 +00:00
|
|
|
Some(indicator) => indicator,
|
2023-08-04 16:47:46 +00:00
|
|
|
None => ": ",
|
2022-03-31 05:22:55 +00:00
|
|
|
},
|
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> {
|
2022-05-10 21:33:18 +00:00
|
|
|
match &self.default_multiline_indicator {
|
2023-01-21 13:47:00 +00:00
|
|
|
Some(indicator) => indicator,
|
|
|
|
None => "::: ",
|
2022-05-10 21:33:18 +00:00
|
|
|
}
|
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
|
|
|
|
))
|
|
|
|
}
|
2022-10-23 14:18:26 +00:00
|
|
|
|
|
|
|
fn right_prompt_on_last_line(&self) -> bool {
|
|
|
|
self.render_right_prompt_on_last_line
|
|
|
|
}
|
2021-10-02 13:10:28 +00:00
|
|
|
}
|