Skip to content

Commit 6ad43b1

Browse files
Jocelyn Falempekdj0c
authored andcommitted
vte: Add bracketed paste support (DEC 2004)
When set, enclose the pasted data with escape character. Signed-off-by: Jocelyn Falempe <[email protected]>
1 parent 438441f commit 6ad43b1

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/tsm/libtsm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ enum tsm_vte_color {
377377
#define TSM_VTE_MOUSE_EVENT_ANY 1003 /* sends position on mouse click and mouse move */
378378
#define TSM_VTE_MOUSE_MODE_SGR 1006 /* modern mode that allows unlimited x and y coordinates */
379379
#define TSM_VTE_MOUSE_MODE_PIXEL 1016 /* sends pixel coordinates instead of cell coordinates */
380+
#define TSM_VTE_BRACKETED_PASTE 2004 /* enclose paste data with escape characters */
380381

381382
enum tsm_mouse_track_mode {
382383
TSM_MOUSE_TRACK_DISABLE = 0, /* don't track mouse events */
@@ -520,6 +521,7 @@ bool tsm_vte_handle_mouse(struct tsm_vte *vte, unsigned int cell_x,
520521
unsigned int cell_y, unsigned int pixel_x, unsigned int pixel_y,
521522
unsigned int button, unsigned int event, unsigned char flags);
522523

524+
void tsm_vte_paste(struct tsm_vte *vte, const char *data);
523525
/** @} */
524526

525527
#ifdef __cplusplus

src/tsm/libtsm.sym

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,8 @@ LIBTSM_4_3 {
137137
global:
138138
tsm_screen_selection_word;
139139
} LIBTSM_4_1;
140+
141+
LIBTSM_4_4 {
142+
global:
143+
tsm_vte_paste;
144+
} LIBTSM_4_3;

src/tsm/tsm-vte.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ struct tsm_vte {
176176
unsigned int mouse_event;
177177
unsigned int mouse_last_col;
178178
unsigned int mouse_last_row;
179+
bool bracketed_paste;
179180

180181
uint8_t (*custom_palette_storage)[3];
181182
uint8_t (*palette)[3];
@@ -1756,6 +1757,9 @@ static void csi_mode(struct tsm_vte *vte, bool set)
17561757
continue;
17571758
}
17581759
continue;
1760+
case TSM_VTE_BRACKETED_PASTE:
1761+
vte->bracketed_paste = set;
1762+
continue;
17591763
default:
17601764
llog_debug(vte, "unknown DEC %set-Mode %d",
17611765
set?"S":"Res", vte->csi_argv[i]);
@@ -3358,3 +3362,22 @@ bool tsm_vte_handle_mouse(struct tsm_vte *vte, unsigned int cell_x,
33583362

33593363
return false;
33603364
}
3365+
3366+
void tsm_vte_paste(struct tsm_vte *vte, const char *data)
3367+
{
3368+
if (vte->bracketed_paste) {
3369+
const char start[] = "\e[200~";
3370+
const char end[] = "\e[201~";
3371+
char *buf;
3372+
int len;
3373+
3374+
len = strlen(data) + sizeof(start) + sizeof(end) + 1;
3375+
buf = malloc(len);
3376+
if (!buf)
3377+
return;
3378+
snprintf(buf, len, "%s%s%s", start, data, end);
3379+
vte_write(vte, buf, strlen(buf));
3380+
free(buf);
3381+
} else
3382+
vte_write(vte, data, strlen(data));
3383+
}

0 commit comments

Comments
 (0)