Repository navigation
paste: send pastes exactly as xterm does - #2116
Merged
Merged
Conversation
- Unbracketed, only LF becomes CR: a CRLF line ending is two Enters, as xterm sends it, where it was collapsed to one. - U+009B is text like any other character: it is no longer replaced, and only ESC [201~ is a bracketed paste end for confirmation. - Every byte encode changes is ASCII, so it copies the text once and changes it in place; accented text no longer breaks the copy into runs (32 MB bracketed: 17.7 ms to 9.7 ms). - The is_replaced test checks every ASCII character against encode.
- encode_in_place compares each byte with the replaced values and picks the result without a branch, so the loop compiles to SIMD; one loop per mode. 32 MB: 10-21 ms to about 5 ms. - encode_owned takes a String, encodes its buffer in place and hands back the markers and the text as separate writes, so the text isn't copied. Rio's paste and paste_from_clipboard take the String; the dialog gives its held paste back without a copy. - librio's Surface::paste takes impl Into<String>: a String isn't copied, a &str once. rio_surface_paste hands over the Cow from from_utf8_lossy, so the C buffer is copied once. - Test: an owned paste keeps its buffer and encodes like encode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2115: pastes are now sent exactly as xterm sends them, where #2115 still differed in two places.
Unbracketed line breaks. Only LF becomes CR, what Enter sends. A CRLF line ending is therefore two Enters, as xterm sends it; #2115 kept Rio's old behavior of collapsing it to one. Bracketed pastes still keep their line endings.
U+009B. The 8-bit CSI character is text like any other: it's no longer replaced by a space, and only
ESC [201~counts as a bracketed paste end when deciding whether to confirm. In UTF-8 the character is two bytes (C2 9B), and xterm's list is about single control bytes.Encoding. With that, every byte
encodechanges is ASCII and replaced by ASCII, so the text can be changed in place:encode_in_placecompares each byte with the 16 replaced values and picks the result without a branch, so the loop compiles to SIMD; one loop per mode, so neither tests the mode per byte.encode_owned(String)takes a paste the caller owns, such as the clipboard's text, encodes it in its own buffer and hands back the markers and the text as separate writes: the text is never copied. Rio'sScreen::pasteandpaste_from_clipboardtake theStringnow, and the dialog gives its held paste back without a copy.Surface::pastetakesimpl Into<String>: aStringisn't copied, a&stris copied once (the writer thread needs the bytes after the call).rio_surface_pastehands over theCowfromfrom_utf8_lossy, so the C buffer is copied once and only once.&str)&str)Docs. librio's
pastedoc andrio_surface_pastein the header now say LF is sent as CR, and the comment in Rio's paste path too.Tests. The unbracketed test expects
\r\rfor CRLF, U+009B is checked to pass through,is_replacedis checked againstencodefor every ASCII character, and an owned paste is checked to keep its buffer. rio-vt (733), rioterm (310) and librio (76) pass, and the workspace builds.