mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #12080 from erw7/feature-bracketed-paste-on-term
terminal: add bracketed pasting feature
This commit is contained in:
commit
787339892d
@ -6289,6 +6289,29 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
attributes instead of "cterm" attributes. |highlight-guifg|
|
attributes instead of "cterm" attributes. |highlight-guifg|
|
||||||
Requires an ISO-8613-3 compatible terminal.
|
Requires an ISO-8613-3 compatible terminal.
|
||||||
|
|
||||||
|
*'termpastefilter'* *'tpf'*
|
||||||
|
'termpastefilter' 'tpf' string (default: "BS,HT,ESC,DEL")
|
||||||
|
global
|
||||||
|
A comma separated list of options for specifying control characters
|
||||||
|
to be removed from the text pasted into the terminal window. The
|
||||||
|
supported values are:
|
||||||
|
|
||||||
|
BS Backspace
|
||||||
|
|
||||||
|
HT TAB
|
||||||
|
|
||||||
|
FF Form feed
|
||||||
|
|
||||||
|
ESC Escape
|
||||||
|
|
||||||
|
DEL DEL
|
||||||
|
|
||||||
|
C0 Other control characters, excluding Line feed and
|
||||||
|
Carriage return < ' '
|
||||||
|
|
||||||
|
C1 Control characters 0x80...0x9F
|
||||||
|
|
||||||
|
|
||||||
*'terse'* *'noterse'*
|
*'terse'* *'noterse'*
|
||||||
'terse' boolean (default off)
|
'terse' boolean (default off)
|
||||||
global
|
global
|
||||||
|
@ -1942,6 +1942,7 @@ static void didset_options(void)
|
|||||||
(void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, true);
|
(void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, true);
|
||||||
(void)opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true);
|
(void)opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true);
|
||||||
(void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false);
|
(void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false);
|
||||||
|
(void)opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true);
|
||||||
(void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true);
|
(void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true);
|
||||||
(void)opt_strings_flags(p_wop, p_wop_values, &wop_flags, true);
|
(void)opt_strings_flags(p_wop, p_wop_values, &wop_flags, true);
|
||||||
(void)opt_strings_flags(p_jop, p_jop_values, &jop_flags, true);
|
(void)opt_strings_flags(p_jop, p_jop_values, &jop_flags, true);
|
||||||
@ -3077,6 +3078,10 @@ ambw_end:
|
|||||||
if (!parse_winhl_opt(curwin)) {
|
if (!parse_winhl_opt(curwin)) {
|
||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
}
|
}
|
||||||
|
} else if (varp == &p_tpf) {
|
||||||
|
if (opt_strings_flags(p_tpf, p_tpf_values, &tpf_flags, true) != OK) {
|
||||||
|
errmsg = e_invarg;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Options that are a list of flags.
|
// Options that are a list of flags.
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
@ -621,6 +621,19 @@ EXTERN int p_sta; // 'smarttab'
|
|||||||
EXTERN int p_sb; // 'splitbelow'
|
EXTERN int p_sb; // 'splitbelow'
|
||||||
EXTERN long p_tpm; // 'tabpagemax'
|
EXTERN long p_tpm; // 'tabpagemax'
|
||||||
EXTERN char_u *p_tal; // 'tabline'
|
EXTERN char_u *p_tal; // 'tabline'
|
||||||
|
EXTERN char_u *p_tpf; // 'termpastefilter'
|
||||||
|
EXTERN unsigned int tpf_flags; ///< flags from 'termpastefilter'
|
||||||
|
#ifdef IN_OPTION_C
|
||||||
|
static char *(p_tpf_values[]) =
|
||||||
|
{ "BS", "HT", "FF", "ESC", "DEL", "C0", "C1", NULL };
|
||||||
|
#endif
|
||||||
|
# define TPF_BS 0x001
|
||||||
|
# define TPF_HT 0x002
|
||||||
|
# define TPF_FF 0x004
|
||||||
|
# define TPF_ESC 0x008
|
||||||
|
# define TPF_DEL 0x010
|
||||||
|
# define TPF_C0 0x020
|
||||||
|
# define TPF_C1 0x040
|
||||||
EXTERN char_u *p_sps; // 'spellsuggest'
|
EXTERN char_u *p_sps; // 'spellsuggest'
|
||||||
EXTERN int p_spr; // 'splitright'
|
EXTERN int p_spr; // 'splitright'
|
||||||
EXTERN int p_sol; // 'startofline'
|
EXTERN int p_sol; // 'startofline'
|
||||||
|
@ -2820,6 +2820,14 @@ return {
|
|||||||
varname='p_tgc',
|
varname='p_tgc',
|
||||||
defaults={if_true={vi=false}}
|
defaults={if_true={vi=false}}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
full_name='termpastefilter', abbreviation='tpf',
|
||||||
|
type='string', list='onecomma', scope={'global'},
|
||||||
|
deny_duplicates=true,
|
||||||
|
vim=true,
|
||||||
|
varname='p_tpf',
|
||||||
|
defaults={if_true={vi="", vim="BS,HT,ESC,DEL"}}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
full_name='terse',
|
full_name='terse',
|
||||||
short_desc=N_("hides notification of search wrap"),
|
short_desc=N_("hides notification of search wrap"),
|
||||||
|
@ -535,8 +535,44 @@ void terminal_send(Terminal *term, char *data, size_t size)
|
|||||||
term->opts.write_cb(data, size, term->opts.data);
|
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)
|
void terminal_paste(long count, char_u **y_array, size_t y_size)
|
||||||
{
|
{
|
||||||
|
vterm_keyboard_start_paste(curbuf->terminal->vt);
|
||||||
|
terminal_flush_output(curbuf->terminal);
|
||||||
|
size_t buff_len = STRLEN(y_array[0]);
|
||||||
|
char_u *buff = xmalloc(buff_len);
|
||||||
for (int i = 0; i < count; i++) { // -V756
|
for (int i = 0; i < count; i++) { // -V756
|
||||||
// feed the lines to the terminal
|
// feed the lines to the terminal
|
||||||
for (size_t j = 0; j < y_size; j++) {
|
for (size_t j = 0; j < y_size; j++) {
|
||||||
@ -544,9 +580,28 @@ void terminal_paste(long count, char_u **y_array, size_t y_size)
|
|||||||
// terminate the previous line
|
// terminate the previous line
|
||||||
terminal_send(curbuf->terminal, "\n", 1);
|
terminal_send(curbuf->terminal, "\n", 1);
|
||||||
}
|
}
|
||||||
terminal_send(curbuf->terminal, (char *)y_array[j], STRLEN(y_array[j]));
|
size_t len = STRLEN(y_array[j]);
|
||||||
|
if (len > buff_len) {
|
||||||
|
buff = xrealloc(buff, len);
|
||||||
|
buff_len = len;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
src += len;
|
||||||
|
}
|
||||||
|
terminal_send(curbuf->terminal, (char *)buff, (size_t)(dst - buff));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xfree(buff);
|
||||||
|
vterm_keyboard_end_paste(curbuf->terminal->vt);
|
||||||
|
terminal_flush_output(curbuf->terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminal_flush_output(Terminal *term)
|
void terminal_flush_output(Terminal *term)
|
||||||
|
Loading…
Reference in New Issue
Block a user