Skip to content

gh-124096: Enable REPL virtual terminal support on Windows #124119

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

Merged
merged 13 commits into from
Feb 23, 2025

Conversation

y5c4l3
Copy link
Contributor

@y5c4l3 y5c4l3 commented Sep 16, 2024

@ghost
Copy link

ghost commented Sep 16, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@y5c4l3 y5c4l3 force-pushed the windows-vt branch 2 times, most recently from 42a48dc to 13bb26f Compare September 19, 2024 12:31
@pablogsal
Copy link
Member

@ambv @zooba can you test this on a windows machine?

@zooba
Copy link
Member

zooba commented Sep 20, 2024

I'm just testing that indentation works when I paste code? That seems fine.

As a side note, my Ctrl+Left and Ctrl+Right shortcuts (skip word) are broken now (possibly ever since the repl went in), and there's way too much ctypes for my liking in here - we should prioritise moving those to _winapi for 3.13.1.

@y5c4l3
Copy link
Contributor Author

y5c4l3 commented Sep 20, 2024

As a side note, my Ctrl+Left and Ctrl+Right shortcuts (skip word) are broken now

It can be fixed by adding two entries in the keymap. I'll later check whether there are other sequences that I missed before and commit as soon.

@y5c4l3 y5c4l3 force-pushed the windows-vt branch 5 times, most recently from 3c1502a to 718110f Compare September 20, 2024 18:07
To support virtual terminal mode in Windows PYREPL, we need a scanner
to read over the supported escaped VT sequences.

Signed-off-by: y5c4l3 <[email protected]>
Windows REPL input was using virtual key mode, which does not support
terminal escape sequences. This patch calls `SetConsoleMode` properly
when initializing and send sequences to enable bracketed-paste modes
to support verbatim copy-and-paste.

Signed-off-by: y5c4l3 <[email protected]>
@y5c4l3
Copy link
Contributor Author

y5c4l3 commented Sep 28, 2024

@pablogsal @ambv @zooba
Consider it's little bit hard to integrate Windows console tests, I recorded a GIF with screenkey for reference, it at least covers:

  • Ctrl + R
  • PgUp / PgDown
  • Home / End / Ctrl + A / Ctrl + E / Ctrl + ← / Ctrl + →
  • bracketed pastes

Peek 2024-09-28 17-10

@cbrnr
Copy link
Contributor

cbrnr commented Jan 14, 2025

I just wanted to ask if there is something that I could do to help get this PR merged? It is currently not possible to paste a code snippet containing indentation into the REPL on Windows. I think this is a pretty serious limitation, because many tools (e.g. Visual Studio Code) rely on this mechanism to run selected code portions. I was hoping that this fix would make it into 3.13.1, but unfortunately this was not the case. Currently, this forces people on 3.13 to either disable the new REPL experience or switch to 3.12, both of which are very suboptimal workarounds (because the new REPL is great!).

@pavlovc2
Copy link

I second the need to get this merged as I am also impacted by the issue.

@wheeheee
Copy link
Contributor

Would this PR also work for VSCode's integrated terminal? There's a comment here: # Currently enable bracketed-paste only if it's Windows Terminal.

@pablogsal
Copy link
Member

I just wanted to ask if there is something that I could do to help get this PR merged? It is currently not possible to paste a code snippet containing indentation into the REPL on Windows. I think this is a pretty serious limitation, because many tools (e.g. Visual Studio Code) rely on this mechanism to run selected code portions. I was hoping that this fix would make it into 3.13.1, but unfortunately this was not the case. Currently, this forces people on 3.13 to either disable the new REPL experience or switch to 3.12, both of which are very suboptimal workarounds (because the new REPL is great!).

We need someone with windows knowledge to validate the PR. Unfortunately I don't have a windows machine or enough knowledge of the platform to validate the correctness.

So if you can review the PR or get some windows expert to do we probably can continue landing it

@pablogsal
Copy link
Member

CC @ambv @zooba

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the change to enable bracketed mode (if VT is supported).

I've tested on Windows 10 on Command Prompt (PS & cmd), VS Code embedded terminal (PS & cmd), and conhost.exe. Bracketed paste works on the first two (there is no confirmation dialog when pasting in multiple lines and the text is not auto-indented; pasting ends the F3 paste mode). On conhost.exe, bracketed paste works as before (dialog appears, text is auto-indented; F3 needs to be ended with another F3).
Ctrl+arrows, PgUp/PgDn, Alt+. still work.

(I found other behaviour that's surprising to me, including a bug, but no unintended changes to the status quo.)

@cbrnr
Copy link
Contributor

cbrnr commented Jan 23, 2025

I just wanted to thank everyone for helping get this PR merged! You are awesome! ❤️

Copy link
Contributor

@wheeheee wheeheee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙂 hope this PR gets merged soon

@encukou encukou added OS-windows topic-repl Related to the interactive shell labels Jan 24, 2025
@encukou
Copy link
Member

encukou commented Feb 5, 2025

I plan to take some time this or next week to write the tests.

@encukou
Copy link
Member

encukou commented Feb 17, 2025

I added base_eventqueue, since the unix and Windows implementations are now identical except the __init__.
@ambv, does this look OK?

@encukou
Copy link
Member

encukou commented Feb 20, 2025

I'll merge next week if there are no objections.

@ambv ambv merged commit a65366e into python:main Feb 23, 2025
47 checks passed
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…hon#124119)

To support virtual terminal mode in Windows PYREPL, we need a scanner
to read over the supported escaped VT sequences.

Windows REPL input was using virtual key mode, which does not support
terminal escape sequences. This patch calls `SetConsoleMode` properly
when initializing and send sequences to enable bracketed-paste modes
to support verbatim copy-and-paste.

Signed-off-by: y5c4l3 <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Pablo Galindo Salgado <[email protected]>
Co-authored-by: Dustin L. Howett <[email protected]>
Co-authored-by: wheeheee <[email protected]>
@ambv ambv added the needs backport to 3.13 bugs and security fixes label May 5, 2025
@miss-islington-app
Copy link

Thanks @y5c4l3 for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 5, 2025
…honGH-124119)

To support virtual terminal mode in Windows PYREPL, we need a scanner
to read over the supported escaped VT sequences.

Windows REPL input was using virtual key mode, which does not support
terminal escape sequences. This patch calls `SetConsoleMode` properly
when initializing and send sequences to enable bracketed-paste modes
to support verbatim copy-and-paste.
(cherry picked from commit a65366e)

Co-authored-by: Y5 <[email protected]>
Signed-off-by: y5c4l3 <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Pablo Galindo Salgado <[email protected]>
Co-authored-by: Dustin L. Howett <[email protected]>
Co-authored-by: wheeheee <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented May 5, 2025

GH-133457 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 5, 2025
ambv pushed a commit that referenced this pull request May 5, 2025
…-124119) (GH-133457)

To support virtual terminal mode in Windows PYREPL, we need a scanner
to read over the supported escaped VT sequences.

Windows REPL input was using virtual key mode, which does not support
terminal escape sequences. This patch calls `SetConsoleMode` properly
when initializing and send sequences to enable bracketed-paste modes
to support verbatim copy-and-paste.
(cherry picked from commit a65366e)

Co-authored-by: Y5 <[email protected]>
Signed-off-by: y5c4l3 <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Pablo Galindo Salgado <[email protected]>
Co-authored-by: Dustin L. Howett <[email protected]>
Co-authored-by: wheeheee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows topic-repl Related to the interactive shell
Projects
None yet
Development

Successfully merging this pull request may close these issues.