From 5bdf8622148be4764cc0757fd5b3e41f4d73b2b2 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Fri, 5 May 2006 18:26:14 +0000 Subject: Readline 5.1 import for HEAD. --- readline/terminal.c | 102 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 33 deletions(-) (limited to 'readline/terminal.c') diff --git a/readline/terminal.c b/readline/terminal.c index ce45d28..21732a7 100644 --- a/readline/terminal.c +++ b/readline/terminal.c @@ -1,6 +1,6 @@ /* terminal.c -- controlling the terminal with termcap. */ -/* Copyright (C) 1996 Free Software Foundation, Inc. +/* Copyright (C) 1996-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -78,6 +78,8 @@ #define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay) #define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc) +int rl_prefer_env_winsize; + /* **************************************************************** */ /* */ /* Terminal and Termcap */ @@ -87,9 +89,6 @@ #ifndef __MSDOS__ static char *term_buffer = (char *)NULL; static char *term_string_buffer = (char *)NULL; - -/* Non-zero means this terminal can't really do anything. */ -static int dumb_term; #endif /* !__MSDOS__ */ static int tcap_initialized; @@ -134,7 +133,7 @@ char *_rl_term_up; static char *_rl_visible_bell; /* Non-zero means the terminal can auto-wrap lines. */ -int _rl_term_autowrap; +int _rl_term_autowrap = -1; /* Non-zero means that this terminal has a meta key. */ static int term_has_meta; @@ -159,6 +158,9 @@ static char *_rl_term_kh; static char *_rl_term_kH; static char *_rl_term_at7; /* @7 */ +/* Delete key */ +static char *_rl_term_kD; + /* Insert key */ static char *_rl_term_kI; @@ -205,12 +207,14 @@ _rl_get_screen_size (tty, ignore_env) #if defined (TIOCGWINSZ) struct winsize window_size; #endif /* TIOCGWINSZ */ + int wr, wc; + wr = wc = -1; #if defined (TIOCGWINSZ) if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) { - _rl_screenwidth = (int) window_size.ws_col; - _rl_screenheight = (int) window_size.ws_row; + wc = (int) window_size.ws_col; + wr = (int) window_size.ws_row; } #endif /* TIOCGWINSZ */ @@ -232,13 +236,25 @@ _rl_get_screen_size (tty, ignore_env) _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight); #endif + if (ignore_env || rl_prefer_env_winsize == 0) + { + _rl_screenwidth = wc; + _rl_screenheight = wr; + } + else + _rl_screenwidth = _rl_screenheight = -1; + /* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV - is unset. */ + is unset. If we prefer the environment, check it first before + assigning the value returned by the kernel. */ if (_rl_screenwidth <= 0) { if (ignore_env == 0 && (ss = sh_get_env_value ("COLUMNS"))) _rl_screenwidth = atoi (ss); + if (_rl_screenwidth <= 0) + _rl_screenwidth = wc; + #if defined (__DJGPP__) if (_rl_screenwidth <= 0) _rl_screenwidth = ScreenCols (); @@ -255,6 +271,9 @@ _rl_get_screen_size (tty, ignore_env) if (ignore_env == 0 && (ss = sh_get_env_value ("LINES"))) _rl_screenheight = atoi (ss); + if (_rl_screenheight <= 0) + _rl_screenheight = wr; + #if defined (__DJGPP__) if (_rl_screenheight <= 0) _rl_screenheight = ScreenRows (); @@ -286,16 +305,20 @@ void _rl_set_screen_size (rows, cols) int rows, cols; { - if (rows == 0 || cols == 0) - return; + if (_rl_term_autowrap == -1) + _rl_init_terminal_io (rl_terminal_name); - _rl_screenheight = rows; - _rl_screenwidth = cols; - - if (_rl_term_autowrap == 0) - _rl_screenwidth--; + if (rows > 0) + _rl_screenheight = rows; + if (cols > 0) + { + _rl_screenwidth = cols; + if (_rl_term_autowrap == 0) + _rl_screenwidth--; + } - _rl_screenchars = _rl_screenwidth * _rl_screenheight; + if (rows > 0 || cols > 0) + _rl_screenchars = _rl_screenwidth * _rl_screenheight; } void @@ -314,6 +337,12 @@ rl_get_screen_size (rows, cols) if (cols) *cols = _rl_screenwidth; } + +void +rl_reset_screen_size () +{ + _rl_get_screen_size (fileno (rl_instream), 0); +} void rl_resize_terminal () @@ -347,6 +376,7 @@ static struct _tc_string tc_strings[] = { "ei", &_rl_term_ei }, { "ic", &_rl_term_ic }, { "im", &_rl_term_im }, + { "kD", &_rl_term_kD }, /* delete */ { "kH", &_rl_term_kH }, /* home down ?? */ { "kI", &_rl_term_kI }, /* insert */ { "kd", &_rl_term_kd }, @@ -381,11 +411,7 @@ get_term_capabilities (bp) register int i; for (i = 0; i < NUM_TC_STRINGS; i++) -# ifdef __LCC__ *(tc_strings[i].tc_value) = tgetstr ((char *)tc_strings[i].tc_var, bp); -# else - *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp); -# endif #endif tcap_initialized = 1; } @@ -401,7 +427,6 @@ _rl_init_terminal_io (terminal_name) term = terminal_name ? terminal_name : sh_get_env_value ("TERM"); _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL; tty = rl_instream ? fileno (rl_instream) : 0; - _rl_screenwidth = _rl_screenheight = 0; if (term == 0) term = "dumb"; @@ -451,12 +476,17 @@ _rl_init_terminal_io (terminal_name) _rl_term_autowrap = 0; /* used by _rl_get_screen_size */ + /* Allow calling application to set default height and width, using + rl_set_screen_size */ + if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) + { #if defined (__EMX__) - _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight); - _rl_screenwidth--; + _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight); + _rl_screenwidth--; #else /* !__EMX__ */ - _rl_get_screen_size (tty, 0); + _rl_get_screen_size (tty, 0); #endif /* !__EMX__ */ + } /* Defaults. */ if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) @@ -471,7 +501,7 @@ _rl_init_terminal_io (terminal_name) _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL; _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL; _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL; - _rl_term_kh = _rl_term_kH = _rl_term_kI = (char *)NULL; + _rl_term_kh = _rl_term_kH = _rl_term_kI = _rl_term_kD = (char *)NULL; _rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL; _rl_term_mm = _rl_term_mo = (char *)NULL; _rl_term_ve = _rl_term_vs = (char *)NULL; @@ -503,7 +533,10 @@ _rl_init_terminal_io (terminal_name) _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); - _rl_get_screen_size (tty, 0); + /* Allow calling application to set default height and width, using + rl_set_screen_size */ + if (_rl_screenwidth <= 0 || _rl_screenheight <= 0) + _rl_get_screen_size (tty, 0); /* "An application program can assume that the terminal can do character insertion if *any one of* the capabilities `IC', @@ -542,13 +575,15 @@ bind_termcap_arrow_keys (map) xkeymap = _rl_keymap; _rl_keymap = map; - _rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history); - _rl_bind_if_unbound (_rl_term_kd, rl_get_next_history); - _rl_bind_if_unbound (_rl_term_kr, rl_forward); - _rl_bind_if_unbound (_rl_term_kl, rl_backward); + rl_bind_keyseq_if_unbound (_rl_term_ku, rl_get_previous_history); + rl_bind_keyseq_if_unbound (_rl_term_kd, rl_get_next_history); + rl_bind_keyseq_if_unbound (_rl_term_kr, rl_forward_char); + rl_bind_keyseq_if_unbound (_rl_term_kl, rl_backward_char); + + rl_bind_keyseq_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */ + rl_bind_keyseq_if_unbound (_rl_term_at7, rl_end_of_line); /* End */ - _rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */ - _rl_bind_if_unbound (_rl_term_at7, rl_end_of_line); /* End */ + rl_bind_keyseq_if_unbound (_rl_term_kD, rl_delete); _rl_keymap = xkeymap; } @@ -575,6 +610,7 @@ int rl_reset_terminal (terminal_name) const char *terminal_name; { + _rl_screenwidth = _rl_screenheight = 0; _rl_init_terminal_io (terminal_name); return 0; } @@ -656,8 +692,8 @@ rl_ding () tputs (_rl_visible_bell, 1, _rl_output_character_function); break; } -#endif /* FALLTHROUGH */ +#endif case AUDIBLE_BELL: fprintf (stderr, "\007"); fflush (stderr); -- cgit v1.1