From: Chet Ramey Date: Tue, 28 Jan 2025 19:56:36 +0000 (-0500) Subject: fix to history search so it doesn't change the offset in the history list; fix to... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bcabd92f35444fa87ed49bd180a2994fd9449ba;p=thirdparty%2Freadline.git fix to history search so it doesn't change the offset in the history list; fix to avoid crash in readline `abort' if there is a command queued to execute; slight change to export-completions output format; fix for redisplay when a prompt spans multiple lines with invisible characters; change to have readline set the screen size on SIGCONT --- diff --git a/complete.c b/complete.c index 473f04d..79026de 100644 --- a/complete.c +++ b/complete.c @@ -3066,7 +3066,10 @@ _rl_export_completions (char **matches, char *text, int start, int end) fprintf (rl_outstream, "%s\n", text); fprintf (rl_outstream, "%d:%d\n", start, end); /* : because it's not a radix character */ for (i = 0; i < len; i++) - fprintf (rl_outstream, "%s\n", matches[i]); + { + print_filename (matches[i], matches[i], 0); + fprintf (rl_outstream, "\n"); + } fflush (rl_outstream); } diff --git a/config.h.in b/config.h.in index dd0a956..06a7e47 100644 --- a/config.h.in +++ b/config.h.in @@ -158,6 +158,12 @@ /* Define if you have the tcgetattr function. */ #undef HAVE_TCGETATTR +/* Define if you have the tcgetwinsize function. */ +#undef HAVE_TCGETWINSIZE + +/* Define if you have the tcsetwinsize function. */ +#undef HAVE_TCSETWINSIZE + /* Define if you have the towlower function. */ #undef HAVE_TOWLOWER diff --git a/configure b/configure index eb2c1bf..f3e20c5 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac for Readline 8.3, version 2.101. +# From configure.ac for Readline 8.3, version 2.102. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.72 for readline 8.3. # @@ -5266,6 +5266,18 @@ if test "x$ac_cv_func_tcgetattr" = xyes then : printf "%s\n" "#define HAVE_TCGETATTR 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "tcgetwinsize" "ac_cv_func_tcgetwinsize" +if test "x$ac_cv_func_tcgetwinsize" = xyes +then : + printf "%s\n" "#define HAVE_TCGETWINSIZE 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "tcsetwinsize" "ac_cv_func_tcsetwinsize" +if test "x$ac_cv_func_tcsetwinsize" = xyes +then : + printf "%s\n" "#define HAVE_TCSETWINSIZE 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf" if test "x$ac_cv_func_vsnprintf" = xyes @@ -6872,13 +6884,6 @@ printf "%s\n" "not found" >&6; } fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for struct dirent.d_ino" >&5 -printf %s "checking for struct dirent.d_ino... " >&6; } -if test ${bash_cv_dirent_has_d_ino+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) ac_fn_c_check_member "$LINENO" "struct dirent" "d_ino" "ac_cv_member_struct_dirent_d_ino" " #include @@ -6907,31 +6912,11 @@ then : printf "%s\n" "#define HAVE_STRUCT_DIRENT_D_INO 1" >>confdefs.h -bash_cv_dirent_has_d_ino=yes -else case e in #( - e) bash_cv_dirent_has_d_ino=no ;; -esac -fi - ;; -esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bash_cv_dirent_has_d_ino" >&5 -printf "%s\n" "$bash_cv_dirent_has_d_ino" >&6; } -if test $bash_cv_dirent_has_d_ino = yes; then -printf "%s\n" "#define HAVE_STRUCT_DIRENT_D_INO 1" >>confdefs.h - -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for struct dirent.d_fileno" >&5 -printf %s "checking for struct dirent.d_fileno... " >&6; } -if test ${bash_cv_dirent_has_d_fileno+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) ac_fn_c_check_member "$LINENO" "struct dirent" "d_fileno" "ac_cv_member_struct_dirent_d_fileno" " #include @@ -6960,22 +6945,9 @@ then : printf "%s\n" "#define HAVE_STRUCT_DIRENT_D_FILENO 1" >>confdefs.h -bash_cv_dirent_has_d_fileno=yes -else case e in #( - e) bash_cv_dirent_has_d_fileno=no ;; -esac -fi - ;; -esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bash_cv_dirent_has_d_fileno" >&5 -printf "%s\n" "$bash_cv_dirent_has_d_fileno" >&6; } -if test $bash_cv_dirent_has_d_fileno = yes; then -printf "%s\n" "#define HAVE_STRUCT_DIRENT_D_FILENO 1" >>confdefs.h - -fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for struct timeval in sys/time.h and time.h" >&5 printf %s "checking for struct timeval in sys/time.h and time.h... " >&6; } diff --git a/configure.ac b/configure.ac index 1783dae..b270ab7 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ dnl Process this file with autoconf to produce a configure script. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_REVISION([for Readline 8.3, version 2.101]) +AC_REVISION([for Readline 8.3, version 2.102]) AC_INIT(readline, 8.3, bug-readline@gnu.org) @@ -151,8 +151,9 @@ AC_HEADER_STAT AC_HEADER_DIRENT AC_CHECK_FUNCS(fcntl gettimeofday kill lstat pselect readlink select setitimer) -AC_CHECK_FUNCS(fnmatch memmove putenv setenv setlocale \ - strcasecmp strpbrk sysconf tcgetattr vsnprintf) +AC_CHECK_FUNCS(fnmatch memmove putenv setenv setlocale strcasecmp \ + strpbrk sysconf tcgetattr tcgetwinsize tcsetwinsize \ + vsnprintf) AC_CHECK_FUNCS(isascii isxdigit) AC_CHECK_FUNCS(getpwent getpwnam getpwuid) diff --git a/display.c b/display.c index f002369..dcc5e80 100644 --- a/display.c +++ b/display.c @@ -1489,7 +1489,7 @@ rl_redisplay (void) but the buffer position needs to be adjusted to account for invisible characters. */ if ((mb_cur_max == 1 || rl_byte_oriented) && cursor_linenum == prompt_last_screen_line) - _rl_last_c_pos = physpos + WRAP_OFFSET (cursor_linenum, wrap_offset);; + _rl_last_c_pos = physpos + WRAP_OFFSET (cursor_linenum, wrap_offset); } /* Now we move the cursor to where it needs to be. First, make @@ -1502,28 +1502,53 @@ rl_redisplay (void) invisible character in the prompt string. */ /* XXX - why not use local_prompt_len? */ nleft = prompt_visible_length + wrap_offset; - if (cursor_linenum == prompt_last_screen_line && wrap_offset > 0 && - _rl_last_c_pos > 0 && local_prompt && - _rl_last_c_pos < PROMPT_ENDING_INDEX) + if (cursor_linenum == prompt_last_screen_line) { - int pmt_offset; - - _rl_cr (); - if (modmark) - _rl_output_some_chars ("*", 1); - - /* If the number of characters in local_prompt is greater than - the screen width, the prompt wraps. We only want to print the - portion after the line wrap. */ - pmt_offset = local_prompt_newlines[cursor_linenum]; - if (cursor_linenum > 0 && pmt_offset > 0 && nleft > pmt_offset) - _rl_output_some_chars (local_prompt + pmt_offset, nleft - pmt_offset); - else - _rl_output_some_chars (local_prompt, nleft); - if (mb_cur_max > 1 && rl_byte_oriented == 0) - _rl_last_c_pos = _rl_col_width (local_prompt, 0, nleft, 1) - wrap_offset + modmark; + int pmt_offset = local_prompt_newlines ? local_prompt_newlines[cursor_linenum] : 0; + int curline_invchars = local_prompt_invis_chars ? local_prompt_invis_chars[cursor_linenum] : wrap_offset; + int cursor_bufpos; + + /* cursor_bufpos is where the portion of the prompt that appears + on the current screen line begins in the buffer. It is a + buffer position, an index into curline + (local_prompt + pmt_offset) */ + cursor_bufpos = pmt_offset; + if (mb_cur_max == 1 || rl_byte_oriented) + cursor_bufpos += _rl_last_c_pos; else - _rl_last_c_pos = nleft + modmark; /* buffer position */ + cursor_bufpos += _rl_last_c_pos + curline_invchars; + + if (local_prompt && local_prompt_invis_chars[cursor_linenum] && + _rl_last_c_pos > 0 && + cursor_bufpos <= prompt_last_invisible) + { + _rl_cr (); + if (modmark) + _rl_output_some_chars ("*", 1); + + /* If the number of characters in local_prompt is greater + than the screen width, the prompt wraps. We only want to + print the portion after the line wrap. */ + + /* Make sure we set _rl_last_c_pos based on the number of + characters we actually output, since we start at column 0. */ + if (cursor_linenum > 0 && pmt_offset > 0 && nleft > pmt_offset) + _rl_output_some_chars (local_prompt + pmt_offset, nleft - pmt_offset); + else + { + _rl_output_some_chars (local_prompt, nleft); + pmt_offset = 0; /* force for calculation below */ + } + + if (mb_cur_max > 1 && rl_byte_oriented == 0) + /* Start width calculation where we started output. */ + _rl_last_c_pos = _rl_col_width (local_prompt, pmt_offset, nleft, 1) - WRAP_OFFSET(cursor_linenum, wrap_offset) + modmark; + else + /* Index into invisible_line+inv_lbreaks[cursor_linenum], + since that's what we use in the call to + _rl_move_cursor_relative below. */ + _rl_last_c_pos = nleft + modmark - inv_lbreaks[cursor_linenum]; /* buffer position */ + } } /* Where on that line? And where does that line start diff --git a/doc/history.3 b/doc/history.3 index 514d6f8..53be120 100644 --- a/doc/history.3 +++ b/doc/history.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Fri Nov 29 18:17:58 EST 2024 +.\" Last Change: Tue Dec 31 13:35:52 EST 2024 .\" -.TH HISTORY 3 "2024 November 29" "GNU History 8.3" +.TH HISTORY 3 "2024 December 31" "GNU History 8.3" .\" .ie \n(.g \{\ .ds ' \(aq @@ -79,8 +79,8 @@ .SH NAME history \- GNU History Library .SH COPYRIGHT -.if t The GNU History Library is Copyright \(co 1989-2024 by the Free Software Foundation, Inc. -.if n The GNU History Library is Copyright (C) 1989-2024 by the Free Software Foundation, Inc. +.if t The GNU History Library is Copyright \(co 1989-2025 by the Free Software Foundation, Inc. +.if n The GNU History Library is Copyright (C) 1989-2025 by the Free Software Foundation, Inc. .SH DESCRIPTION Many programs read input from the user a line at a time. The GNU @@ -495,7 +495,8 @@ The history list will contain only \fImax\fP entries at a time. .F1 int unstifle_history "void" Stop stifling the history. This returns the previously-set maximum number of history entries (as set by \fBstifle_history()\fP). -history was stifled. The value is positive if the history was +history was stifled. +The value is positive if the history was stifled, negative if it wasn't. .PP .F1 int history_is_stifled "void" diff --git a/doc/history.texi b/doc/history.texi index 247e208..e78773e 100644 --- a/doc/history.texi +++ b/doc/history.texi @@ -1,4 +1,4 @@ -\input texinfo @c -*-texinfo-*- +c\input texinfo @c -*-texinfo-*- @c %**start of header (This is for running Texinfo on a region.) @setfilename history.info @settitle GNU History Library @@ -12,7 +12,7 @@ This document describes the GNU History library a programming tool that provides a consistent user interface for recalling lines of previously typed input. -Copyright @copyright{} 1988--2024 Free Software Foundation, Inc. +Copyright @copyright{} 1988--2025 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document diff --git a/doc/hstech.texi b/doc/hstech.texi index c1c15b0..82ff77c 100644 --- a/doc/hstech.texi +++ b/doc/hstech.texi @@ -1,7 +1,7 @@ @ignore This file documents the user interface to the GNU History library. -Copyright (C) 1988-2024 Free Software Foundation, Inc. +Copyright (C) 1988-2025 Free Software Foundation, Inc. Authored by Brian Fox and Chet Ramey. Permission is granted to make and distribute verbatim copies of this manual @@ -36,7 +36,7 @@ For information on the interactive use of @sc{gnu} History, * Introduction to History:: What is the GNU History library for? * History Storage:: How information is stored. * History Functions:: Functions that you can use. -* History Variables:: Variables that control behaviour. +* History Variables:: Variables that control behavior. * History Programming Example:: Example of using the GNU History Library. @end menu diff --git a/doc/hsuser.texi b/doc/hsuser.texi index 04b25d1..5bce1c3 100644 --- a/doc/hsuser.texi +++ b/doc/hsuser.texi @@ -1,7 +1,7 @@ @ignore This file documents the user interface to the GNU History library. -Copyright (C) 1988--2024 Free Software Foundation, Inc. +Copyright (C) 1988--2025 Free Software Foundation, Inc. Authored by Brian Fox and Chet Ramey. Permission is granted to make and distribute verbatim copies of this manual @@ -504,6 +504,8 @@ It may be omitted if the word designator begins with a @samp{^}, @samp{$}, @samp{*}, @samp{-}, or @samp{%}. Words are numbered from the beginning of the line, with the first word being denoted by 0 (zero). +That first word is usually the command word, and the arguments begin +with the second word. Words are inserted into the current line separated by single spaces. @need 0.75 @@ -515,7 +517,7 @@ designates the preceding command. When you type this, the preceding command is repeated in toto. @item !!:$ -designates the last argument of the preceding command. +designates the last word of the preceding command. This may be shortened to @code{!$}. @item !fi:2 diff --git a/doc/readline.3 b/doc/readline.3 index 3a66a9c..3c1ef48 100644 --- a/doc/readline.3 +++ b/doc/readline.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Fri Nov 29 18:17:27 EST 2024 +.\" Last Change: Mon Dec 30 11:27:47 EST 2024 .\" -.TH READLINE 3 "2024 November 29" "GNU Readline 8.3" +.TH READLINE 3 "2024 December 30" "GNU Readline 8.3" .\" .ie \n(.g \{\ .ds ' \(aq @@ -60,8 +60,8 @@ readline \- get a line from a user with editing \fBreadline\fP (\fIconst char *prompt\fP); .fi .SH COPYRIGHT -.if n Readline is Copyright (C) 1989\-2024 Free Software Foundation, Inc. -.if t Readline is Copyright \(co 1989\-2024 Free Software Foundation, Inc. +.if n Readline is Copyright (C) 1989\-2025 Free Software Foundation, Inc. +.if t Readline is Copyright \(co 1989\-2025 Free Software Foundation, Inc. .SH DESCRIPTION .LP .B readline @@ -1248,7 +1248,7 @@ Negative arguments have no effect. .TP .B transpose\-words (M\-t) Drag the word before point past the word after point, -moving point over that word as well. +moving point past that word as well. If point is at the end of the line, this transposes the last two words on the line. .TP @@ -1438,7 +1438,7 @@ the number of matches \fIN\fP; the word being completed; .IP \(bu \fIS\fP:\fIE\fP, -where S and E are the start and end offsets of the word +where \fIS\fP and \fIE\fP are the start and end offsets of the word in the \fBreadline\fP line buffer; then .IP \(bu each match, one per line diff --git a/doc/rlman.texi b/doc/rlman.texi index d016c76..9049709 100644 --- a/doc/rlman.texi +++ b/doc/rlman.texi @@ -13,7 +13,7 @@ This manual describes the GNU Readline Library consistency of user interface across discrete programs which provide a command line interface. -Copyright @copyright{} 1988--2024 Free Software Foundation, Inc. +Copyright @copyright{} 1988--2025 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document diff --git a/doc/rltech.texi b/doc/rltech.texi index dadca6a..c8965ef 100644 --- a/doc/rltech.texi +++ b/doc/rltech.texi @@ -7,7 +7,7 @@ This document describes the GNU Readline Library, a utility for aiding in the consistency of user interface across discrete programs that need to provide a command line interface. -Copyright (C) 1988--2024 Free Software Foundation, Inc. +Copyright (C) 1988--2025 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -58,7 +58,7 @@ in your own programs, this section is for you. Many programs provide a command line interface, such as @code{mail}, @code{ftp}, and @code{sh}. -For such programs, the default behaviour of Readline is sufficient. +For such programs, the default behavior of Readline is sufficient. This section describes how to use Readline in the simplest way possible, perhaps to replace calls in your code to @code{fgets()}. @@ -149,7 +149,7 @@ rl_gets () @} @end example -This function gives the user the default behaviour of @key{TAB} +This function gives the user the default behavior of @key{TAB} completion: filename completion. If you do not want Readline to complete filenames, you can change the binding of the @key{TAB} key @@ -768,7 +768,7 @@ The caller should free @var{keymap}. @deftypefun void rl_free_keymap (Keymap keymap) Free all storage associated with @var{keymap}. -This calls @code{rl_discard_keymap} to free subordindate +This calls @code{rl_discard_keymap} to free subordinate keymaps and macros. @end deftypefun @@ -1168,7 +1168,7 @@ displaying a new message in the message area with @code{rl_message()}. @deftypefun void rl_restore_prompt (void) Restore the local Readline prompt display state saved by the most recent call to @code{rl_save_prompt}. -if you called @code{rl_save_prompt} to save the prompt before a call +If you called @code{rl_save_prompt} to save the prompt before a call to @code{rl_message}, you should call this function before the corresponding call to @code{rl_clear_message}. @end deftypefun diff --git a/doc/rluser.texi b/doc/rluser.texi index 757661b..27078b5 100644 --- a/doc/rluser.texi +++ b/doc/rluser.texi @@ -11,7 +11,7 @@ use these features. There is a document entitled "readline.texinfo" which contains both end-user and programmer documentation for the GNU Readline Library. -Copyright (C) 1988--2024 Free Software Foundation, Inc. +Copyright (C) 1988--2025 Free Software Foundation, Inc. Authored by Brian Fox and Chet Ramey. @@ -466,9 +466,10 @@ A sample value might be @samp{\e[01;33m}. @item active-region-end-color @vindex active-region-end-color -A string variable that "undoes" the effects of @code{active-region-start-color} -and restores "normal" terminal display appearance after displaying text -in the active region. +A string variable that ``undoes'' +the effects of @code{active-region-start-color} +and restores ``normal'' +terminal display appearance after displaying text in the active region. This string must not take up any physical character positions on the display, so it should consist only of terminal escape sequences. It is output to the terminal after displaying the text in the active region. @@ -703,7 +704,7 @@ are saved. If set to a value less than zero, the number of history entries is not limited. @ifset BashFeatures -By default, Bash sets the the maximum number of history entries to +By default, Bash sets the maximum number of history entries to the value of the @code{HISTSIZE} shell variable. @end ifset @ifclear BashFeatures @@ -1055,7 +1056,7 @@ The eight-bit character whose value is the hexadecimal value @var{HH} When entering the text of a macro, single or double quotes must be used to indicate a macro definition. Unquoted text is assumed to be a function name. -Tthe backslash escapes described above are expanded +The backslash escapes described above are expanded in the macro body. Backslash will quote any other character in the macro text, including @samp{"} and @samp{'}. @@ -1188,7 +1189,7 @@ binding, variable assignment, and conditional syntax. @example @page -# This file controls the behaviour of line input editing for +# This file controls the behavior of line input editing for # programs that use the GNU Readline library. Existing # programs include FTP, Bash, and GDB. # @@ -1316,10 +1317,13 @@ In the following descriptions, @dfn{point} refers to the current cursor position, and @dfn{mark} refers to a cursor position saved by the @code{set-mark} command. The text between the point and mark is referred to as the @dfn{region}. -Readline has the concept of an @emph{active region}: +Readline +has the concept of an @emph{active region}: when the region is active, Readline redisplay highlights the region using the -value of the @code{active-region-start-color} variable. +value of the +@code{active-region-start-color} +variable. The @code{enable-active-region} variable turns this on and off. Several commands set the region to active; those are noted below. @@ -1806,7 +1810,7 @@ the number of matches @var{N}; the word being completed; @item @var{S}:@var{E}, -where S and E are the start and end offsets of the word +where @var{S} and @var{E} are the start and end offsets of the word in the Readline line buffer; then @item each match, one per line @@ -2057,7 +2061,7 @@ Expand the line by performing shell word expansions. This performs alias and history expansion, $'@var{string}' and $"@var{string}" quoting, tilde expansion, parameter and variable expansion, arithmetic expansion, -command and proces substitution, +command and process substitution, word splitting, and quote removal. An explicit argument suppresses command and process substitution. diff --git a/doc/rluserman.texi b/doc/rluserman.texi index 51255ca..6265c63 100644 --- a/doc/rluserman.texi +++ b/doc/rluserman.texi @@ -12,7 +12,7 @@ This manual describes the end user interface of the GNU Readline Library consistency of user interface across discrete programs which provide a command line interface. -Copyright @copyright{} 1988--2024 Free Software Foundation, Inc. +Copyright @copyright{} 1988--2025 Free Software Foundation, Inc. @quotation Permission is granted to copy, distribute and/or modify this document diff --git a/doc/version.texi b/doc/version.texi index 5353622..9faa386 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,11 +1,11 @@ @ignore -Copyright (C) 1988-2024 Free Software Foundation, Inc. +Copyright (C) 1988-2025 Free Software Foundation, Inc. @end ignore @set EDITION 8.3 @set VERSION 8.3 -@set UPDATED 29 November 2024 -@set UPDATED-MONTH November 2024 +@set UPDATED 30 December 2024 +@set UPDATED-MONTH December 2024 -@set LASTCHANGE Fri Nov 29 18:18:20 EST 2024 +@set LASTCHANGE Mon Dec 30 11:27:03 EST 2024 diff --git a/histexpand.c b/histexpand.c index 068fecc..fc0008e 100644 --- a/histexpand.c +++ b/histexpand.c @@ -141,7 +141,7 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote) register char c; HIST_ENTRY *entry; int which, sign, local_index, substring_okay; - int search_flags; + int search_flags, old_offset; char *temp; /* The event can be specified in a number of ways. @@ -251,9 +251,10 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote) *caller_index = i; + old_offset = history_offset; /* XXX */ #define FAIL_SEARCH() \ do { \ - history_offset = history_length; xfree (temp) ; return (char *)NULL; \ + history_offset = old_offset; xfree (temp) ; return (char *)NULL; \ } while (0) /* If there is no search string, try to use the previous search string, @@ -282,7 +283,7 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote) entry = current_history (); if (entry == 0) FAIL_SEARCH (); - history_offset = history_length; + history_offset = old_offset; /* XXX - was history_length */ /* If this was a substring search, then remember the string that we matched for word substitution. */ diff --git a/rlprivate.h b/rlprivate.h index 23cf8d3..ac1de28 100644 --- a/rlprivate.h +++ b/rlprivate.h @@ -640,6 +640,7 @@ extern int _rl_history_search_pos; /* signals.c */ extern int volatile _rl_caught_signal; +extern int volatile _rl_handling_signal; extern _rl_sigcleanup_func_t *_rl_sigcleanup; extern void *_rl_sigcleanarg; diff --git a/rltty.c b/rltty.c index a4ad94c..9681775 100644 --- a/rltty.c +++ b/rltty.c @@ -80,15 +80,25 @@ static int ksrflow; #endif /* Dummy call to force a backgrounded readline to stop before it tries - to get the tty settings. */ + to get the tty settings. But we use the information to set our idea + of the screen size if we're in a signal handling context, since it + doesn't make sense to waste it. */ static void set_winsize (int tty) { -#if defined (TIOCGWINSZ) +#if defined (TIOCGWINSZ) || defined (HAVE_TCGETWINSIZE) struct winsize w; - - if (ioctl (tty, TIOCGWINSZ, &w) == 0) - (void) ioctl (tty, TIOCSWINSZ, &w); + + if (_rl_tcgetwinsize (tty, &w) == 0) + { + (void) _rl_tcsetwinsize (tty, &w); + /* We restrict this to the case where we're running a signal handler + and executing after a SIGTSTP. We can relax it later. */ +#if defined (SIGTSTP) + if (RL_ISSTATE (RL_STATE_SIGHANDLER) && _rl_handling_signal == SIGTSTP && rl_prefer_env_winsize == 0) + _rl_set_screen_size (w.ws_row, w.ws_col); /* don't waste the info */ +#endif + } #endif /* TIOCGWINSZ */ } diff --git a/rlwinsize.h b/rlwinsize.h index d198fcf..3d1c97f 100644 --- a/rlwinsize.h +++ b/rlwinsize.h @@ -55,4 +55,7 @@ # define tcflow(fd, action) ioctl(fd, TCXONC, action) #endif +extern int _rl_tcgetwinsize (int, struct winsize *); +extern void _rl_tcsetwinsize (int, struct winsize *); + #endif /* _RL_WINSIZE_H */ diff --git a/signals.c b/signals.c index 1cdb762..8c4f3fa 100644 --- a/signals.c +++ b/signals.c @@ -88,6 +88,7 @@ int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */ /* Private variables. */ int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including everywhere */ +int volatile _rl_handling_signal = 0; /* If non-zero, print characters corresponding to received signals as long as the user has indicated his desire to do so (_rl_echo_control_chars). */ @@ -133,6 +134,7 @@ _rl_signal_handler (int sig) if (sig == SIGWINCH) { RL_SETSTATE(RL_STATE_SIGHANDLER); + _rl_handling_signal = SIGWINCH; rl_resize_terminal (); /* XXX - experimental for now */ @@ -142,6 +144,7 @@ _rl_signal_handler (int sig) if (rl_signal_event_hook) (*rl_signal_event_hook) (); + _rl_handling_signal = 0; RL_UNSETSTATE(RL_STATE_SIGHANDLER); } else @@ -177,6 +180,7 @@ _rl_handle_signal (int sig) #endif /* !HAVE_POSIX_SIGNALS */ RL_SETSTATE(RL_STATE_SIGHANDLER); + _rl_handling_signal = sig; #if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS) /* Since the signal will not be blocked while we are in the signal @@ -301,6 +305,7 @@ _rl_handle_signal (int sig) rl_reset_after_signal (); } + _rl_handling_signal = 0; RL_UNSETSTATE(RL_STATE_SIGHANDLER); SIGHANDLER_RETURN; } diff --git a/terminal.c b/terminal.c index 7003d2a..2c70553 100644 --- a/terminal.c +++ b/terminal.c @@ -258,6 +258,30 @@ _win_get_screensize (int *swp, int *shp) } #endif +int +_rl_tcgetwinsize (int tty, struct winsize *wp) +{ +#if defined (HAVE_TCGETWINSIZE) + return (tcgetwinsize (tty, wp)); +#elif defined (TIOCGWINSZ) + return (ioctl (tty, TIOCGWINSZ, wp)); +#else + return -1; +#endif +} + +void +_rl_tcsetwinsize (int tty, struct winsize *wp) +{ +#if defined (HAVE_TCGETWINSIZE) + tcsetwinsize (tty, wp); +#elif defined (TIOCGWINSZ) + ioctl (tty, TIOCSWINSZ, wp); +#else + ; +#endif +} + /* Get readline's idea of the screen size. TTY is a file descriptor open to the terminal. If IGNORE_ENV is true, we do not pay attention to the values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being @@ -266,19 +290,19 @@ void _rl_get_screen_size (int tty, int ignore_env) { char *ss; -#if defined (TIOCGWINSZ) +#if defined (TIOCGWINSZ) || defined (HAVE_TCGETWINSIZE) struct winsize window_size; -#endif /* TIOCGWINSZ */ +#endif /* TIOCGWINSZ || HAVE_TCGETWINSIZE */ int wr, wc; wr = wc = -1; -#if defined (TIOCGWINSZ) - if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) +#if defined (TIOCGWINSZ) || defined (HAVE_TCGETWINSIZE) + if (_rl_tcgetwinsize (tty, &window_size) == 0) { wc = (int) window_size.ws_col; wr = (int) window_size.ws_row; } -#endif /* TIOCGWINSZ */ +#endif /* TIOCGWINSZ || HAVE_TCGETWINSIZE */ #if defined (__EMX__) _emx_get_screensize (&wc, &wr); diff --git a/util.c b/util.c index d03c899..0a5df9b 100644 --- a/util.c +++ b/util.c @@ -112,6 +112,7 @@ _rl_abort_internal (void) RL_UNSETSTATE (RL_STATE_MULTIKEY); /* XXX */ rl_last_func = (rl_command_func_t *)NULL; + _rl_command_to_execute = 0; _rl_longjmp (_rl_top_level, 1); return (0);