ReviewOS

also looking at this

den-shell/den

feat(line-editor): support bracketed paste mode

#54
Closed chris wants to merge feat/bracketed-paste into main
1 file +8 -0
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) so the terminal wraps pastes in ESC[200~ … ESC[201~.
  • types.zig: add paste_start / paste_end to EscapeSequence.
  • escape.zig: map CSI 200~ / 201~ (the existing ESC[N~ number parser already does the work — two switch arms).
  • line_editor.zig: handlePaste reads everything up to the terminator via a small state machine and inserts it in one batch (insertPasteByte, single redraw), normalizing embedded newlines/tabs to spaces so the whole paste stays on one editable line and only runs on Enter.

Verification

  • zig build clean (the exhaustive EscapeSequence switches forced both handlers to cover the new variants).
  • PTY test: pasting echo LINE1\necho DANGER2 bracketed by ESC[200~/201~ yields the single line echo LINE1 echo DANGER2; standalone echo LINE1 is never executed; ESC[?2004h/l are emitted.

Three small, additive files; no API changes.

1 changed file on the files tab, with 0 review threads.

Sign in to comment on this pull request.