ReviewOS

also looking at this

den-shell/den

feat(line-editor): support bracketed paste mode

#55
Merged chris wants to merge feat/bracketed-paste into main
2 files +108 -14
9 days ago

What

Adds bracketed-paste support to the interactive line editor.

Pasting multi-line text without bracketed paste is a classic footgun: each embedded newline submits a line, so a pasted block runs partially, line by line — often executing something the user hadn't reviewed. Den had no paste handling at all.

  • Enable the mode (ESC[?2004h on entry / ESC[?2004l on exit, via a defer so the terminal is always restored) so the terminal wraps pastes in ESC[200~ … ESC[201~.
  • escape.zig: the CSI parameter parser only matched single-digit ESC[N~ sequences and returned .unknown for anything longer — truncating 200/201 to ESC[2 and dumping the rest as literal input. Rewrote that arm to scan the full numeric parameter, return null while digits are still arriving, then map 200~→paste_start, 201~→paste_end (existing 1/3/4/5/6 and ESC[1;5C/D ctrl-arrows preserved).
  • line_editor.zig: handlePaste() reads up to the terminator via a small state machine and inserts the text in one batch (insertPasteByte, single redraw), normalizing embedded newline/CR/tab to spaces so the whole paste stays on one editable line and only runs on Enter.

Verification

  • zig build clean (exit 0).
  • PTY test: pasting echo LINE1\necho DANGER2 bracketed by ESC[200~/201~ yields the single line echo LINE1 echo DANGER2; nothing executes before Enter (no command not found, no standalone DANGER2); ESC[?2004h/l emitted exactly once each.

Two files; additive; no API changes.

2 changed files on the files tab, with 0 review threads.

Sign in to comment on this pull request.