Add termpastefilter option

Change to specify a character to be filtered as an option when pasting on
the terminal.
This commit is contained in:
erw7
2020-04-04 16:10:09 +09:00
parent 14158e8d47
commit 1e3fadb419
5 changed files with 91 additions and 8 deletions

View File

@@ -535,6 +535,38 @@ void terminal_send(Terminal *term, char *data, size_t size)
term->opts.write_cb(data, size, term->opts.data);
}
static bool is_filter_char(int c)
{
unsigned int flag = 0;
switch (c) {
case 0x08:
flag = TPF_BS;
break;
case 0x09:
flag = TPF_HT;
break;
case 0x0A:
case 0x0D:
break;
case 0x0C:
flag = TPF_FF;
break;
case 0x1b:
flag = TPF_ESC;
break;
case 0x7F:
flag = TPF_DEL;
break;
default:
if (c < ' ') {
flag = TPF_C0;
} else if (c >= 0x80 && c <= 0x9F) {
flag = TPF_C1;
}
}
return !!(tpf_flags & flag);
}
void terminal_paste(long count, char_u **y_array, size_t y_size)
{
vterm_keyboard_start_paste(curbuf->terminal->vt);
@@ -553,16 +585,18 @@ void terminal_paste(long count, char_u **y_array, size_t y_size)
buff = xrealloc(buff, len);
buff_len = len;
}
char_u *p = buff;
char_u *q = y_array[j];
while (*q != '\0') {
if ((*q > '\x07' && *q < '\x0e' && *q != '\x0b' && *q != '\x0c')
|| *q > '\x1f') {
*(p++) = *q;
char_u *dst = buff;
char_u *src = y_array[j];
while (*src != '\0') {
len = (size_t)utf_ptr2len(src);
int c = utf_ptr2char(src);
if (!is_filter_char(c)) {
memcpy(dst, src, len);
dst += len;
}
q++;
src += len;
}
terminal_send(curbuf->terminal, (char *)buff, (size_t)(p - buff));
terminal_send(curbuf->terminal, (char *)buff, (size_t)(dst - buff));
}
}
xfree(buff);