Skip to content

overhaul shell_integration to enable individual control over ansi escape sequences#12629

Merged
fdncred merged 8 commits intonushell:mainfrom
fdncred:overhaul_shell_integration
May 2, 2024
Merged

overhaul shell_integration to enable individual control over ansi escape sequences#12629
fdncred merged 8 commits intonushell:mainfrom
fdncred:overhaul_shell_integration

Conversation

@fdncred
Copy link
Copy Markdown
Contributor

@fdncred fdncred commented Apr 23, 2024

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

  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

After Submitting

@fdncred fdncred marked this pull request as draft April 23, 2024 15:57
@fdncred fdncred marked this pull request as ready for review May 2, 2024 12:51
@fdncred fdncred added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label May 2, 2024
@fdncred fdncred merged commit 0805f1f into nushell:main May 2, 2024
@fdncred fdncred deleted the overhaul_shell_integration branch May 2, 2024 13:57
@hustcer hustcer added this to the v0.94.0 milestone May 2, 2024
@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented May 7, 2024

Thanks for this one Darren.

@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented May 8, 2024

With this PR, confirmed that osc633 is causing issues on Windows WezTerm (on every keypress, most of the screen scrolls up).

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 8, 2024

@rgwood So, you're saying that osc633 is being activated when NOT inside the vscode terminal? If that's the case then it's a bug. It should only be available within the vscode terminal and it determines this by checking the env var TERM_PROGRAM for "vscode".

However, osc133 has always affected wezterm and should be what is used outside of the vscode terminal.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 8, 2024

With escape-artist, I don't see osc633 being sent if it's off, but I do see other problems. Thanks!

@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented May 8, 2024

So, you're saying that osc633 is being activated when NOT inside the vscode terminal? If that's the case then it's a bug.

I think so? Setting osc633: true breaks WezTerm on Windows for me. Haven't looked at the raw bytes/escape codes being emitted.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 8, 2024

I did that too but it was sending 133 not 633, so that was a bug. I also found some logic issues that I'm trying to fix now. I'm building release to test with escape-artist. :)

fdncred added a commit that referenced this pull request May 8, 2024
# Description

This PR is a continuation of #12629 and meant to address [Reilly's
stated
issue](#12629 (comment)).

With this PR, nushell should work more consistently with WezTerm on
Windows. However, that means continued scrolling with typing if osc133
is enabled. If it's possible to run WezTerm inside of vscode, then
having osc633 enabled will also cause the display to scroll with every
character typed. I think the cause of this is that reedline paints the
entire prompt on each character typed. We need to figure out how to fix
that, but that's in reedline.

For my purposes, I keep osc133 and osc633 set to true and don't use
WezTerm on Windows.

Thanks @rgwood for reporting the issue. I found several logic errors.
It's often good to come back to PRs and look at them with fresh eyes. I
think this is pretty close to logically correct now. However, I'm
approaching burn out on ansi escape codes so i could've missed
something.

Kudos to [escape-artist](https://github.com/rgwood/escape-artist) for
helping me debug an ansi escape codes that are actually being sent to
the terminal. It was an invaluable tool.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# 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.
-->
FilipAndersson245 pushed a commit to FilipAndersson245/nushell that referenced this pull request May 18, 2024
# Description

This PR is a continuation of nushell#12629 and meant to address [Reilly's
stated
issue](nushell#12629 (comment)).

With this PR, nushell should work more consistently with WezTerm on
Windows. However, that means continued scrolling with typing if osc133
is enabled. If it's possible to run WezTerm inside of vscode, then
having osc633 enabled will also cause the display to scroll with every
character typed. I think the cause of this is that reedline paints the
entire prompt on each character typed. We need to figure out how to fix
that, but that's in reedline.

For my purposes, I keep osc133 and osc633 set to true and don't use
WezTerm on Windows.

Thanks @rgwood for reporting the issue. I found several logic errors.
It's often good to come back to PRs and look at them with fresh eyes. I
think this is pretty close to logically correct now. However, I'm
approaching burn out on ansi escape codes so i could've missed
something.

Kudos to [escape-artist](https://github.com/rgwood/escape-artist) for
helping me debug an ansi escape codes that are actually being sent to
the terminal. It was an invaluable tool.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# 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.
-->
@dedebenui
Copy link
Copy Markdown

shell_integration is no longer a boolean value.

Any reason to make this a breaking change? Would it not have been possible to interpret shell_integration = true as shell_integration = <default table>, as @RGBCube mentioned in #11301? Additionally, if the defaults change in future versions, no action would be required from the user.

@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented May 29, 2024

yup, that would've been possible. I didn't think of it.

@eliax1996
Copy link
Copy Markdown

Adding a comment here for noobs like me that didn't knew how to apply the suggested tip;

  1. Run config nu, this will open the nu config file with the default editor (in my wsl instance the referenced file its /home/${USERNAME}/.config/nushell/config.nu, obtained by running echo $nu.config-path)
  2. Insert the following in the config file:
$env.config = {
  shell_integration: {
    osc133: false
  }
}

This is an override of the default file
3. Reload the config by running source $nu.config-path

@sholderbach
Copy link
Copy Markdown
Member

Since 0.101.0 the recommended line would be just

$env.config.shell_integration.osc133 = false

(The config error recovery will recover the rest of the record values, but its both terser and more realistic in that it just sets the value you care about and doesn't imply clearing the other keys, which doesn't occurr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable only specific shell_integration features

6 participants