Skip to content
Snippets Groups Projects
Commit 353530d9 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add support for XTerm "Bracketed Paste"

At the same time, add BD, BE, PE, and PS to the terminfo entry.

Note that it seems this is "normally" detected by seeing if $TERM
contains "xterm" which shouldn't work with SyncTERM (which is wildly
incompatible), but the terminfo source file here:
https://invisible-island.net/ncurses/terminfo.ti.html
Gives us hope in the form of this comment:

https://invisible-island.net/xterm/xterm-paste64.html

Bracketed paste was introduced by xterm patch #203 in May 2005, as part of a
larger feature for manipulating the clipboard selection.  Few terminals aside
from xterm fully implement the clipboard feature, but several copy this
detail.  The names for the extended capabilities here were introduced by vim
in January 2017, but used internally.  In 2023, vim patch 9.0.1117 is needed
to work with this change.

That is to say that it likely won't work on anyone's system today
(except maybe Cyan's), but it may magically start working in the
future... assuming tic supports these capnames.  No real clue there
since there's absolutely no termcap support, and I use FreeBSD.
parent cda7525d
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4361 passed
......@@ -2527,6 +2527,9 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
if (cterm->mouse_state_change)
cterm->mouse_state_change(seq->param_int[i], 1, cterm->mouse_state_change_cbdata);
break;
case 2004:
cterm->extattr |= CTERM_EXTATTR_BRACKETPASTE;
break;
}
}
if (updfg || updbg) {
......@@ -2602,6 +2605,9 @@ static void do_ansi(struct cterminal *cterm, char *retbuf, size_t retsize, int *
if (cterm->mouse_state_change)
cterm->mouse_state_change(seq->param_int[i], 0, cterm->mouse_state_change_cbdata);
break;
case 2004:
cterm->extattr &= ~(CTERM_EXTATTR_BRACKETPASTE);
break;
}
}
if (updfg || updbg) {
......
......@@ -122,6 +122,7 @@ struct cterminal {
#define CTERM_EXTATTR_ORIGINMODE 0x0002
#define CTERM_EXTATTR_SXSCROLL 0x0004
#define CTERM_EXTATTR_DECLRMM 0x0008
#define CTERM_EXTATTR_BRACKETPASTE 0x0016
int save_xpos; // Saved position (for later restore)
int save_ypos;
int sequence; // An escape sequence is being parsed
......
......@@ -901,6 +901,8 @@ CSI ? Ps... h (DECSET)
1015 - URXVT encoded extended coordinates
(Not supported by SyncTERM)
SOURCE: xterm
2004 - Set bracketed paste mode
SOURCE: xterm (https://invisible-island.net/xterm/xterm-paste64.html)
CSI Pn j (HPB)
Character Position Backward
......@@ -996,6 +998,8 @@ CSI ? Ps... l (DECRST)
1015 - Disable URXVT encoded extended coordinates
(Not supported by SyncTERM)
SOURCE: xterm
2004 - Disable bracketed paste mode
SOURCE: xterm (https://invisible-island.net/xterm/xterm-paste64.html)
CSI Ps... m (SGR)
Select Graphic Rendition
......
......@@ -1409,6 +1409,15 @@ main(int argc, char **argv)
"\tsmglp=\\E[69h\\E[%{1}%p1%+%d;0s\\E[69l,smgrp=\\E[69h\\E[0;%{1}%p1%+%ds\\E[69l,\n"
"\thts=\\E[H,ht=\t,setab=\\E[4%p1%dm,setaf=\\E[3%p1%dm,\n"
"\tsmglr=\\E[?69h\\E[%i%p1%d;%p2%ds\\E?69l,smso=\\E[0;1;7m,rmso=\\E[m,\n"
// XTerm bracketed pasted: https://invisible-island.net/xterm/xterm-paste64.html
/* NOTE: From terminfo source: https://invisible-island.net/ncurses/terminfo.ti.html
* Bracketed paste was introduced by xterm patch #203 in May 2005, as part of a
* larger feature for manipulating the clipboard selection. Few terminals aside
* from xterm fully implement the clipboard feature, but several copy this
* detail. The names for the extended capabilities here were introduced by vim
* in January 2017, but used internally. In 2023, vim patch 9.0.1117 is needed
* to work with this change. */
"\tBD=\\E[?2004l,BE=\\E[?2004h,PE=\\E[201~,PS=\\E[200~,"
"syncterm-bitmap|SyncTERM in Bitmap Mode,\n"
"\tccc,\n"
"\tcolors#256,pairs#65535,\n"
......
......@@ -3572,16 +3572,28 @@ do_paste(void)
setfont(oldfont, false, 1);
free(p2);
if (p != NULL) {
if (cterm->extattr & CTERM_EXTATTR_BRACKETPASTE)
conn_send("\x1b[200~", 6, 0);
for (p2 = p; *p2; p2++) {
if (*p2 == '\n') {
/* If previous char was not \r, send a \r */
if ((p2 == p) || (*(p2 - 1) != '\r'))
conn_send("\r", 1, 0);
}
else if (*p2 == '\x1b') {
// If we're using bracked paste, strip paste end sequence
// TODO: Do we generally want to disable all ESC chars?
if (strcmp(p2, "\x1b[201~") == 0)
p2 += 5;
else
conn_send(p2, 1, 0);
}
else {
conn_send(p2, 1, 0);
}
}
if (cterm->extattr & CTERM_EXTATTR_BRACKETPASTE)
conn_send("\x1b[201~", 6, 0);
free(p);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment