Skip to content

Commit

Permalink
fix: strip osc from prompt detection (#256)
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery committed May 7, 2024
1 parent ae6e6e1 commit 2269665
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions shell/shellIntegration-rc.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ __is_escape_value() {
token="\\\\"
elif [ "$byte" = ";" ]; then
token="\\x3b"
elif [ "$byte" = $'\n' ]; then
token="\x0a"
elif [ "$byte" = $'\e' ]; then
token="\\x1b"
elif [ "$byte" = $'\a' ]; then
token="\\x07"
else
token="$byte"
fi
Expand Down
2 changes: 2 additions & 0 deletions shell/shellIntegration.bash
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ __is_escape_value() {
token="\x0a"
elif [ "$byte" = $'\e' ]; then
token="\\x1b"
elif [ "$byte" = $'\a' ]; then
token="\\x07"
else
token="$byte"
fi
Expand Down
1 change: 1 addition & 0 deletions shell/shellIntegration.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function __is_escape_value
| string replace -a '\\' '\\\\' \
| string replace -a ';' '\\x3b' \
| string replace -a \e '\\x1b' \
| string replace -a \a '\\x07' \
| string split \n | string join '\x0a' \
;
end
Expand Down
2 changes: 1 addition & 1 deletion shell/shellIntegration.nu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let __is_escape_value = {|x| $x | str replace --all "\\" "\\\\" | str replace --all ";" "\\x3b" | str replace --all "\n" '\x0a' | str replace --all "\e" "\\x1b" }
let __is_escape_value = {|x| $x | str replace --all "\\" "\\\\" | str replace --all ";" "\\x3b" | str replace --all "\n" '\x0a' | str replace --all "\e" "\\x1b" | str replace --all "\a" "\\x07" }
let __is_original_PROMPT_COMMAND = if 'PROMPT_COMMAND' in $env { $env.PROMPT_COMMAND } else { "" }
let __is_original_PROMPT_INDICATOR = if 'PROMPT_INDICATOR' in $env { $env.PROMPT_INDICATOR } else { "" }

Expand Down
2 changes: 1 addition & 1 deletion shell/shellIntegration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ($env:ISTERM_TESTING -eq "1") {
}

function Global:__IS-Escape-Value([string]$value) {
[regex]::Replace($value, "[$([char]0x1b)\\\n;]", { param($match)
[regex]::Replace($value, "[$([char]0x1b)$([char]0x07)\\\n;]", { param($match)
-Join (
[System.Text.Encoding]::UTF8.GetBytes($match.Value) | ForEach-Object { '\x{0:x2}' -f $_ }
)
Expand Down
2 changes: 1 addition & 1 deletion shell/shellIntegration.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __is_escape_value(value: str) -> str:
byte_list = [bytes([byte]).decode("utf-8") for byte in list(value.encode("utf-8"))]
return "".join(
[
"\\x3b" if byte == ";" else "\\\\" if byte == "\\" else "\\x1b" if byte == "\x1b" else "\x0a" if byte == "\n" else byte
"\\x3b" if byte == ";" else "\\\\" if byte == "\\" else "\\x1b" if byte == "\x1b" else "\x0a" if byte == "\n"else "\\x07" if byte == "\x07" else byte
for byte in byte_list
]
)
Expand Down
4 changes: 1 addition & 3 deletions src/isterm/commandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ export class CommandManager {
const italic = (cell?.isItalic() ?? 0) > 0;
const dullColor = color == 8 || color == 7 || (color ?? 0) > 235 || (color == 15 && dim);
const dimItalic = dim || italic;
if (this.#shell == Shell.Powershell) {
return false;
} else if (this.#shell == Shell.Pwsh) {
if (this.#shell == Shell.Pwsh || this.#shell == Shell.Powershell) {
return dimItalic;
}
return dullColor;
Expand Down
4 changes: 3 additions & 1 deletion src/isterm/pty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class ISTerm implements IPty {
}

private _sanitizedPrompt(prompt: string): string {
return stripAnsi(prompt);
// eslint-disable-next-line no-control-regex -- strip OSC control sequences
const oscStrippedPrompt = prompt.replace(/\x1b\][0-9]+;.*\x07/g, "");
return stripAnsi(oscStrippedPrompt);
}

private _handleIsSequence(data: string): boolean {
Expand Down

0 comments on commit 2269665

Please sign in to comment.