From: Chet Ramey Date: Mon, 8 Aug 2016 19:48:07 +0000 (-0400) Subject: commit readline-20160808 snapshot X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f46c78d1e48134bf66588b7d24e64efa7a460b17;p=thirdparty%2Freadline.git commit readline-20160808 snapshot --- diff --git a/CHANGES b/CHANGES index 266cd53..1291439 100644 --- a/CHANGES +++ b/CHANGES @@ -97,6 +97,18 @@ ff. Fixed a bug in the character insertion code that attempts to optimize typeahead when it reads a character that is not bound to self-insert and resets the key sequence state. +gg. When refreshing the line as the result of a key sequence, Readline attempts + to redraw only the last line of a multiline prompt. + +hh. Fixed an issue that caused completion of git commands to display + incorrectly when using colored-completion-prefix. + +ii. Fixed several redisplay bugs having to do with multibyte characters and + invisible characters in prompt strings. + +jj. Fixed a bug that caused mode strings to be displayed incorrectly if the prompt was + shorter than the mode string. + 2. New Features in Readline a. The history truncation code now uses the same error recovery mechansim as @@ -142,6 +154,33 @@ k. If readline reads a history file that begins with `#' (or the value of l. Readline now throws an error if it parses a key binding without a terminating `:' or whitespace. +m. The default binding for ^W in vi mode now uses word boundaries specified + by Posix (vi-unix-word-rubout is bindable command name). + +n. rl_clear_visible_line: new application-callable function; clears all + screen lines occupied by the current visible readline line. + +o. rl_tty_set_echoing: application-callable function that controls whether + or not readline thinks it is echoing terminal output. + +p. Handle >| and strings of digits preceding and following redirection + specifications as single tokens when tokenizing the line for history + expansion. + +q. Fixed a bug with displaying completions when the prefix display length + is greater than the length of the completions to be displayed. + +r. The :p history modifier now applies to the entire line, so any expansion + specifying :p causes the line to be printed instead of expanded. + +s. New application-callable function: rl_pending_signal(): returns the signal + number of any signal readline has caught but not yet handled. + +t. New application-settable variable: rl_persistent_signal_handlers: if set to a + non-zero value, readline will enable the readline-6.2 signal handler behavior + in callback mode: handlers are installed when rl_callback_handler_install is + called and removed removed when a complete line has been read. + ------------------------------------------------------------------------------- This document details the changes between this version, readline-6.3, and the previous version, readline-6.2. diff --git a/CHANGES-7.0 b/CHANGES-7.0 index 4fa44f5..36694cb 100644 --- a/CHANGES-7.0 +++ b/CHANGES-7.0 @@ -55,6 +55,60 @@ q. Fixed a bug that caused readline commands that depend on knowing which r. Paren matching now works in vi insert mode. +s. Colored completion prefixes are now displayed using a different color, less + likely to collide with files. + +t. Fixed a bug that caused vi-mode character search to misbehave when + running in callback mode. + +u. Fixed a bug that caused output to be delayed when input is coming from a + macro in vi-mode. + +v. Fixed a bug that caused the vi-mode `.' command to misbehave when redoing + a multi-key key sequence via a macro. + +w. Fixed a bug that caused problems with applications that supply their own + input function when performing completion. + +x. When read returns -1/EIO when attempting to read a key, return an error + instead of line termination back to the caller. + +y. Updated tty auditing feature based on patch from Red Hat. + +z. Fixed a bug that could cause the history library to crash on overflows + introduced by malicious editing of timestamps in the history file. + +aa. The history file writing functions only attempt to create and use a backup + history file if the history file exists and is a regular file. + +bb. Fixed an out-of-bounds read in readline's internal tilde expansion interface. + +cc. Fixed several redisplay bugs with prompt strings containing multibyte + and non-visible characters whose physical length is longer than the screen + width. + +dd. Fixed a redisplay bug with prompt strings containing invisible characters + whose physical length exceeds the screen width and using incremental search. + +ee. Readline prints more descriptive error messages when it encounters errors + while reading an inputrc file. + +ff. Fixed a bug in the character insertion code that attempts to optimize + typeahead when it reads a character that is not bound to self-insert and + resets the key sequence state. + +gg. When refreshing the line as the result of a key sequence, Readline attempts + to redraw only the last line of a multiline prompt. + +hh. Fixed an issue that caused completion of git commands to display + incorrectly when using colored-completion-prefix. + +ii. Fixed several redisplay bugs having to do with multibyte characters and + invisible characters in prompt strings. + +jj. Fixed a bug that caused mode strings to be displayed incorrectly if the prompt was + shorter than the mode string. + 2. New Features in Readline a. The history truncation code now uses the same error recovery mechansim as @@ -88,3 +142,41 @@ h. The insert-char function attempts to batch-insert all pending typeahead i. rl_callback_sigcleanup: a new application function that can clean up and unset any state set by readline's callback mode. Intended to be used after a signal. + +j. If an incremental search string has its last character removed with DEL, the + resulting empty search string no longer matches the previous line. + +k. If readline reads a history file that begins with `#' (or the value of + the history comment character) and has enabled history timestamps, the history + entries are assumed to be delimited by timestamps. This allows multi-line + history entries. + +l. Readline now throws an error if it parses a key binding without a terminating + `:' or whitespace. + +m. The default binding for ^W in vi mode now uses word boundaries specified + by Posix (vi-unix-word-rubout is bindable command name). + +n. rl_clear_visible_line: new application-callable function; clears all + screen lines occupied by the current visible readline line. + +o. rl_tty_set_echoing: application-callable function that controls whether + or not readline thinks it is echoing terminal output. + +p. Handle >| and strings of digits preceding and following redirection + specifications as single tokens when tokenizing the line for history + expansion. + +q. Fixed a bug with displaying completions when the prefix display length + is greater than the length of the completions to be displayed. + +r. The :p history modifier now applies to the entire line, so any expansion + specifying :p causes the line to be printed instead of expanded. + +s. New application-callable function: rl_pending_signal(): returns the signal + number of any signal readline has caught but not yet handled. + +t. New application-settable variable: rl_persistent_signal_handlers: if set to a + non-zero value, readline will enable the readline-6.2 signal handler behavior + in callback mode: handlers are installed when rl_callback_handler_install is + called and removed removed when a complete line has been read. diff --git a/NEWS-7.0 b/NEWS-7.0 index ededd6a..8959d6c 100644 --- a/NEWS-7.0 +++ b/NEWS-7.0 @@ -34,3 +34,41 @@ h. The insert-char function attempts to batch-insert all pending typeahead i. rl_callback_sigcleanup: a new application function that can clean up and unset any state set by readline's callback mode. Intended to be used after a signal. + +j. If an incremental search string has its last character removed with DEL, the + resulting empty search string no longer matches the previous line. + +k. If readline reads a history file that begins with `#' (or the value of + the history comment character) and has enabled history timestamps, the history + entries are assumed to be delimited by timestamps. This allows multi-line + history entries. + +l. Readline now throws an error if it parses a key binding without a terminating + `:' or whitespace. + +m. The default binding for ^W in vi mode now uses word boundaries specified + by Posix (vi-unix-word-rubout is bindable command name). + +n. rl_clear_visible_line: new application-callable function; clears all + screen lines occupied by the current visible readline line. + +o. rl_tty_set_echoing: application-callable function that controls whether + or not readline thinks it is echoing terminal output. + +p. Handle >| and strings of digits preceding and following redirection + specifications as single tokens when tokenizing the line for history + expansion. + +q. Fixed a bug with displaying completions when the prefix display length + is greater than the length of the completions to be displayed. + +r. The :p history modifier now applies to the entire line, so any expansion + specifying :p causes the line to be printed instead of expanded. + +s. New application-callable function: rl_pending_signal(): returns the signal + number of any signal readline has caught but not yet handled. + +t. New application-settable variable: rl_persistent_signal_handlers: if set to a + non-zero value, readline will enable the readline-6.2 signal handler behavior + in callback mode: handlers are installed when rl_callback_handler_install is + called and removed removed when a complete line has been read. diff --git a/bind.c b/bind.c index 3dbc1ce..f1098c4 100644 --- a/bind.c +++ b/bind.c @@ -2591,9 +2591,9 @@ _rl_get_string_variable_value (name) else if (_rl_stricmp (name, "emacs-mode-string") == 0) return (_rl_emacs_mode_str ? _rl_emacs_mode_str : RL_EMACS_MODESTR_DEFAULT); else if (_rl_stricmp (name, "vi-cmd-mode-string") == 0) - return (_rl_emacs_mode_str ? _rl_emacs_mode_str : RL_VI_CMD_MODESTR_DEFAULT); + return (_rl_vi_cmd_mode_str ? _rl_vi_cmd_mode_str : RL_VI_CMD_MODESTR_DEFAULT); else if (_rl_stricmp (name, "vi-ins-mode-string") == 0) - return (_rl_emacs_mode_str ? _rl_emacs_mode_str : RL_VI_INS_MODESTR_DEFAULT); + return (_rl_vi_ins_mode_str ? _rl_vi_ins_mode_str : RL_VI_INS_MODESTR_DEFAULT); else return (0); } diff --git a/callback.c b/callback.c index fafe5a5..cc3ce11 100644 --- a/callback.c +++ b/callback.c @@ -50,6 +50,14 @@ _rl_callback_func_t *_rl_callback_func = 0; _rl_callback_generic_arg *_rl_callback_data = 0; +/* Applications can set this to non-zero to have readline's signal handlers + installed during the entire duration of reading a complete line, as in + readline-6.2. This should be used with care, because it can result in + readline receiving signals and not handling them until it's called again + via rl_callback_read_char, thereby stealing them from the application. + By default, signal handlers are only active while readline is active. */ +int rl_persistent_signal_handlers = 0; + /* **************************************************************** */ /* */ /* Callback Readline Functions */ @@ -82,6 +90,11 @@ _rl_callback_newline () if (rl_prep_term_function) (*rl_prep_term_function) (_rl_meta_flag); + +#if defined (HANDLE_SIGNALS) + if (rl_persistent_signal_handlers) + rl_set_signals (); +#endif } readline_internal_setup (); @@ -103,7 +116,8 @@ rl_callback_handler_install (prompt, linefunc) #if defined (HANDLE_SIGNALS) #define CALLBACK_READ_RETURN() \ do { \ - rl_clear_signals (); \ + if (rl_persistent_signal_handlers == 0) \ + rl_clear_signals (); \ return; \ } while (0) #else @@ -140,7 +154,8 @@ rl_callback_read_char () #if defined (HANDLE_SIGNALS) /* Install signal handlers only when readline has control. */ - rl_set_signals (); + if (rl_persistent_signal_handlers == 0) + rl_set_signals (); #endif do diff --git a/display.c b/display.c index a409574..41fb053 100644 --- a/display.c +++ b/display.c @@ -119,6 +119,8 @@ static int _rl_col_width PARAMS((const char *, int, int, int)); buffer index in others. This macro is used when deciding whether the current cursor position is in the middle of a prompt string containing invisible characters. XXX - might need to take `modmark' into account. */ +/* XXX - only valid when tested against _rl_last_c_pos; buffer indices need + to use prompt_last_invisible directly. */ #define PROMPT_ENDING_INDEX \ ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) ? prompt_physical_chars : prompt_last_invisible+1) @@ -1389,6 +1391,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) int current_invis_chars; int col_lendiff, col_temp; int bytes_to_insert; + int mb_cur_max = MB_CUR_MAX; #if defined (HANDLE_MULTIBYTE) mbstate_t ps_new, ps_old; int new_offset, old_offset; @@ -1399,7 +1402,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) the exact cursor position and cut-and-paste with certain terminal emulators. In this calculation, TEMP is the physical screen position of the cursor. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) temp = _rl_last_c_pos; else temp = _rl_last_c_pos - WRAP_OFFSET (_rl_last_v_pos, visible_wrap_offset); @@ -1407,7 +1410,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) && _rl_last_v_pos == current_line - 1) { #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { wchar_t wc; mbstate_t ps; @@ -1421,7 +1424,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) _rl_clear_to_eol (line_state_visible->wrapped_line[current_line]); memset (&ps, 0, sizeof (mbstate_t)); - ret = mbrtowc (&wc, new, MB_CUR_MAX, &ps); + ret = mbrtowc (&wc, new, mb_cur_max, &ps); if (MB_INVALIDCH (ret)) { tempwidth = 1; @@ -1441,7 +1444,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) _rl_last_c_pos = tempwidth; _rl_last_v_pos++; memset (&ps, 0, sizeof (mbstate_t)); - ret = mbrtowc (&wc, old, MB_CUR_MAX, &ps); + ret = mbrtowc (&wc, old, mb_cur_max, &ps); if (ret != 0 && bytes != 0) { if (MB_INVALIDCH (ret)) @@ -1480,7 +1483,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) /* Find first difference. */ #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { /* See if the old line is a subset of the new line, so that the only change is adding characters. */ @@ -1537,7 +1540,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) return; #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && _rl_utf8locale) + if (mb_cur_max > 1 && rl_byte_oriented == 0 && _rl_utf8locale) { wchar_t wc; mbstate_t ps = { 0 }; @@ -1546,7 +1549,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) /* If the first character in the difference is a zero-width character, assume it's a combining character and back one up so the two base characters no longer compare equivalently. */ - t = mbrtowc (&wc, ofd, MB_CUR_MAX, &ps); + t = mbrtowc (&wc, ofd, mb_cur_max, &ps); if (t > 0 && UNICODE_COMBINING_CHAR (wc) && WCWIDTH (wc) == 0) { old_offset = _rl_find_prev_mbchar (old, ofd - old, MB_FIND_ANY); @@ -1560,7 +1563,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) wsatend = 1; /* flag for trailing whitespace */ #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { ols = old + _rl_find_prev_mbchar (old, oe - old, MB_FIND_ANY); nls = new + _rl_find_prev_mbchar (new, ne - new, MB_FIND_ANY); @@ -1618,14 +1621,14 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) { if (*ols) /* don't step past the NUL */ { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) ols = old + _rl_find_next_mbchar (old, ols - old, 1, MB_FIND_ANY); else ols++; } if (*nls) { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) nls = new + _rl_find_next_mbchar (new, nls - new, 1, MB_FIND_ANY); else nls++; @@ -1642,7 +1645,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) visible_wrap_offset based on what we know. */ if (current_line == 0) visible_wrap_offset = prompt_invis_chars_first_line; /* XXX */ - if ((MB_CUR_MAX == 1 || rl_byte_oriented) && current_line == 0 && visible_wrap_offset) + if ((mb_cur_max == 1 || rl_byte_oriented) && current_line == 0 && visible_wrap_offset) _rl_last_c_pos += visible_wrap_offset; } @@ -1673,10 +1676,10 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if (lendiff > nmax) lendiff = nmax; od = ofd - old; /* index of first difference in visible line */ - nd = nfd - new; + nd = nfd - new; /* nd, od are buffer indexes */ if (current_line == 0 && !_rl_horizontal_scroll_mode && _rl_term_cr && lendiff > prompt_visible_length && _rl_last_c_pos > 0 && - (((od > 0 || nd > 0) && (od < PROMPT_ENDING_INDEX || nd < PROMPT_ENDING_INDEX)) || + (((od > 0 || nd > 0) && (od <= prompt_last_invisible || nd <= prompt_last_invisible)) || ((od >= lendiff) && _rl_last_c_pos < PROMPT_ENDING_INDEX))) { #if defined (__MSDOS__) @@ -1687,7 +1690,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if (modmark) _rl_output_some_chars ("*", 1); _rl_output_some_chars (local_prompt, lendiff); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { /* We take wrap_offset into account here so we can pass correct information to _rl_move_cursor_relative. */ @@ -1701,7 +1704,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) was within the prompt, see if we need to recompute where the lines differ. Check whether where we are now is past the last place where the old and new lines are the same and short-circuit now if we are. */ - if ((od < PROMPT_ENDING_INDEX || nd < PROMPT_ENDING_INDEX) && + if ((od <= prompt_last_invisible || nd <= prompt_last_invisible) && omax == nmax && lendiff > (ols-old) && lendiff > (nls-new)) return; @@ -1713,7 +1716,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) first difference, but you don't know the number of invisible characters in that case. This needs a lot of work to be efficient. */ - if ((od < PROMPT_ENDING_INDEX || nd < PROMPT_ENDING_INDEX)) + if ((od <= prompt_last_invisible || nd <= prompt_last_invisible)) { nfd = new + lendiff; /* number of characters we output above */ nd = lendiff; @@ -1723,7 +1726,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if (temp > 0) { _rl_output_some_chars (nfd, temp); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) _rl_last_c_pos += _rl_col_width (new, nd, ne - new, 1); else _rl_last_c_pos += temp; @@ -1746,7 +1749,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) /* We need to indicate that the cursor position is correct in the presence of invisible characters in the prompt string. Let's see if setting this when we make sure we're at the end of the drawn prompt string works. */ - if (current_line == 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0 && + if (current_line == 0 && mb_cur_max > 1 && rl_byte_oriented == 0 && (_rl_last_c_pos > 0 || o_cpos > 0) && _rl_last_c_pos == prompt_physical_chars) cpos_adjusted = 1; @@ -1757,7 +1760,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) col_lendiff == difference on screen (columns) When not using multibyte characters, these are equal */ lendiff = (nls - nfd) - (ols - ofd); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) col_lendiff = _rl_col_width (new, nfd - new, nls - new, 1) - _rl_col_width (old, ofd - old, ols - old, 1); else col_lendiff = lendiff; @@ -1768,7 +1771,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) if (current_line == 0 && /* !_rl_horizontal_scroll_mode && */ current_invis_chars != visible_wrap_offset) { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { lendiff += visible_wrap_offset - current_invis_chars; col_lendiff += visible_wrap_offset - current_invis_chars; @@ -1786,7 +1789,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) and writes TEMP bytes. */ /* Insert (diff (len (old), len (new)) ch. */ temp = ne - nfd; - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) col_temp = _rl_col_width (new, nfd - new, ne - new, 1); else col_temp = temp; @@ -1837,7 +1840,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) _rl_last_c_pos == 0 && lendiff > prompt_visible_length && current_invis_chars > 0) == 0) && - (((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && + (((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && wrap_offset && ((nfd - new) <= prompt_last_invisible) && (col_lendiff < prompt_visible_length)) == 0) && @@ -1845,12 +1848,12 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) { open_some_spaces (col_lendiff); _rl_output_some_chars (nfd, bytes_to_insert); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) _rl_last_c_pos += _rl_col_width (nfd, 0, bytes_to_insert, 1); else _rl_last_c_pos += bytes_to_insert; } - else if ((MB_CUR_MAX == 1 || rl_byte_oriented != 0) && *ols == 0 && lendiff > 0) + else if ((mb_cur_max == 1 || rl_byte_oriented != 0) && *ols == 0 && lendiff > 0) { /* At the end of a line the characters do not have to be "inserted". They can just be placed on the screen. */ @@ -1865,7 +1868,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) /* If nfd begins before the last invisible character in the prompt, adjust _rl_last_c_pos to account for wrap_offset and set cpos_adjusted to let the caller know. */ - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) + if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) { _rl_last_c_pos -= wrap_offset; cpos_adjusted = 1; @@ -1878,7 +1881,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) /* If nfd begins before the last invisible character in the prompt, adjust _rl_last_c_pos to account for wrap_offset and set cpos_adjusted to let the caller know. */ - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) + if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == 0 && displaying_prompt_first_line && wrap_offset && ((nfd - new) <= prompt_last_invisible)) { _rl_last_c_pos -= wrap_offset; cpos_adjusted = 1; @@ -1898,7 +1901,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) crude attempt to compute how far into the new line buffer we are. It doesn't work well in the face of multibyte characters and needs to be rethought. XXX */ - if ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) && + if ((mb_cur_max > 1 && rl_byte_oriented == 0) && current_line == prompt_last_screen_line && wrap_offset && displaying_prompt_first_line && wrap_offset != prompt_invis_chars_first_line && @@ -1942,7 +1945,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) in a multibyte locale to account for the wrap offset and set cpos_adjusted accordingly. */ _rl_output_some_chars (nfd, bytes_to_insert); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { _rl_last_c_pos += _rl_col_width (nfd, 0, bytes_to_insert, 1); if (current_line == 0 && wrap_offset && @@ -1977,7 +1980,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) set cpos_adjusted accordingly. */ _rl_output_some_chars (nfd, temp); _rl_last_c_pos += col_temp; /* XXX */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { if (current_line == 0 && wrap_offset && displaying_prompt_first_line && @@ -1991,7 +1994,7 @@ update_line (old, new, current_line, omax, nmax, inv_botlin) } clear_rest_of_line: lendiff = (oe - old) - (ne - new); - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) col_lendiff = _rl_col_width (old, 0, oe - old, 1) - _rl_col_width (new, 0, ne - new, 1); else col_lendiff = lendiff; @@ -2001,7 +2004,7 @@ clear_rest_of_line: space_to_eol will insert too many spaces. XXX - maybe we should adjust col_lendiff based on the difference between _rl_last_c_pos and _rl_screenwidth */ - if (col_lendiff && ((MB_CUR_MAX == 1 || rl_byte_oriented) || (_rl_last_c_pos < _rl_screenwidth))) + if (col_lendiff && ((mb_cur_max == 1 || rl_byte_oriented) || (_rl_last_c_pos < _rl_screenwidth))) { if (_rl_term_autowrap && current_line < inv_botlin) space_to_eol (col_lendiff); @@ -2161,6 +2164,7 @@ _rl_move_cursor_relative (new, data) int cpos, dpos; /* current and desired cursor positions */ int adjust; int in_invisline; + int mb_cur_max = MB_CUR_MAX; woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset); cpos = _rl_last_c_pos; @@ -2174,7 +2178,7 @@ _rl_move_cursor_relative (new, data) this case, NEW's display position is not obvious and must be calculated. We need to account for invisible characters in this line, as long as we are past them and they are counted by _rl_col_width. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { adjust = 1; /* Try to short-circuit common cases and eliminate a bunch of multibyte @@ -2242,7 +2246,7 @@ _rl_move_cursor_relative (new, data) of moving backwards. */ /* i == current physical cursor position. */ #if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) i = _rl_last_c_pos; else #endif @@ -2277,7 +2281,7 @@ _rl_move_cursor_relative (new, data) in the buffer and we have to go back to the beginning of the screen line. In this case, we can use the terminal sequence to move forward if it's available. */ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + if (mb_cur_max > 1 && rl_byte_oriented == 0) { if (_rl_term_forward_char) { diff --git a/doc/rltech.texi b/doc/rltech.texi index 9b21e27..b8ce90f 100644 --- a/doc/rltech.texi +++ b/doc/rltech.texi @@ -1435,12 +1435,16 @@ It understands the EOF character or "exit" to exit the program. @example /* Standard include files. stdio.h is required. */ #include +#include #include +#include /* Used for select(2) */ #include #include +#include + #include /* Standard readline include files. */ @@ -1448,10 +1452,20 @@ It understands the EOF character or "exit" to exit the program. #include static void cb_linehandler (char *); +static void sighandler (int); int running; +int sigwinch_received; const char *prompt = "rltest$ "; +/* Handle SIGWINCH and window size changes when readline is not active and + reading a character. */ +static void +sighandler (int sig) +@{ + sigwinch_received = 1; +@} + /* Callback function called for each line when accept-line executed, EOF seen, or EOF character read. This sets a flag and returns; it could also call exit(3). */ @@ -1486,6 +1500,13 @@ main (int c, char **v) fd_set fds; int r; + /* Set the default locale values according to environment variables. */ + setlocale (LC_ALL, ""); + + /* Handle window size changes when readline is not active and reading + characters. */ + signal (SIGWINCH, sighandler); + /* Install the line handler. */ rl_callback_handler_install (prompt, cb_linehandler); @@ -1500,12 +1521,19 @@ main (int c, char **v) FD_SET (fileno (rl_instream), &fds); r = select (FD_SETSIZE, &fds, NULL, NULL, NULL); - if (r < 0) + if (r < 0 && errno != EINTR) @{ perror ("rltest: select"); rl_callback_handler_remove (); break; @} + if (sigwinch_received) + @{ + rl_resize_terminal (); + sigwinch_received = 0; + @} + if (r < 0) + continue; if (FD_ISSET (fileno (rl_instream), &fds)) rl_callback_read_char (); @@ -1563,6 +1591,22 @@ using the callback interface should be prepared to clean up Readline's state if they wish to handle the signal before the line handler completes and restores the terminal state. +If an application using the callback interface wishes to have Readline +install its signal handlers at the time the application calls +@code{rl_callback_handler_install} and remove them only when a complete +line of input has been read, it should set the +@code{rl_persistent_signal_handlers} variable to a non-zero value. +This allows an application to defer all of the handling of the signals +Readline catches to Readline. +Applications should use this variable with care; it can result in Readline +catching signals and not acting on them (or allowing the application to react +to them) until the application calls @code{rl_callback_read_char}. This +can result in an application becoming less responsive to keyboard signals +like SIGINT. +If an application does not want or need to perform any signal handling, or +does not need to do any processing between calls to @code{rl_callback_read_char}, +setting this variable may be desirable. + Readline provides two variables that allow application writers to control whether or not it will catch certain signals and act on them when they are received. It is important that applications change the @@ -1584,6 +1628,15 @@ Readline will install a signal handler for @code{SIGWINCH}. The default value of @code{rl_catch_sigwinch} is 1. @end deftypevar +@deftypevar int rl_persistent_signal_handlers +If an application using the callback interface wishes Readline's signal +handlers to be installed and active during the set of calls to +@code{rl_callback_read_char} that constitutes an entire single line, +it should set this variable to a non-zero value. + +The default value of @code{rl_persistent_signal_handlers} is 0. +@end deftypevar + @deftypevar int rl_change_environment If this variable is set to a non-zero value, and Readline is handling @code{SIGWINCH}, Readline will modify the @@ -1599,6 +1652,11 @@ for example), Readline provides convenience functions to do the necessary terminal and internal state cleanup upon receipt of a signal. +@deftypefun int rl_pending_signal (void) +Return the signal number of the most recent signal Readline received but +has not yet handled, or 0 if there is no pending signal. +@end deftypefun + @deftypefun void rl_cleanup_after_signal (void) This function will reset the state of the terminal to what it was before @code{readline()} was called, and remove the Readline signal handlers for diff --git a/doc/version.texi b/doc/version.texi index 766864a..9dc2998 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -4,7 +4,7 @@ Copyright (C) 1988-2016 Free Software Foundation, Inc. @set EDITION 7.0 @set VERSION 7.0 -@set UPDATED 20 April 2016 -@set UPDATED-MONTH April 2016 +@set UPDATED 16 July 2016 +@set UPDATED-MONTH July 2016 -@set LASTCHANGE Wed Apr 20 13:32:48 PDT 2016 +@set LASTCHANGE Sat Jul 16 13:43:15 EDT 2016 diff --git a/examples/Makefile.in b/examples/Makefile.in index 5723658..5094c6c 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -123,7 +123,7 @@ rl-callbacktest$(EXEEXT): rl-callbacktest.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ rl-callbacktest.o $(READLINE_LIB) $(TERMCAP_LIB) rlptytest$(EXEEXT): rlptytest.o $(READLINE_LIB) - $(CC) $(LDFLAGS) -o $@ rlptytest.o $(READLINE_LIB) $(TERMCAP_LIB) + $(CC) $(LDFLAGS) -o $@ rlptytest.o $(READLINE_LIB) $(TERMCAP_LIB) $(LIBUTIL) rlversion$(EXEEXT): rlversion.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ rlversion.o $(READLINE_LIB) $(TERMCAP_LIB) diff --git a/examples/rl-callbacktest.c b/examples/rl-callbacktest.c index 0f00e57..3525ffd 100644 --- a/examples/rl-callbacktest.c +++ b/examples/rl-callbacktest.c @@ -2,11 +2,14 @@ #include #include #include +#include /* Used for select(2) */ #include #include +#include + #include #include @@ -22,10 +25,19 @@ extern int errno; static void cb_linehandler (char *); +static void signandler (int); -int running; +int running, sigwinch_received; const char *prompt = "rltest$ "; +/* Handle SIGWINCH and window size changes when readline is not active and + reading a character. */ +static void +sighandler (int sig) +{ + sigwinch_received = 1; +} + /* Callback function called for each line when accept-line executed, EOF seen, or EOF character read. This sets a flag and returns; it could also call exit(3). */ @@ -60,6 +72,12 @@ main (int c, char **v) fd_set fds; int r; + + setlocale (LC_ALL, ""); + + /* Handle SIGWINCH */ + signal (SIGWINCH, sighandler); + /* Install the line handler. */ rl_callback_handler_install (prompt, cb_linehandler); @@ -80,6 +98,13 @@ main (int c, char **v) rl_callback_handler_remove (); break; } + if (sigwinch_received) + { + rl_resize_terminal (); + sigwinch_received = 0; + } + if (r < 0) + continue; if (FD_ISSET (fileno (rl_instream), &fds)) rl_callback_read_char (); diff --git a/examples/rlptytest.c b/examples/rlptytest.c index 0699e86..9c42f8a 100644 --- a/examples/rlptytest.c +++ b/examples/rlptytest.c @@ -48,6 +48,13 @@ sigint (s) exit (0); } +void +sigwinch (s) + int s; +{ + rl_resize_terminal (); +} + static int user_input() { @@ -316,6 +323,7 @@ main() if (val == -1) return -1; + signal (SIGWINCH, sigwinch); signal (SIGINT, sigint); val = init_readline (slavefd, slavefd); diff --git a/histexpand.c b/histexpand.c index 457cdb4..46a99aa 100644 --- a/histexpand.c +++ b/histexpand.c @@ -1220,7 +1220,7 @@ history_expand (hstring, output) ADD_STRING (temp); xfree (temp); } - only_printing = r == 1; + only_printing += r == 1; i = eindex; } break; diff --git a/readline.h b/readline.h index 0bd2e04..924bbfb 100644 --- a/readline.h +++ b/readline.h @@ -442,6 +442,8 @@ extern void rl_cleanup_after_signal PARAMS((void)); extern void rl_reset_after_signal PARAMS((void)); extern void rl_free_line_state PARAMS((void)); +extern int rl_pending_signal PARAMS((void)); + extern void rl_echo_signal_char PARAMS((int)); extern int rl_set_paren_blink_timeout PARAMS((int)); @@ -640,7 +642,7 @@ extern rl_compentry_func_t *rl_completion_entry_function; /* Optional generator for menu completion. Default is rl_completion_entry_function (rl_filename_completion_function). */ - extern rl_compentry_func_t *rl_menu_completion_entry_function; +extern rl_compentry_func_t *rl_menu_completion_entry_function; /* If rl_ignore_some_completions_function is non-NULL it is the address of a function to call after all of the possible matches have been @@ -832,6 +834,14 @@ extern int rl_ignore_completion_duplicates; completion character will be inserted as any other. */ extern int rl_inhibit_completion; +/* Applications can set this to non-zero to have readline's signal handlers + installed during the entire duration of reading a complete line, as in + readline-6.2. This should be used with care, because it can result in + readline receiving signals and not handling them until it's called again + via rl_callback_read_char, thereby stealing them from the application. + By default, signal handlers are only active while readline is active. */ +extern int rl_persistent_signal_handlers; + /* Input error; can be returned by (*rl_getc_function) if readline is reading a top-level command (RL_ISSTATE (RL_STATE_READCMD)). */ #define READERR (-2) diff --git a/signals.c b/signals.c index 4c542b3..0b8dda4 100644 --- a/signals.c +++ b/signals.c @@ -1,6 +1,6 @@ /* signals.c -- signal handling support for readline. */ -/* Copyright (C) 1987-2015 Free Software Foundation, Inc. +/* Copyright (C) 1987-2016 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. @@ -585,6 +585,11 @@ rl_free_line_state () _rl_reset_argument (); } +int +rl_pending_signal () +{ + return (_rl_caught_signal); +} #endif /* HANDLE_SIGNALS */ /* **************************************************************** */ diff --git a/tilde.c b/tilde.c index 3788eba..95bc421 100644 --- a/tilde.c +++ b/tilde.c @@ -236,7 +236,11 @@ tilde_expand (string) string += end; expansion = tilde_expand_word (tilde_word); - xfree (tilde_word); + + if (expansion == 0) + expansion = tilde_word; + else + xfree (tilde_word); len = strlen (expansion); #ifdef __CYGWIN__