1/* terminal.c -- controlling the terminal with termcap. */ 2 3/* Copyright (C) 1996 Free Software Foundation, Inc. 4 5 This file is part of the GNU Readline Library, a library for 6 reading lines of text with interactive input and history editing. 7 8 The GNU Readline Library is free software; you can redistribute it --- 5 unchanged lines hidden (view full) --- 14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 The GNU General Public License is often shipped with GNU software, and 19 is generally kept in a file called COPYING or LICENSE. If you do not 20 have a copy of the license, write to the Free Software Foundation, 21 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ |
22/* $FreeBSD: head/contrib/libreadline/terminal.c 119614 2003-08-31 18:29:38Z ache $ */ |
23#define READLINE_LIBRARY 24 25#if defined (HAVE_CONFIG_H) 26# include <config.h> 27#endif 28 29#include <sys/types.h> 30#include "posixstat.h" --- 29 unchanged lines hidden (view full) --- 60#include "tcap.h" 61 62/* Some standard library routines. */ 63#include "readline.h" 64#include "history.h" 65 66#include "rlprivate.h" 67#include "rlshell.h" |
68#include "xmalloc.h" |
69 |
70#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay) 71#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc) 72 |
73/* **************************************************************** */ 74/* */ 75/* Terminal and Termcap */ 76/* */ 77/* **************************************************************** */ 78 79static char *term_buffer = (char *)NULL; 80static char *term_string_buffer = (char *)NULL; --- 58 unchanged lines hidden (view full) --- 139 140/* How to initialize and reset the arrow keys, if this terminal has any. */ 141static char *_rl_term_ks; 142static char *_rl_term_ke; 143 144/* The key sequences sent by the Home and End keys, if any. */ 145static char *_rl_term_kh; 146static char *_rl_term_kH; |
147static char *_rl_term_at7; /* @7 */ |
148 |
149/* Insert key */ 150static char *_rl_term_kI; 151 152/* Cursor control */ 153static char *_rl_term_vs; /* very visible */ 154static char *_rl_term_ve; /* normal */ 155 156static void bind_termcap_arrow_keys PARAMS((Keymap)); 157 |
158/* Variables that hold the screen dimensions, used by the display code. */ 159int _rl_screenwidth, _rl_screenheight, _rl_screenchars; 160 161/* Non-zero means the user wants to enable the keypad. */ 162int _rl_enable_keypad; 163 164/* Non-zero means the user wants to enable a meta key. */ 165int _rl_enable_meta = 1; --- 117 unchanged lines hidden (view full) --- 283} 284 285void 286rl_resize_terminal () 287{ 288 if (readline_echoing_p) 289 { 290 _rl_get_screen_size (fileno (rl_instream), 1); |
291 if (CUSTOM_REDISPLAY_FUNC ()) 292 rl_forced_update_display (); 293 else 294 _rl_redisplay_after_sigwinch (); |
295 } 296} 297 298struct _tc_string { 299 const char *tc_var; 300 char **tc_value; 301}; 302 303/* This should be kept sorted, just in case we decide to change the 304 search algorithm to something smarter. */ 305static struct _tc_string tc_strings[] = 306{ |
307 { "@7", &_rl_term_at7 }, |
308 { "DC", &_rl_term_DC }, 309 { "IC", &_rl_term_IC }, 310 { "ce", &_rl_term_clreol }, 311 { "cl", &_rl_term_clrpag }, 312 { "cr", &_rl_term_cr }, 313 { "dc", &_rl_term_dc }, 314 { "ei", &_rl_term_ei }, 315 { "ic", &_rl_term_ic }, 316 { "im", &_rl_term_im }, |
317 { "kH", &_rl_term_kH }, /* home down ?? */ 318 { "kI", &_rl_term_kI }, /* insert */ |
319 { "kd", &_rl_term_kd }, |
320 { "ke", &_rl_term_ke }, /* end keypad mode */ |
321 { "kh", &_rl_term_kh }, /* home */ |
322 { "kl", &_rl_term_kl }, 323 { "kr", &_rl_term_kr }, |
324 { "ks", &_rl_term_ks }, /* start keypad mode */ |
325 { "ku", &_rl_term_ku }, |
326 { "le", &_rl_term_backspace }, 327 { "mm", &_rl_term_mm }, 328 { "mo", &_rl_term_mo }, 329#if defined (HACK_TERMCAP_MOTION) 330 { "nd", &_rl_term_forward_char }, 331#endif 332 { "pc", &_rl_term_pc }, 333 { "up", &_rl_term_up }, 334 { "vb", &_rl_visible_bell }, |
335 { "vs", &_rl_term_vs }, 336 { "ve", &_rl_term_ve }, |
337}; 338 339#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string)) 340 341/* Read the desired terminal capability strings into BP. The capabilities 342 are described in the TC_STRINGS table. */ 343static void 344get_term_capabilities (bp) 345 char **bp; 346{ 347#if !defined (__DJGPP__) /* XXX - doesn't DJGPP have a termcap library? */ 348 register int i; 349 350 for (i = 0; i < NUM_TC_STRINGS; i++) |
351# ifdef __LCC__ 352 *(tc_strings[i].tc_value) = tgetstr ((char *)tc_strings[i].tc_var, bp); 353# else |
354 *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp); |
355# endif |
356#endif 357 tcap_initialized = 1; 358} 359 |
360int 361_rl_init_terminal_io (terminal_name) 362 const char *terminal_name; 363{ 364 const char *term; 365 char *buffer; 366 int tty, tgetent_ret; |
367 368 term = terminal_name ? terminal_name : sh_get_env_value ("TERM"); 369 _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL; 370 tty = rl_instream ? fileno (rl_instream) : 0; 371 _rl_screenwidth = _rl_screenheight = 0; 372 373 if (term == 0) 374 term = "dumb"; 375 376 /* I've separated this out for later work on not calling tgetent at all 377 if the calling application has supplied a custom redisplay function, 378 (and possibly if the application has supplied a custom input function). */ 379 if (CUSTOM_REDISPLAY_FUNC()) 380 { 381 tgetent_ret = -1; 382 } 383 else 384 { 385 if (term_string_buffer == 0) |
386 term_string_buffer = (char *)xmalloc(2032); |
387 388 if (term_buffer == 0) |
389 term_buffer = (char *)xmalloc(4080); |
390 391 buffer = term_string_buffer; 392 393 tgetent_ret = tgetent (term_buffer, term); 394 } 395 396 if (tgetent_ret <= 0) 397 { --- 18 unchanged lines hidden (view full) --- 416 } 417 418 /* Everything below here is used by the redisplay code (tputs). */ 419 _rl_screenchars = _rl_screenwidth * _rl_screenheight; 420 _rl_term_cr = "\r"; 421 _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL; 422 _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL; 423 _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL; |
424 _rl_term_kh = _rl_term_kH = _rl_term_kI = (char *)NULL; 425 _rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL; |
426 _rl_term_mm = _rl_term_mo = (char *)NULL; |
427 _rl_term_ve = _rl_term_vs = (char *)NULL; |
428#if defined (HACK_TERMCAP_MOTION) 429 term_forward_char = (char *)NULL; 430#endif 431 _rl_terminal_can_insert = term_has_meta = 0; 432 433 /* Reasonable defaults for tgoto(). Readline currently only uses 434 tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we 435 change that later... */ --- 28 unchanged lines hidden (view full) --- 464 /* Check to see if this terminal has a meta key and clear the capability 465 variables if there is none. */ 466 term_has_meta = (tgetflag ("km") || tgetflag ("MT")); 467 if (!term_has_meta) 468 _rl_term_mm = _rl_term_mo = (char *)NULL; 469 470 /* Attempt to find and bind the arrow keys. Do not override already 471 bound keys in an overzealous attempt, however. */ |
472 |
473 bind_termcap_arrow_keys (emacs_standard_keymap); |
474 |
475#if defined (VI_MODE) |
476 bind_termcap_arrow_keys (vi_movement_keymap); 477 bind_termcap_arrow_keys (vi_insertion_keymap); 478#endif /* VI_MODE */ 479 480 return 0; 481} 482 483/* Bind the arrow key sequences from the termcap description in MAP. */ 484static void 485bind_termcap_arrow_keys (map) 486 Keymap map; 487{ 488 Keymap xkeymap; 489 490 xkeymap = _rl_keymap; 491 _rl_keymap = map; 492 |
493 _rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history); 494 _rl_bind_if_unbound (_rl_term_kd, rl_get_next_history); 495 _rl_bind_if_unbound (_rl_term_kr, rl_forward); 496 _rl_bind_if_unbound (_rl_term_kl, rl_backward); 497 498 _rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */ |
499 _rl_bind_if_unbound (_rl_term_at7, rl_end_of_line); /* End */ |
500 501 _rl_keymap = xkeymap; |
502} 503 504char * 505rl_get_termcap (cap) 506 const char *cap; 507{ 508 register int i; 509 --- 120 unchanged lines hidden (view full) --- 630{ 631#if !defined (__DJGPP__) 632 if (on && _rl_term_ks) 633 tputs (_rl_term_ks, 1, _rl_output_character_function); 634 else if (!on && _rl_term_ke) 635 tputs (_rl_term_ke, 1, _rl_output_character_function); 636#endif 637} |
638 639/* **************************************************************** */ 640/* */ 641/* Controlling the Cursor */ 642/* */ 643/* **************************************************************** */ 644 645/* Set the cursor appropriately depending on IM, which is one of the 646 insert modes (insert or overwrite). Insert mode gets the normal 647 cursor. Overwrite mode gets a very visible cursor. Only does 648 anything if we have both capabilities. */ 649void 650_rl_set_cursor (im, force) 651 int im, force; 652{ 653 if (_rl_term_ve && _rl_term_vs) 654 { 655 if (force || im != rl_insert_mode) 656 { 657 if (im == RL_IM_OVERWRITE) 658 tputs (_rl_term_vs, 1, _rl_output_character_function); 659 else 660 tputs (_rl_term_ve, 1, _rl_output_character_function); 661 } 662 } 663} |