Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell integration: Fix PS2 prompt reporting #212491

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

grawity
Copy link

@grawity grawity commented May 11, 2024

Currently shellIntegration-bash attempts to handle raw ESCs within the PS2 continuation prompt by converting them to backslash-escapes... but then it feeds those backslash-escapes to printf which immediately converts them back.

And in most cases, just like PS1, the PS2 will have \e backslash-escaped form anyway – which still leads to the same problem of printf translating them back to raw ESC.

For example, if PS2 is set to:

PS2="\[\e[0;1;30m\]...\[\e[m\] "

(with Bash strings keeping the \[ and \e as literal text), then the printf results in the output:

<U+001B>]633;P;ContinuationPrompt=\[<U+001B>[0;1;30m\]...\[<U+001B>[m\] <U+0007>

With this change, it should result in the expected:

<U+001B>]633;P;ContinuationPrompt=\[\e[0;1;30m\]...\[\e[m\] \a<U+0007>

(Yes, I noticed __vsc_report_prompt() just a few lines below which does everything differently with PS1 – I'm pretty sure the same code should be handling both prompts identically, but I'm not sufficiently familiar with the code to attempt unifying them just yet.)

Currently shellIntegration-bash attempts to handle raw ESCs within the `PS2` continuation prompt by converting them to backslash-escapes... but then it feeds those backslash-escapes to `printf` which immediately converts them back.

And in most cases, just like PS1, the PS2 will have `\e` backslash-escaped form anyway – which still leads to the same problem of printf translating them back to raw ESC.

For example, if PS2 is set to:

    PS2="\[\e[0;1;30m\]...\[\e[m\] "

(with Bash strings keeping the `\[` and `\e` as literal text), then the printf results in the output:

    <U+001B>]633;P;ContinuationPrompt=\[<U+001B>[0;1;30m\]...\[<U+001B>[m\] <U+0007>

With this change, it should result in the expected:

    <U+001B>]633;P;ContinuationPrompt=\[\e[0;1;30m\]...\[\e[m\] \a<U+0007>

(Yes, I noticed __vsc_report_prompt() just a few lines below which does everything differently with PS1 – I'm pretty sure the same code should be handling both prompts identically, but I'm not sufficiently familiar with the code to attempt unifying them just yet.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants