commit bash-20190731 snapshot

This commit is contained in:
Chet Ramey
2019-08-01 16:00:56 -04:00
parent 9a53e2aa75
commit 1679cff94f
11 changed files with 273 additions and 75 deletions
+1 -3
View File
@@ -635,9 +635,7 @@ _rl_read_mbchar (char *mbchar, int size)
mb_len = 0;
while (mb_len < size)
{
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
c = (mb_len == 0) ? _rl_bracketed_read_key () : rl_read_key ();
if (c < 0)
break;
+1
View File
@@ -297,6 +297,7 @@ _rl_isearch_fini (_rl_search_cxt *cxt)
rl_clear_message ();
}
/* XXX - we could use _rl_bracketed_read_mbstring () here. */
int
_rl_search_getchar (_rl_search_cxt *cxt)
{
+96 -3
View File
@@ -1,6 +1,6 @@
/* kill.c -- kill ring management. */
/* Copyright (C) 1994-2017 Free Software Foundation, Inc.
/* Copyright (C) 1994-2019 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -668,8 +668,7 @@ rl_yank_last_arg (int count, int key)
/* Having read the special escape sequence denoting the beginning of a
`bracketed paste' sequence, read the rest of the pasted input until the
closing sequence and insert the pasted text as a single unit without
interpretation. */
closing sequence and return the pasted text. */
char *
_rl_bracketed_text (size_t *lenp)
{
@@ -715,6 +714,10 @@ _rl_bracketed_text (size_t *lenp)
return (buf);
}
/* Having read the special escape sequence denoting the beginning of a
`bracketed paste' sequence, read the rest of the pasted input until the
closing sequence and insert the pasted text as a single unit without
interpretation. */
int
rl_bracketed_paste_begin (int count, int key)
{
@@ -729,6 +732,96 @@ rl_bracketed_paste_begin (int count, int key)
return (retval);
}
int
_rl_read_bracketed_paste_prefix (int c)
{
char pbuf[BRACK_PASTE_SLEN+1], *pbpref;
int key, ind, j;
pbpref = BRACK_PASTE_PREF; /* XXX - debugging */
if (c != pbpref[0])
return (0);
pbuf[ind = 0] = c;
while (ind < BRACK_PASTE_SLEN-1 &&
(RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
_rl_pushed_input_available () == 0 &&
_rl_input_queued (0))
{
key = rl_read_key (); /* XXX - for now */
if (key < 0)
break;
pbuf[++ind] = key;
if (pbuf[ind] != pbpref[ind])
break;
}
if (ind < BRACK_PASTE_SLEN-1) /* read incomplete sequence */
{
while (ind >= 0)
_rl_unget_char (pbuf[ind--]);
return (key < 0 ? key : 0);
}
return (key < 0 ? key : 1);
}
/* Get a character from wherever we read input, handling input in bracketed
paste mode. If we don't have or use bracketed paste mode, this can be
used in place of rl_read_key(). */
int
_rl_bracketed_read_key ()
{
int c, r;
char *pbuf;
size_t pblen;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (c < 0)
return -1;
/* read pasted data with bracketed-paste mode enabled. */
if (_rl_enable_bracketed_paste && c == ESC && (r = _rl_read_bracketed_paste_prefix (c)) == 1)
{
pbuf = _rl_bracketed_text (&pblen);
if (pblen == 0)
{
xfree (pbuf);
return 0; /* XXX */
}
c = (unsigned char)pbuf[0];
if (pblen > 1)
{
while (--pblen > 0)
_rl_unget_char ((unsigned char)pbuf[pblen]);
}
xfree (pbuf);
}
return c;
}
/* Get a character from wherever we read input, handling input in bracketed
paste mode. If we don't have or use bracketed paste mode, this can be
used in place of rl_read_key(). */
int
_rl_bracketed_read_mbstring (char *mb, int mlen)
{
int c, r;
c = _rl_bracketed_read_key ();
if (c < 0)
return -1;
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
c = _rl_read_mbstring (c, mb, mlen);
#endif
return c;
}
/* A special paste command for Windows users. */
#if defined (_WIN32)
#include <windows.h>
+1 -3
View File
@@ -138,9 +138,7 @@ _rl_arg_dispatch (_rl_arg_cxt cxt, int c)
}
else
{
RL_SETSTATE(RL_STATE_MOREINPUT);
key = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
key = _rl_bracketed_read_key ();
rl_restore_prompt ();
rl_clear_message ();
RL_UNSETSTATE(RL_STATE_NUMERICARG);
+3
View File
@@ -309,7 +309,10 @@ extern int _rl_search_getchar PARAMS((_rl_search_cxt *));
#define BRACK_PASTE_INIT "\033[?2004h"
#define BRACK_PASTE_FINI "\033[?2004l\r"
extern int _rl_read_bracketed_paste_prefix PARAMS((int));
extern char *_rl_bracketed_text PARAMS((size_t *));
extern int _rl_bracketed_read_key PARAMS((void));
extern int _rl_bracketed_read_mbstring PARAMS((char *, int));
/* macro.c */
extern void _rl_with_macro_input PARAMS((char *));
+2 -5
View File
@@ -1,6 +1,6 @@
/* text.c -- text handling commands for readline. */
/* Copyright (C) 1987-2017 Free Software Foundation, Inc.
/* Copyright (C) 1987-2019 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -1722,10 +1722,7 @@ _rl_char_search (int count, int fdir, int bdir)
{
int c;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
c = _rl_bracketed_read_key ();
if (c < 0)
return 1;
+34 -23
View File
@@ -1,7 +1,7 @@
/* vi_mode.c -- A vi emulation mode for Bash.
Derived from code written by Jeff Sparkes (jsparkes@bnr.ca). */
/* Copyright (C) 1987-2018 Free Software Foundation, Inc.
/* Copyright (C) 1987-2019 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@@ -1316,13 +1316,7 @@ rl_domove_read_callback (_rl_vimotion_cxt *m)
static int
rl_vi_domove_getchar (_rl_vimotion_cxt *m)
{
int c;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
return c;
return (_rl_bracketed_read_key ());
}
#if defined (READLINE_CALLBACKS)
@@ -2000,21 +1994,7 @@ _rl_vi_change_char (int count, int c, char *mb)
static int
_rl_vi_callback_getchar (char *mb, int mlen)
{
int c;
RL_SETSTATE(RL_STATE_MOREINPUT);
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
if (c < 0)
return -1;
#if defined (HANDLE_MULTIBYTE)
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
c = _rl_read_mbstring (c, mb, mlen);
#endif
return c;
return (_rl_bracketed_read_mbstring (mb, mlen));
}
#if defined (READLINE_CALLBACKS)
@@ -2137,6 +2117,34 @@ rl_vi_overstrike_delete (int count, int key)
return (0);
}
/* Read bracketed paste mode pasted text and insert it in overwrite mode */
static int
rl_vi_overstrike_bracketed_paste (int count, int key)
{
int r;
char *pbuf;
size_t pblen;
pbuf = _rl_bracketed_text (&pblen);
if (pblen == 0)
{
xfree (pbuf);
return 0;
}
r = pblen;
while (--r >= 0)
_rl_unget_char ((unsigned char)pbuf[r]);
xfree (pbuf);
while (_rl_pushed_input_available ())
{
key = rl_read_key ();
r = rl_vi_overstrike (1, key);
}
return r;
}
int
rl_vi_replace (int count, int key)
{
@@ -2179,6 +2187,9 @@ rl_vi_replace (int count, int key)
_rl_vi_last_key_before_insert = key;
_rl_keymap = vi_replace_map;
if (_rl_enable_bracketed_paste)
rl_bind_keyseq_if_unbound (BRACK_PASTE_PREF, rl_vi_overstrike_bracketed_paste);
return (0);
}