Skip to content

Commit bffc9b3

Browse files
authored
Fix shell integration decoration bug for Windows pwsh (#22572)
Attempt to fix colorless and randomized circle decoration for Python REPL usage by Windows Powershell users. Resolves: #22546 #22535
1 parent e1b54d0 commit bffc9b3

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

pythonFiles/pythonrc.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ def __str__(self):
3939
exit_code = 0
4040

4141
# Guide following official VS Code doc for shell integration sequence:
42-
# result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format(
43-
# command_finished="\x1b]633;D;" + str(exit_code) + "0\x07",
44-
# prompt_started="\x1b]633;A\x07",
45-
# prompt=original_ps1,
46-
# command_start="\x1b]633;B\x07",
47-
# command_executed="\x1b]633;C\x07",
48-
# )
49-
result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}"
42+
result = "{command_explicit}{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format(
43+
command_explicit="\x1b]633;E;\x07",
44+
command_finished="\x1b]633;D;" + str(exit_code) + "\x07",
45+
prompt_started="\x1b]633;A\x07",
46+
prompt=original_ps1,
47+
command_start="\x1b]633;B\x07",
48+
command_executed="\x1b]633;C\x07",
49+
)
50+
# result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}"
5051

5152
return result
5253

pythonFiles/tests/test_shell_integration.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ def test_decoration_success():
1010

1111
ps1.hooks.failure_flag = False
1212
result = str(ps1)
13-
assert result == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
13+
assert (
14+
result
15+
== "\x1b]633;E;\x07\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
16+
)
1417

1518

1619
def test_decoration_failure():
@@ -20,7 +23,10 @@ def test_decoration_failure():
2023
ps1.hooks.failure_flag = True
2124
result = str(ps1)
2225

23-
assert result == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
26+
assert (
27+
result
28+
== "\x1b]633;E;\x07\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
29+
)
2430

2531

2632
def test_displayhook_call():

0 commit comments

Comments
 (0)