Skip to content

Conversation

@y5c4l3
Copy link
Contributor

@y5c4l3y5c4l3 commented Sep 16, 2024

@ghost
Copy link

ghost commented Sep 16, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@y5c4l3y5c4l3force-pushed the windows-vt branch 2 times, most recently from 42a48dc to 13bb26fCompareSeptember 19, 2024 12:31
@pablogsal
Copy link
Member

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

@zooba
Copy link
Member

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
ContributorAuthor

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.

@y5c4l3y5c4l3force-pushed the windows-vt branch 5 times, most recently from 3c1502a to 718110fCompareSeptember 20, 2024 18:07
Signed-off-by: y5c4l3 <y5c4l3@proton.me>
To support virtual terminal mode in Windows PYREPL, we need a scanner to read over the supported escaped VT sequences. Signed-off-by: y5c4l3 <y5c4l3@proton.me>
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 <y5c4l3@proton.me>
@y5c4l3
Copy link
ContributorAuthor

@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

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

@encukouencukou 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

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

Co-authored-by: Dustin L. Howett <dustin@howett.net>
Copy link
Contributor

@wheeheeewheeheee 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

@encukouencukou added OS-windows topic-repl Related to the interactive shell labels Jan 24, 2025
encukouand others added 2 commits February 5, 2025 10:16
Co-authored-by: wheeheee <104880306+wheeheee@users.noreply.github.com>
@encukou
Copy link
Member

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

@encukou
Copy link
Member

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

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

@ambvambv merged commit a65366e into python:mainFeb 23, 2025
47 checks passed
@ambvambv 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 <124019959+y5c4l3@users.noreply.github.com> Signed-off-by: y5c4l3 <y5c4l3@proton.me> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> Co-authored-by: Dustin L. Howett <dustin@howett.net> Co-authored-by: wheeheee <104880306+wheeheee@users.noreply.github.com>
@bedevere-app
Copy link

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

@bedevere-appbedevere-appbot 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 <124019959+y5c4l3@users.noreply.github.com> Signed-off-by: y5c4l3 <y5c4l3@proton.me> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> Co-authored-by: Dustin L. Howett <dustin@howett.net> Co-authored-by: wheeheee <104880306+wheeheee@users.noreply.github.com>
@tpnga95
Copy link

I still get that error even using the latest version 3.13.7. Is there any solution?

@encukou
Copy link
Member

What's your setup? Are you using Windows Terminal?

A workaround is using “paste mode” (the F3 key) for pasting text to the console.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OS-windowstopic-replRelated to the interactive shell

Projects

None yet

Development

Successfully merging this pull request may close these issues.

12 participants

@y5c4l3@pablogsal@zooba@cbrnr@pavlovc2@wheeheee@DHowett@encukou@tpnga95@vstinner@zadjii-msft@ambv