Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.6.0 (unreleased)

- **Pastes are sent exactly as xterm sends them.** Unbracketed, only LF becomes CR, so a CRLF line ending is two Enters, as in xterm; it was one. The 8-bit CSI character (U+009B) is no longer replaced, and only `ESC [201~` counts as a bracketed paste end, so a pasted U+009B is text like any other character. A paste is encoded in its own buffer and no longer copied, about three times faster: 32 MB in 4 ms ([#2116](https://github.com/raphamorim/rio/pull/2116)).

- **Pastes that could run commands are confirmed first, and pasted control bytes can't act as input.** A paste is checked before it reaches the program: when it isn't bracketed, a line break would run each line, so Rio asks first; a paste holding the end of a bracketed paste is always asked about. `paste-protection = false` turns this off, and `paste-bracketed-safe = false` asks about line breaks in bracketed pastes too. Control bytes in a paste are now sent as spaces in either mode, as xterm does: not only ESC and ^C, which were dropped, but ^Z and ^\ (which would suspend or quit the program), the line-editing and flow-control keys, NUL and DEL; and in bracketed paste the 8-bit CSI too. Bracketed pastes keep their line endings. librio hosts paste the same way, and `rio_surface_paste_is_safe` tells them when to ask ([#2115](https://github.com/raphamorim/rio/pull/2115)).

- **Programs can make the cursor blink, and a configured blink holds.** With `cursor.blinking` unset (the default), the cursor is steady, and programs may now make it blink (DECSCUSR, `?12h`/`?12l`); before, the default kept them from it. Set it to `true` or `false` and it is the default, and mode 12 is ignored, so a legacy program can't stop or start the blink for good, while DECSCUSR still applies and `CSI 0 SP q` restores it. New tabs and splits take the configured cursor rather than the current tab's, so an editor's insert-mode beam no longer carries over to them ([#2114](https://github.com/raphamorim/rio/pull/2114)).
Expand Down
5 changes: 3 additions & 2 deletions frontends/rioterm/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,8 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
return;
}
// Don't use bracketed paste for single char input.
route.window.screen.paste(&text, text.chars().count() > 1);
let bracketed = text.chars().count() > 1;
route.window.screen.paste(text, bracketed);
}
Ime::Preedit(text, cursor_offset) => {
let preedit = if text.is_empty() || route.modal_owns_input() {
Expand Down Expand Up @@ -2397,7 +2398,7 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
}

let path = crate::platform::shell_escape(&path.to_string_lossy());
route.window.screen.paste(&(path + " "), true);
route.window.screen.paste(path + " ", true);
}

WindowEvent::Resized(new_size) => {
Expand Down
1 change: 0 additions & 1 deletion frontends/rioterm/src/renderer/confirm_paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ mod tests {
assert!(confirm.needs_confirmation("ls\r", false));
assert!(!confirm.needs_confirmation("ls\nrm -rf ~", true));
assert!(confirm.needs_confirmation("a\x1b[201~rm -rf ~\n", true));
assert!(confirm.needs_confirmation("a\u{9b}201~rm", true));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions frontends/rioterm/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ impl Route<'_> {
if let Some(text) =
self.window.screen.renderer.confirm_paste.take()
{
self.window.screen.paste(&text, true);
self.window.screen.paste(text, true);
}
self.request_overlay_redraw();
}
Key::Named(NamedKey::Enter) => {
if let Some(text) =
self.window.screen.renderer.confirm_paste.take()
{
self.window.screen.paste(&text, true);
self.window.screen.paste(text, true);
}
self.request_overlay_redraw();
}
Expand Down
37 changes: 21 additions & 16 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ impl Screen<'_> {
&& binding.action == Act::PasteSelection
{
let content = clipboard.get(ClipboardType::Selection);
self.paste_from_clipboard(&content);
self.paste_from_clipboard(content);
}
}
}
Expand Down Expand Up @@ -1110,18 +1110,18 @@ impl Screen<'_> {
match &action {
Act::Run(program) => self.exec(program.program(), program.args()),
Act::Esc(s) => {
self.paste(s, false);
self.paste(s.clone(), false);
}
Act::Paste => {
let content = clipboard.get(ClipboardType::Clipboard);
self.paste_from_clipboard(&content);
self.paste_from_clipboard(content);
}
Act::ClearSelection => {
self.clear_selection();
}
Act::PasteSelection => {
let content = clipboard.get(ClipboardType::Selection);
self.paste_from_clipboard(&content);
self.paste_from_clipboard(content);
}
Act::Copy => {
self.copy_selection(ClipboardType::Clipboard, clipboard);
Expand Down Expand Up @@ -3705,22 +3705,25 @@ impl Screen<'_> {
/// Paste what the user pasted from a clipboard, first asking them
/// if it could run commands (`paste-protection`): the text is held by
/// the confirmation dialog, which pastes it on yes.
pub fn paste_from_clipboard(&mut self, text: &str) {
pub fn paste_from_clipboard(&mut self, text: String) {
let bracketed = self.get_mode().contains(Mode::BRACKETED_PASTE);
if !self.search_active()
&& self
.renderer
.confirm_paste
.needs_confirmation(text, bracketed)
.needs_confirmation(&text, bracketed)
{
self.renderer.confirm_paste.hold(text.to_owned(), bracketed);
self.renderer.confirm_paste.hold(text, bracketed);
self.mark_dirty();
return;
}
self.paste(text, true);
}

pub fn paste(&mut self, text: &str, bracketed: bool) {
/// Paste `text`, bracketed when `bracketed` and the program asked for
/// it. The text is encoded in its own buffer and written between the
/// markers, never copied: a large paste costs one pass over it.
pub fn paste(&mut self, text: String, bracketed: bool) {
if self.search_active() {
for c in text.chars() {
self.search_input(c);
Expand All @@ -3738,18 +3741,20 @@ impl Screen<'_> {

// The markers, and the text with its control bytes as
// spaces so it can't end the bracket or act as tty input.
let payload = rio_backend::paste::encode(text, true);
self.ctx_mut().current_mut().messenger.send_write(payload);
let encoded = rio_backend::paste::encode_owned(text, true);
let messenger = &self.ctx_mut().current_mut().messenger;
messenger.send_write(encoded.start);
messenger.send_write(encoded.text);
messenger.send_write(encoded.end);
} else {
let payload = if bracketed {
// The program can't tell a paste from typing: control
// bytes become spaces and a line break is what Enter
// sends.
rio_backend::paste::encode(text, false)
// bytes become spaces and LF is what Enter sends.
rio_backend::paste::encode_owned(text, false).text
} else {
// When we explicitly disable bracketed paste don't manipulate with the input,
// so we pass user input as is.
text.to_owned().into_bytes()
text.into_bytes()
};

self.ctx_mut().current_mut().messenger.send_write(payload);
Expand Down Expand Up @@ -3850,7 +3855,7 @@ impl Screen<'_> {
}
PaletteAction::Paste => {
let content = clipboard.get(ClipboardType::Clipboard);
self.paste_from_clipboard(&content);
self.paste_from_clipboard(content);
}
PaletteAction::SearchForward => {
self.start_search(Direction::Right);
Expand Down Expand Up @@ -4936,7 +4941,7 @@ impl Screen<'_> {
clipboard.set(ClipboardType::Clipboard, hint_match.text.clone());
}
HintInternalAction::Paste => {
self.paste(&hint_match.text, true);
self.paste(hint_match.text.clone(), true);
}
HintInternalAction::Select => {
// Set selection to the hint match
Expand Down
2 changes: 1 addition & 1 deletion librio/include/librio.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ bool rio_surface_hangup_child(const rio_surface_t *surface);
void rio_surface_text(rio_surface_t *surface, const char *bytes, size_t len);
/* Paste `bytes` (UTF-8), bracketed when the program has enabled mode 2004.
* Control bytes are sent as spaces, so a paste can't end its bracket or act
* as tty input; unbracketed, a line break is sent as CR. */
* as tty input; unbracketed, LF is sent as CR. */
void rio_surface_paste(rio_surface_t *surface, const char *bytes, size_t len);
/* Whether `bytes` can be pasted without asking the user: bracketed, only a
* bracketed paste end is suspect; otherwise any line break is too, since
Expand Down
5 changes: 4 additions & 1 deletion librio/src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,10 @@ pub unsafe extern "C" fn rio_surface_paste(
return;
}
let slice = unsafe { std::slice::from_raw_parts(bytes as *const u8, len) };
unsafe { &*surface }.paste(&String::from_utf8_lossy(slice));
// Copied once here (borrowed text; the buffer is the host's only
// for this call), or not at all when invalid UTF-8 was already
// repaired into an owned string.
unsafe { &*surface }.paste(String::from_utf8_lossy(slice));
}));
}

Expand Down
28 changes: 21 additions & 7 deletions librio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,17 +921,31 @@ impl Surface {
self.write(text.as_bytes().to_vec());
}

/// Paste text the way Rio does, see [`rio_vt::paste::encode`]: its
/// control bytes as spaces so it can't end the bracket or act as tty
/// input, between the bracketed paste markers when the program asked
/// for them (mode 2004) with its line endings as they are, and
/// otherwise with every line break as CR, what Enter sends.
pub fn paste(&self, text: &str) {
/// Paste text the way Rio does, see [`rio_vt::paste::encode_in_place`]:
/// its control bytes as spaces so it can't end the bracket or act as
/// tty input, between the bracketed paste markers when the program
/// asked for them (mode 2004) with its line endings as they are, and
/// otherwise with LF as CR, what Enter sends.
///
/// A `String` is encoded in its own buffer and sent as is, never
/// copied; a `&str` is copied once, since the writer thread needs the
/// bytes after this returns.
pub fn paste(&self, text: impl Into<String>) {
let text = text.into();
if text.is_empty() {
return;
}
let bracketed = self.terminal.lock().mode().contains(Mode::BRACKETED_PASTE);
self.write(rio_vt::paste::encode(text, bracketed));
let encoded = rio_vt::paste::encode_owned(text, bracketed);
// `write` snaps the view back once, for the whole paste; the rest
// follows in order.
if encoded.start.is_empty() {
self.write(encoded.text);
} else {
self.write(encoded.start);
self.send(encoded.text);
self.send(encoded.end);
}
}

/// Whether `text` can be pasted without asking the user first, for a
Expand Down
Loading
Loading