From 35b6c4e8d9d3deed7074d2fa5118c689eef13ffe Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Thu, 27 Aug 2026 15:46:47 -0700 Subject: [PATCH 1/6] Streamline ANSI Codes --- python_files/pythonrc.py | 42 +++++++++++++------ .../terminals/pythonStartupLinkProvider.ts | 11 ++--- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index 3042ffb7a309..345fddc11319 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -1,5 +1,6 @@ import platform import sys +from enum import Enum if sys.platform != "win32": import readline @@ -8,6 +9,17 @@ is_wsl = "microsoft-standard-WSL" in platform.release() +class ShellIntegrationSequence(str, Enum): + SOH = "\001" + STX = "\002" + COMMAND_EXECUTED = "\x1b]633;C\x07" + COMMAND_LINE = "\x1b]633;E;" + COMMAND_FINISHED = "\x1b]633;D;" + PROMPT_STARTED = "\x1b]633;A\x07" + COMMAND_START = "\x1b]633;B\x07" + TERMINATOR = "\x07" + + class REPLHooks: def __init__(self): self.global_exit = None @@ -53,26 +65,30 @@ def __str__(self): # For non-windows allow recent_command history. if sys.platform != "win32": result = "{soh}{command_executed}{command_line}{command_finished}{prompt_started}{stx}{prompt}{soh}{command_start}{stx}".format( - soh="\001", - stx="\002", - command_executed="\x1b]633;C\x07", - command_line="\x1b]633;E;" + str(get_last_command()) + "\x07", - command_finished="\x1b]633;D;" + str(exit_code) + "\x07", - prompt_started="\x1b]633;A\x07", + soh=ShellIntegrationSequence.SOH, + stx=ShellIntegrationSequence.STX, + command_executed=ShellIntegrationSequence.COMMAND_EXECUTED, + command_line=ShellIntegrationSequence.COMMAND_LINE + + str(get_last_command()) + + ShellIntegrationSequence.TERMINATOR, + command_finished=ShellIntegrationSequence.COMMAND_FINISHED + + str(exit_code) + + ShellIntegrationSequence.TERMINATOR, + prompt_started=ShellIntegrationSequence.PROMPT_STARTED, prompt=original_ps1, - command_start="\x1b]633;B\x07", + command_start=ShellIntegrationSequence.COMMAND_START, ) else: result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( - command_finished="\x1b]633;D;" + str(exit_code) + "\x07", - prompt_started="\x1b]633;A\x07", + command_finished=ShellIntegrationSequence.COMMAND_FINISHED + + str(exit_code) + + ShellIntegrationSequence.TERMINATOR, + prompt_started=ShellIntegrationSequence.PROMPT_STARTED, prompt=original_ps1, - command_start="\x1b]633;B\x07", - command_executed="\x1b]633;C\x07", + command_start=ShellIntegrationSequence.COMMAND_START, + command_executed=ShellIntegrationSequence.COMMAND_EXECUTED, ) - # 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)}" - return result def __repr__(self): diff --git a/src/client/terminals/pythonStartupLinkProvider.ts b/src/client/terminals/pythonStartupLinkProvider.ts index aba1270f1412..6e7234c4687b 100644 --- a/src/client/terminals/pythonStartupLinkProvider.ts +++ b/src/client/terminals/pythonStartupLinkProvider.ts @@ -21,13 +21,10 @@ export class CustomTerminalLinkProvider implements TerminalLinkProvider { const links: CustomTerminalLink[] = []; - let expectedNativeLink; - - if (process.platform === 'darwin') { - expectedNativeLink = 'Cmd click to launch VS Code Native REPL'; - } else { - expectedNativeLink = 'Ctrl click to launch VS Code Native REPL'; - } + let expectedNativeLink = + process.platform === 'darwin' + ? 'Cmd click to launch VS Code Native REPL' + : 'Ctrl click to launch VS Code Native REPL'; if (context.line.includes(expectedNativeLink)) { links.push({ From a1f016fb915a6cec0159e49fdef8611c26e9d677 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 31 Aug 2026 19:50:53 -0400 Subject: [PATCH 2/6] Add link --- python_files/pythonrc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index 345fddc11319..eb16e2b564c1 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -99,6 +99,6 @@ def __repr__(self): sys.ps1 = PS1() if sys.platform == "darwin": - print("Cmd click to launch VS Code Native REPL") + print("Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)") else: - print("Ctrl click to launch VS Code Native REPL") + print("Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)") From 8b2e2efae365b00d7a3a478ec20c9010d14cfe32 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 31 Aug 2026 20:02:33 -0400 Subject: [PATCH 3/6] Fix tests --- .vscode/settings.json | 3 ++- python_files/tests/test_shell_integration.py | 8 ++++++-- src/test/terminals/shellIntegration/pythonStartup.test.ts | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 01de0d907706..29bacae80395 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -74,5 +74,6 @@ "python.testing.pytestEnabled": true, "rust-analyzer.linkedProjects": [ ".\\python-env-tools\\Cargo.toml" - ] + ], + "python-envs.defaultEnvManager": "ms-python.python:system" } diff --git a/python_files/tests/test_shell_integration.py b/python_files/tests/test_shell_integration.py index 7503a725b6d1..013aa3d514b5 100644 --- a/python_files/tests/test_shell_integration.py +++ b/python_files/tests/test_shell_integration.py @@ -70,7 +70,9 @@ def test_print_statement_darwin(monkeypatch): with monkeypatch.context() as m: m.setattr("builtins.print", Mock()) importlib.reload(sys.modules["pythonrc"]) - print.assert_any_call("Cmd click to launch VS Code Native REPL") + print.assert_any_call( + "Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)" + ) if sys.platform == "win32": @@ -80,4 +82,6 @@ def test_print_statement_non_darwin(monkeypatch): with monkeypatch.context() as m: m.setattr("builtins.print", Mock()) importlib.reload(sys.modules["pythonrc"]) - print.assert_any_call("Ctrl click to launch VS Code Native REPL") + print.assert_any_call( + "Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)" + ) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 16f45fb26a40..f15da1179018 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -182,7 +182,8 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { test('Mac - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => { const provider = new CustomTerminalLinkProvider(); const context: TerminalLinkContext = { - line: 'Some random string with Cmd click to launch VS Code Native REPL', + line: + 'Some random string with Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)', terminal: {} as Terminal, }; const token: CancellationToken = { @@ -224,7 +225,8 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { test('Windows/Linux - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => { const provider = new CustomTerminalLinkProvider(); const context: TerminalLinkContext = { - line: 'Some random string with Ctrl click to launch VS Code Native REPL', + line: + 'Some random string with Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)', terminal: {} as Terminal, }; const token: CancellationToken = { From 0fc1fd23eade71dd14ca8bf28aa8bdc374165c13 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 31 Aug 2026 20:06:12 -0400 Subject: [PATCH 4/6] Fix tests --- src/test/terminals/shellIntegration/pythonStartup.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index f15da1179018..5a66edc9d191 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -248,12 +248,14 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { ); assert.equal( links[0].startIndex, - context.line.indexOf('Ctrl click to launch VS Code Native REPL'), + context.line.indexOf( + 'Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)', + ), 'start index should match', ); assert.equal( links[0].length, - 'Ctrl click to launch VS Code Native REPL'.length, + 'Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)'.length, 'Match expected Length', ); assert.equal( From 373c0d689fb232a9b0c6bb8aadc7ab96f3c02fa0 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 31 Aug 2026 20:08:49 -0400 Subject: [PATCH 5/6] Fix tests --- python_files/pythonrc.py | 3 +++ src/test/terminals/shellIntegration/pythonStartup.test.ts | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index eb16e2b564c1..32498a60e624 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -19,6 +19,9 @@ class ShellIntegrationSequence(str, Enum): COMMAND_START = "\x1b]633;B\x07" TERMINATOR = "\x07" + def __str__(self): + return self.value + class REPLHooks: def __init__(self): diff --git a/src/test/terminals/shellIntegration/pythonStartup.test.ts b/src/test/terminals/shellIntegration/pythonStartup.test.ts index 5a66edc9d191..f15da1179018 100644 --- a/src/test/terminals/shellIntegration/pythonStartup.test.ts +++ b/src/test/terminals/shellIntegration/pythonStartup.test.ts @@ -248,14 +248,12 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => { ); assert.equal( links[0].startIndex, - context.line.indexOf( - 'Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)', - ), + context.line.indexOf('Ctrl click to launch VS Code Native REPL'), 'start index should match', ); assert.equal( links[0].length, - 'Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)'.length, + 'Ctrl click to launch VS Code Native REPL'.length, 'Match expected Length', ); assert.equal( From 957ab0825178aecaf5dfa0ec8777d96a1fed56bf Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Mon, 31 Aug 2026 20:11:13 -0400 Subject: [PATCH 6/6] Restore settings.json --- .vscode/settings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 29bacae80395..01de0d907706 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -74,6 +74,5 @@ "python.testing.pytestEnabled": true, "rust-analyzer.linkedProjects": [ ".\\python-env-tools\\Cargo.toml" - ], - "python-envs.defaultEnvManager": "ms-python.python:system" + ] }