aboutsummaryrefslogtreecommitdiff
path: root/src/raw_input.rs
diff options
context:
space:
mode:
authorakbash <akbash@herdr.dev>2026-08-21 15:16:43 +0300
committerGitHub <noreply@github.com>2026-08-21 15:16:43 +0300
commit8fe09d5ddf77da5c377760682b33b386ebc37640 (patch)
treec63a23bb630d17e8347c93dc1b01e3ff95bfc531 /src/raw_input.rs
parent624dfd4796559042ec13ccf4d4b54374902ab81d (diff)
fix: preserve multiline paste in terminal attach (#3056)
refs #3054 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
Diffstat (limited to 'src/raw_input.rs')
-rw-r--r--src/raw_input.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/raw_input.rs b/src/raw_input.rs
index 510768fc..5f750ca8 100644
--- a/src/raw_input.rs
+++ b/src/raw_input.rs
@@ -108,19 +108,22 @@ pub(crate) const GHOSTTY_COLOR_SCHEME_LIGHT_REPORT: &[u8] = b"\x1b[?997;2n";
const BRACKETED_PASTE_START: &[u8] = b"\x1b[200~";
const BRACKETED_PASTE_END: &[u8] = b"\x1b[201~";
-/// Returns whether `data` is exactly one complete bracketed-paste sequence.
-///
+/// Returns the UTF-8 payload when `data` is exactly one complete bracketed paste.
+pub(crate) fn complete_text_bracketed_paste(data: &[u8]) -> Option<&str> {
+ if !data.starts_with(BRACKETED_PASTE_START) {
+ return None;
+ }
+ let end = find_subsequence(data, BRACKETED_PASTE_END)?;
+ if end + BRACKETED_PASTE_END.len() != data.len() {
+ return None;
+ }
+ std::str::from_utf8(&data[BRACKETED_PASTE_START.len()..end]).ok()
+}
+
/// Client transport uses this to distinguish recoverable oversized interactive
/// pastes from generic oversized input, which remains a protocol violation.
pub(crate) fn is_complete_text_bracketed_paste(data: &[u8]) -> bool {
- if !data.starts_with(BRACKETED_PASTE_START) {
- return false;
- }
- let Some(end) = find_subsequence(data, BRACKETED_PASTE_END) else {
- return false;
- };
- end + BRACKETED_PASTE_END.len() == data.len()
- && std::str::from_utf8(&data[BRACKETED_PASTE_START.len()..end]).is_ok()
+ complete_text_bracketed_paste(data).is_some()
}
#[derive(Debug)]
@@ -1424,7 +1427,10 @@ mod tests {
#[test]
fn complete_text_bracketed_paste_requires_one_exact_utf8_sequence() {
- assert!(is_complete_text_bracketed_paste(b"\x1b[200~hello\x1b[201~"));
+ assert_eq!(
+ complete_text_bracketed_paste(b"\x1b[200~hello\x1b[201~"),
+ Some("hello")
+ );
assert!(!is_complete_text_bracketed_paste(b"\x1b[200~hello"));
assert!(!is_complete_text_bracketed_paste(
b"\x1b[200~hello\x1b[201~rest"