Skip to content
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

Bracketed paste issue with split escape sequence #3668

Open
HiFiPhile opened this issue Feb 18, 2025 · 0 comments
Open

Bracketed paste issue with split escape sequence #3668

HiFiPhile opened this issue Feb 18, 2025 · 0 comments

Comments

@HiFiPhile
Copy link

HiFiPhile commented Feb 18, 2025

Previous discussion: #3666

Description

I met a paste issue when SSH into Debian 12 servers from Windows Terminal, sometimes the pasted text is surrounded by 200 and 201 and lost formatting, looks like bracketed paste escape sequence is not processed correctly.

  • Server
    Debian 12
    micro 2.0.14

  • Client
    Windows 10
    Windows Terminal 1.21.10351.0
    OpenSSH 9.5

Diagnostic

Using raw mode, I saw a successful paste result a EventPaste but a distorted paste result a sequence of EventKey.

WindowsTerminal_KeyWy1CMjl.mp4
With this script I see Windows Terminal sometimes cut the escape sequence in half
import sys
import tty
import termios
import os
import atexit

@atexit.register
def restore_term():
   global old_settings
   if old_settings:
      termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)

old_settings=None

def init():
   global old_settings
   old_settings = termios.tcgetattr(sys.stdin)
   tty.setraw(sys.stdin)
   # Enable bracketed paste mode
   sys.stdout.write("\033[?2004h")
   sys.stdout.flush()

init()

while True:
    ch = os.read(sys.stdin.fileno(), 256)
    print(f"-> {repr(ch)[2:-1]}", end='\r\n')

Paste issues:

-> \x1b[200~issues\x1b[20
-> 1~
-> \x1b[200~issues\x1b[201~
-> \x1b[200~issues\x1b[201~
-> \x1b[200~issues\x1b[201~
-> \x1b[200~issues\x1b[20
-> 1~
-> \x1b[200~issues\x1b[201~

Seems related: microsoft/terminal#4037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant