mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 15:16:17 +02: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. -->
This commit is contained in:
@ -74,7 +74,14 @@ pub struct Config {
|
||||
pub menus: Vec<ParsedMenu>,
|
||||
pub hooks: Hooks,
|
||||
pub rm_always_trash: bool,
|
||||
pub shell_integration: bool,
|
||||
// Shell integration OSC meaning is described in the default_config.nu
|
||||
pub shell_integration_osc2: bool,
|
||||
pub shell_integration_osc7: bool,
|
||||
pub shell_integration_osc8: bool,
|
||||
pub shell_integration_osc9_9: bool,
|
||||
pub shell_integration_osc133: bool,
|
||||
pub shell_integration_osc633: bool,
|
||||
pub shell_integration_reset_application_mode: bool,
|
||||
pub buffer_editor: Value,
|
||||
pub table_index_mode: TableIndexMode,
|
||||
pub case_sensitive_completions: bool,
|
||||
@ -154,7 +161,15 @@ impl Default for Config {
|
||||
use_ansi_coloring: true,
|
||||
bracketed_paste: true,
|
||||
edit_mode: EditBindings::default(),
|
||||
shell_integration: false,
|
||||
// shell_integration: false,
|
||||
shell_integration_osc2: false,
|
||||
shell_integration_osc7: false,
|
||||
shell_integration_osc8: false,
|
||||
shell_integration_osc9_9: false,
|
||||
shell_integration_osc133: false,
|
||||
shell_integration_osc633: false,
|
||||
shell_integration_reset_application_mode: false,
|
||||
|
||||
render_right_prompt_on_last_line: false,
|
||||
|
||||
hooks: Hooks::new(),
|
||||
@ -639,7 +654,54 @@ impl Value {
|
||||
&mut errors);
|
||||
}
|
||||
"shell_integration" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration);
|
||||
if let Value::Record { val, .. } = value {
|
||||
val.to_mut().retain_mut(|key2, value| {
|
||||
let span = value.span();
|
||||
match key2 {
|
||||
"osc2" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_osc2);
|
||||
}
|
||||
"osc7" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_osc7);
|
||||
}
|
||||
"osc8" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_osc8);
|
||||
}
|
||||
"osc9_9" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_osc9_9);
|
||||
}
|
||||
"osc133" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_osc133);
|
||||
}
|
||||
"osc633" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_osc633);
|
||||
}
|
||||
"reset_application_mode" => {
|
||||
process_bool_config(value, &mut errors, &mut config.shell_integration_reset_application_mode);
|
||||
}
|
||||
_ => {
|
||||
report_invalid_key(&[key, key2], span, &mut errors);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
true
|
||||
})
|
||||
} else {
|
||||
report_invalid_value("boolean value is deprecated, should be a record. see default_conifg.nu.", span, &mut errors);
|
||||
// Reconstruct
|
||||
*value = Value::record(
|
||||
record! {
|
||||
"osc2" => Value::bool(config.shell_integration_osc2, span),
|
||||
"ocs7" => Value::bool(config.shell_integration_osc7, span),
|
||||
"osc8" => Value::bool(config.shell_integration_osc8, span),
|
||||
"osc9_9" => Value::bool(config.shell_integration_osc9_9, span),
|
||||
"osc133" => Value::bool(config.shell_integration_osc133, span),
|
||||
"osc633" => Value::bool(config.shell_integration_osc633, span),
|
||||
"reset_application_mode" => Value::bool(config.shell_integration_reset_application_mode, span),
|
||||
},
|
||||
span,
|
||||
);
|
||||
}
|
||||
}
|
||||
"buffer_editor" => match value {
|
||||
Value::Nothing { .. } | Value::String { .. } => {
|
||||
|
Reference in New Issue
Block a user