micro-editor / micro-editor/micro

Bracketed paste issue with split escape sequence

Open
#3,668 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
29.6k
Forks
1.4k
Avg merge
2d 18h
Merged PRs (30d)
10

Description

Previous discussion: https://github.com/zyedidia/micro/discussions/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.

https://github.com/user-attachments/assets/a6ec66f5-46a6-45ea-91d9-35cd607dfbcc

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: https://github.com/microsoft/terminal/issues/4037

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the provided Python raw-mode script while connecting to a Debian 12 server through Windows Terminal. Trace how split bracketed-paste escape sequences become EventKey instead of EventPaste; done when the paste remains formatted and is consistently reported as EventPaste.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.