Skip to content

Parse bracketed-paste sequences into Paste events#40

Open
reisub wants to merge 1 commit into
pcharbon70:developfrom
reisub:fix-bracketed-paste
Open

Parse bracketed-paste sequences into Paste events#40
reisub wants to merge 1 commit into
pcharbon70:developfrom
reisub:fix-bracketed-paste

Conversation

@reisub

@reisub reisub commented May 27, 2026

Copy link
Copy Markdown

I ran into this gap while implementing an input box where I want to enable the user to paste multiline text without indadvertedly submitting.

The InputReader-backed EscapeParser had no clause for ESC[200~/ESC[201~, so when bracketed paste mode is enabled the markers leaked into the byte stream as printable text and the pasted content was emitted as a flurry of key events (including embedded \r being interpreted as Enter).

With this change we recognise ESC[200~content ESC[201~ as a single Paste event. If the end marker isn't in the current chunk, return :incomplete and signal partial_sequence?/1 so InputReader keeps buffering.

We cap that buffering at 8 MiB so a stuck terminal that opens a paste but never closes it cannot grow the input buffer without bound; on overflow we emit what we have as a Paste event and the eventual stray \e[201~ is consumed by the existing defensive end-marker clause.

The InputReader-backed EscapeParser had no clause for ESC[200~/ESC[201~,
so when bracketed paste mode is enabled the markers leaked into the byte
stream as printable text and the pasted content was emitted as a flurry
of key events (including embedded \r being interpreted as Enter).

Recognise ESC[200~content ESC[201~ as a single Paste event. If the end
marker isn't in the current chunk, return :incomplete and signal
partial_sequence?/1 so InputReader keeps buffering. Cap that buffering
at 8 MiB so a stuck terminal that opens a paste but never closes it
cannot grow the input buffer without bound; on overflow we emit what
we have as a Paste event and the eventual stray \e[201~ is consumed by
the existing defensive end-marker clause.
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

Successfully merging this pull request may close these issues.

1 participant