* input.c (rl_getc): Use getch to read console input on
[deliverable/binutils-gdb.git] / readline / terminal.c
CommitLineData
d60d9f65
SS
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
9 and/or modify it under the terms of the GNU General Public License
1b17e766 10 as published by the Free Software Foundation; either version 2, or
d60d9f65
SS
11 (at your option) any later version.
12
13 The GNU Readline Library is distributed in the hope that it will be
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,
1b17e766 21 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
d60d9f65
SS
22#define READLINE_LIBRARY
23
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
28#include <sys/types.h>
29#include "posixstat.h"
30#include <fcntl.h>
31#if defined (HAVE_SYS_FILE_H)
32# include <sys/file.h>
33#endif /* HAVE_SYS_FILE_H */
34
35#if defined (HAVE_UNISTD_H)
36# include <unistd.h>
37#endif /* HAVE_UNISTD_H */
38
39#if defined (HAVE_STDLIB_H)
40# include <stdlib.h>
41#else
42# include "ansi_stdlib.h"
43#endif /* HAVE_STDLIB_H */
44
45#if defined (HAVE_LOCALE_H)
46# include <locale.h>
47#endif
48
d60d9f65 49#include <stdio.h>
d60d9f65
SS
50
51/* System-specific feature definitions and include files. */
52#include "rldefs.h"
53
54#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ)
55# include <sys/ioctl.h>
56#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */
57
30083a32
EZ
58#ifdef __MSDOS__
59# include <pc.h>
60#endif
61
d60d9f65
SS
62#include "rltty.h"
63#include "tcap.h"
64
65/* Some standard library routines. */
66#include "readline.h"
67#include "history.h"
68
1b17e766
EZ
69#include "rlprivate.h"
70#include "rlshell.h"
9255ee31
EZ
71#include "xmalloc.h"
72
73#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay)
74#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc)
8f2eba6e 75
d60d9f65
SS
76/* **************************************************************** */
77/* */
78/* Terminal and Termcap */
79/* */
80/* **************************************************************** */
81
30083a32 82#ifndef __MSDOS__
d60d9f65
SS
83static char *term_buffer = (char *)NULL;
84static char *term_string_buffer = (char *)NULL;
85
d60d9f65
SS
86/* Non-zero means this terminal can't really do anything. */
87static int dumb_term;
30083a32
EZ
88#endif /* !__MSDOS__ */
89
90static int tcap_initialized;
d60d9f65
SS
91
92#if !defined (__linux__)
93# if defined (__EMX__) || defined (NEED_EXTERN_PC)
94extern
95# endif /* __EMX__ || NEED_EXTERN_PC */
96char PC, *BC, *UP;
97#endif /* __linux__ */
98
99/* Some strings to control terminal actions. These are output by tputs (). */
9255ee31
EZ
100char *_rl_term_clreol;
101char *_rl_term_clrpag;
102char *_rl_term_cr;
103char *_rl_term_backspace;
104char *_rl_term_goto;
105char *_rl_term_pc;
d60d9f65
SS
106
107/* Non-zero if we determine that the terminal can do character insertion. */
9255ee31 108int _rl_terminal_can_insert = 0;
d60d9f65
SS
109
110/* How to insert characters. */
9255ee31
EZ
111char *_rl_term_im;
112char *_rl_term_ei;
113char *_rl_term_ic;
114char *_rl_term_ip;
115char *_rl_term_IC;
d60d9f65
SS
116
117/* How to delete characters. */
9255ee31
EZ
118char *_rl_term_dc;
119char *_rl_term_DC;
d60d9f65
SS
120
121#if defined (HACK_TERMCAP_MOTION)
9255ee31 122char *_rl_term_forward_char;
d60d9f65
SS
123#endif /* HACK_TERMCAP_MOTION */
124
125/* How to go up a line. */
9255ee31 126char *_rl_term_up;
d60d9f65 127
9255ee31
EZ
128/* A visible bell; char if the terminal can be made to flash the screen. */
129static char *_rl_visible_bell;
d60d9f65
SS
130
131/* Non-zero means the terminal can auto-wrap lines. */
132int _rl_term_autowrap;
133
134/* Non-zero means that this terminal has a meta key. */
135static int term_has_meta;
136
137/* The sequences to write to turn on and off the meta key, if this
9255ee31
EZ
138 terminal has one. */
139static char *_rl_term_mm;
140static char *_rl_term_mo;
d60d9f65
SS
141
142/* The key sequences output by the arrow keys, if this terminal has any. */
9255ee31
EZ
143static char *_rl_term_ku;
144static char *_rl_term_kd;
145static char *_rl_term_kr;
146static char *_rl_term_kl;
d60d9f65
SS
147
148/* How to initialize and reset the arrow keys, if this terminal has any. */
9255ee31
EZ
149static char *_rl_term_ks;
150static char *_rl_term_ke;
d60d9f65
SS
151
152/* The key sequences sent by the Home and End keys, if any. */
9255ee31
EZ
153static char *_rl_term_kh;
154static char *_rl_term_kH;
155static char *_rl_term_at7; /* @7 */
156
157/* Insert key */
158static char *_rl_term_kI;
159
160/* Cursor control */
161static char *_rl_term_vs; /* very visible */
162static char *_rl_term_ve; /* normal */
163
164static void bind_termcap_arrow_keys PARAMS((Keymap));
d60d9f65
SS
165
166/* Variables that hold the screen dimensions, used by the display code. */
9255ee31 167int _rl_screenwidth, _rl_screenheight, _rl_screenchars;
d60d9f65
SS
168
169/* Non-zero means the user wants to enable the keypad. */
170int _rl_enable_keypad;
171
172/* Non-zero means the user wants to enable a meta key. */
173int _rl_enable_meta = 1;
174
1b17e766
EZ
175#if defined (__EMX__)
176static void
177_emx_get_screensize (swp, shp)
178 int *swp, *shp;
179{
180 int sz[2];
181
182 _scrsize (sz);
183
184 if (swp)
185 *swp = sz[0];
186 if (shp)
187 *shp = sz[1];
188}
189#endif
190
d60d9f65
SS
191/* Get readline's idea of the screen size. TTY is a file descriptor open
192 to the terminal. If IGNORE_ENV is true, we do not pay attention to the
193 values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being
194 non-null serve to check whether or not we have initialized termcap. */
195void
196_rl_get_screen_size (tty, ignore_env)
197 int tty, ignore_env;
198{
199 char *ss;
200#if defined (TIOCGWINSZ)
201 struct winsize window_size;
202#endif /* TIOCGWINSZ */
d60d9f65
SS
203
204#if defined (TIOCGWINSZ)
205 if (ioctl (tty, TIOCGWINSZ, &window_size) == 0)
206 {
9255ee31
EZ
207 _rl_screenwidth = (int) window_size.ws_col;
208 _rl_screenheight = (int) window_size.ws_row;
d60d9f65
SS
209 }
210#endif /* TIOCGWINSZ */
211
212#if defined (__EMX__)
9255ee31 213 _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
d60d9f65
SS
214#endif
215
216 /* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV
217 is unset. */
9255ee31 218 if (_rl_screenwidth <= 0)
d60d9f65 219 {
9255ee31
EZ
220 if (ignore_env == 0 && (ss = sh_get_env_value ("COLUMNS")))
221 _rl_screenwidth = atoi (ss);
d60d9f65 222
b0f0a30e
EZ
223#if defined (__DJGPP__)
224 if (_rl_screenwidth <= 0)
225 _rl_screenwidth = ScreenCols ();
226#else
9255ee31
EZ
227 if (_rl_screenwidth <= 0 && term_string_buffer)
228 _rl_screenwidth = tgetnum ("co");
771578d1 229#endif
d60d9f65
SS
230 }
231
232 /* Environment variable LINES overrides setting of "li" if IGNORE_ENV
233 is unset. */
9255ee31 234 if (_rl_screenheight <= 0)
d60d9f65 235 {
9255ee31
EZ
236 if (ignore_env == 0 && (ss = sh_get_env_value ("LINES")))
237 _rl_screenheight = atoi (ss);
d60d9f65 238
b0f0a30e
EZ
239#if defined (__DJGPP__)
240 if (_rl_screenheight <= 0)
241 _rl_screenheight = ScreenRows ();
242#else
9255ee31
EZ
243 if (_rl_screenheight <= 0 && term_string_buffer)
244 _rl_screenheight = tgetnum ("li");
771578d1 245#endif
d60d9f65
SS
246 }
247
248 /* If all else fails, default to 80x24 terminal. */
9255ee31
EZ
249 if (_rl_screenwidth <= 1)
250 _rl_screenwidth = 80;
d60d9f65 251
9255ee31
EZ
252 if (_rl_screenheight <= 0)
253 _rl_screenheight = 24;
d60d9f65
SS
254
255 /* If we're being compiled as part of bash, set the environment
256 variables $LINES and $COLUMNS to new values. Otherwise, just
257 do a pair of putenv () or setenv () calls. */
9255ee31 258 sh_set_lines_and_columns (_rl_screenheight, _rl_screenwidth);
d60d9f65 259
1b17e766 260 if (_rl_term_autowrap == 0)
9255ee31 261 _rl_screenwidth--;
d60d9f65 262
9255ee31 263 _rl_screenchars = _rl_screenwidth * _rl_screenheight;
d60d9f65
SS
264}
265
266void
267_rl_set_screen_size (rows, cols)
268 int rows, cols;
269{
9255ee31
EZ
270 if (rows == 0 || cols == 0)
271 return;
272
273 _rl_screenheight = rows;
274 _rl_screenwidth = cols;
d60d9f65
SS
275
276 if (_rl_term_autowrap == 0)
9255ee31 277 _rl_screenwidth--;
d60d9f65 278
9255ee31 279 _rl_screenchars = _rl_screenwidth * _rl_screenheight;
d60d9f65
SS
280}
281
9255ee31
EZ
282void
283rl_set_screen_size (rows, cols)
284 int rows, cols;
285{
286 _rl_set_screen_size (rows, cols);
287}
288
289void
290rl_get_screen_size (rows, cols)
291 int *rows, *cols;
292{
293 if (rows)
294 *rows = _rl_screenheight;
295 if (cols)
296 *cols = _rl_screenwidth;
297}
298
c862e87b
JM
299void
300rl_resize_terminal ()
301{
302 if (readline_echoing_p)
303 {
304 _rl_get_screen_size (fileno (rl_instream), 1);
9255ee31
EZ
305 if (CUSTOM_REDISPLAY_FUNC ())
306 rl_forced_update_display ();
307 else
308 _rl_redisplay_after_sigwinch ();
c862e87b
JM
309 }
310}
311
d60d9f65 312struct _tc_string {
9255ee31 313 const char *tc_var;
d60d9f65
SS
314 char **tc_value;
315};
316
317/* This should be kept sorted, just in case we decide to change the
318 search algorithm to something smarter. */
319static struct _tc_string tc_strings[] =
320{
9255ee31
EZ
321 { "@7", &_rl_term_at7 },
322 { "DC", &_rl_term_DC },
323 { "IC", &_rl_term_IC },
324 { "ce", &_rl_term_clreol },
325 { "cl", &_rl_term_clrpag },
326 { "cr", &_rl_term_cr },
327 { "dc", &_rl_term_dc },
328 { "ei", &_rl_term_ei },
329 { "ic", &_rl_term_ic },
330 { "im", &_rl_term_im },
331 { "kH", &_rl_term_kH }, /* home down ?? */
332 { "kI", &_rl_term_kI }, /* insert */
333 { "kd", &_rl_term_kd },
334 { "ke", &_rl_term_ke }, /* end keypad mode */
335 { "kh", &_rl_term_kh }, /* home */
336 { "kl", &_rl_term_kl },
337 { "kr", &_rl_term_kr },
338 { "ks", &_rl_term_ks }, /* start keypad mode */
339 { "ku", &_rl_term_ku },
340 { "le", &_rl_term_backspace },
341 { "mm", &_rl_term_mm },
342 { "mo", &_rl_term_mo },
d60d9f65 343#if defined (HACK_TERMCAP_MOTION)
9255ee31 344 { "nd", &_rl_term_forward_char },
d60d9f65 345#endif
9255ee31
EZ
346 { "pc", &_rl_term_pc },
347 { "up", &_rl_term_up },
348 { "vb", &_rl_visible_bell },
349 { "vs", &_rl_term_vs },
350 { "ve", &_rl_term_ve },
d60d9f65
SS
351};
352
353#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string))
354
355/* Read the desired terminal capability strings into BP. The capabilities
356 are described in the TC_STRINGS table. */
357static void
358get_term_capabilities (bp)
359 char **bp;
360{
1b17e766 361#if !defined (__DJGPP__) /* XXX - doesn't DJGPP have a termcap library? */
d60d9f65
SS
362 register int i;
363
364 for (i = 0; i < NUM_TC_STRINGS; i++)
9255ee31
EZ
365# ifdef __LCC__
366 *(tc_strings[i].tc_value) = tgetstr ((char *)tc_strings[i].tc_var, bp);
367# else
d60d9f65 368 *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp);
9255ee31 369# endif
771578d1 370#endif
d60d9f65
SS
371 tcap_initialized = 1;
372}
373
374int
375_rl_init_terminal_io (terminal_name)
9255ee31 376 const char *terminal_name;
d60d9f65 377{
9255ee31
EZ
378 const char *term;
379 char *buffer;
1b17e766 380 int tty, tgetent_ret;
d60d9f65 381
9255ee31
EZ
382 term = terminal_name ? terminal_name : sh_get_env_value ("TERM");
383 _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL;
1b17e766 384 tty = rl_instream ? fileno (rl_instream) : 0;
9255ee31 385 _rl_screenwidth = _rl_screenheight = 0;
d60d9f65 386
1b17e766
EZ
387 if (term == 0)
388 term = "dumb";
d60d9f65 389
30083a32 390#ifdef __MSDOS__
b0f0a30e
EZ
391 _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
392 _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
393 _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
394 _rl_term_mm = _rl_term_mo = (char *)NULL;
395 _rl_terminal_can_insert = term_has_meta = _rl_term_autowrap = 0;
396 _rl_term_cr = "\r";
397 _rl_term_clreol = _rl_term_clrpag = _rl_term_backspace = (char *)NULL;
398 _rl_term_goto = _rl_term_pc = _rl_term_ip = (char *)NULL;
399 _rl_term_ks = _rl_term_ke =_rl_term_vs = _rl_term_ve = (char *)NULL;
400 _rl_term_kh = _rl_term_kH = _rl_term_at7 = _rl_term_kI = (char *)NULL;
401#if defined(HACK_TERMCAP_MOTION)
402 _rl_term_forward_char = (char *)NULL;
403#endif
30083a32
EZ
404
405 _rl_get_screen_size (tty, 0);
406#else /* !__MSDOS__ */
1b17e766
EZ
407 /* I've separated this out for later work on not calling tgetent at all
408 if the calling application has supplied a custom redisplay function,
409 (and possibly if the application has supplied a custom input function). */
410 if (CUSTOM_REDISPLAY_FUNC())
411 {
412 tgetent_ret = -1;
413 }
414 else
415 {
416 if (term_string_buffer == 0)
9255ee31 417 term_string_buffer = (char *)xmalloc(2032);
d60d9f65 418
1b17e766 419 if (term_buffer == 0)
9255ee31 420 term_buffer = (char *)xmalloc(4080);
d60d9f65 421
1b17e766 422 buffer = term_string_buffer;
d60d9f65 423
1b17e766
EZ
424 tgetent_ret = tgetent (term_buffer, term);
425 }
d60d9f65 426
1b17e766 427 if (tgetent_ret <= 0)
d60d9f65 428 {
1b17e766
EZ
429 FREE (term_string_buffer);
430 FREE (term_buffer);
431 buffer = term_buffer = term_string_buffer = (char *)NULL;
432
1b17e766
EZ
433 _rl_term_autowrap = 0; /* used by _rl_get_screen_size */
434
435#if defined (__EMX__)
9255ee31
EZ
436 _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
437 _rl_screenwidth--;
1b17e766
EZ
438#else /* !__EMX__ */
439 _rl_get_screen_size (tty, 0);
440#endif /* !__EMX__ */
441
442 /* Defaults. */
9255ee31 443 if (_rl_screenwidth <= 0 || _rl_screenheight <= 0)
1b17e766 444 {
9255ee31
EZ
445 _rl_screenwidth = 79;
446 _rl_screenheight = 24;
1b17e766
EZ
447 }
448
449 /* Everything below here is used by the redisplay code (tputs). */
9255ee31
EZ
450 _rl_screenchars = _rl_screenwidth * _rl_screenheight;
451 _rl_term_cr = "\r";
452 _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
453 _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
454 _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
455 _rl_term_kh = _rl_term_kH = _rl_term_kI = (char *)NULL;
456 _rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL;
457 _rl_term_mm = _rl_term_mo = (char *)NULL;
458 _rl_term_ve = _rl_term_vs = (char *)NULL;
d60d9f65
SS
459#if defined (HACK_TERMCAP_MOTION)
460 term_forward_char = (char *)NULL;
461#endif
9255ee31 462 _rl_terminal_can_insert = term_has_meta = 0;
1b17e766
EZ
463
464 /* Reasonable defaults for tgoto(). Readline currently only uses
9255ee31 465 tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we
1b17e766
EZ
466 change that later... */
467 PC = '\0';
9255ee31
EZ
468 BC = _rl_term_backspace = "\b";
469 UP = _rl_term_up;
1b17e766 470
d60d9f65
SS
471 return 0;
472 }
473
474 get_term_capabilities (&buffer);
475
476 /* Set up the variables that the termcap library expects the application
477 to provide. */
9255ee31
EZ
478 PC = _rl_term_pc ? *_rl_term_pc : 0;
479 BC = _rl_term_backspace;
480 UP = _rl_term_up;
d60d9f65 481
9255ee31
EZ
482 if (!_rl_term_cr)
483 _rl_term_cr = "\r";
d60d9f65 484
d60d9f65
SS
485 _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn");
486
487 _rl_get_screen_size (tty, 0);
488
489 /* "An application program can assume that the terminal can do
490 character insertion if *any one of* the capabilities `IC',
491 `im', `ic' or `ip' is provided." But we can't do anything if
492 only `ip' is provided, so... */
9255ee31 493 _rl_terminal_can_insert = (_rl_term_IC || _rl_term_im || _rl_term_ic);
d60d9f65
SS
494
495 /* Check to see if this terminal has a meta key and clear the capability
496 variables if there is none. */
497 term_has_meta = (tgetflag ("km") || tgetflag ("MT"));
498 if (!term_has_meta)
9255ee31 499 _rl_term_mm = _rl_term_mo = (char *)NULL;
d60d9f65 500
30083a32
EZ
501#endif /* !__MSDOS__ */
502
d60d9f65
SS
503 /* Attempt to find and bind the arrow keys. Do not override already
504 bound keys in an overzealous attempt, however. */
d60d9f65 505
9255ee31 506 bind_termcap_arrow_keys (emacs_standard_keymap);
d60d9f65
SS
507
508#if defined (VI_MODE)
9255ee31
EZ
509 bind_termcap_arrow_keys (vi_movement_keymap);
510 bind_termcap_arrow_keys (vi_insertion_keymap);
d60d9f65
SS
511#endif /* VI_MODE */
512
d60d9f65
SS
513 return 0;
514}
515
9255ee31
EZ
516/* Bind the arrow key sequences from the termcap description in MAP. */
517static void
518bind_termcap_arrow_keys (map)
519 Keymap map;
520{
521 Keymap xkeymap;
522
523 xkeymap = _rl_keymap;
524 _rl_keymap = map;
525
526 _rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history);
527 _rl_bind_if_unbound (_rl_term_kd, rl_get_next_history);
528 _rl_bind_if_unbound (_rl_term_kr, rl_forward);
529 _rl_bind_if_unbound (_rl_term_kl, rl_backward);
530
531 _rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */
532 _rl_bind_if_unbound (_rl_term_at7, rl_end_of_line); /* End */
533
534 _rl_keymap = xkeymap;
535}
536
d60d9f65
SS
537char *
538rl_get_termcap (cap)
9255ee31 539 const char *cap;
d60d9f65
SS
540{
541 register int i;
542
543 if (tcap_initialized == 0)
544 return ((char *)NULL);
545 for (i = 0; i < NUM_TC_STRINGS; i++)
546 {
547 if (tc_strings[i].tc_var[0] == cap[0] && strcmp (tc_strings[i].tc_var, cap) == 0)
548 return *(tc_strings[i].tc_value);
549 }
550 return ((char *)NULL);
551}
552
553/* Re-initialize the terminal considering that the TERM/TERMCAP variable
554 has changed. */
555int
556rl_reset_terminal (terminal_name)
9255ee31 557 const char *terminal_name;
d60d9f65
SS
558{
559 _rl_init_terminal_io (terminal_name);
560 return 0;
561}
562
563/* A function for the use of tputs () */
564#ifdef _MINIX
565void
566_rl_output_character_function (c)
567 int c;
568{
569 putc (c, _rl_out_stream);
570}
571#else /* !_MINIX */
572int
573_rl_output_character_function (c)
574 int c;
575{
576 return putc (c, _rl_out_stream);
577}
578#endif /* !_MINIX */
1b17e766 579
d60d9f65
SS
580/* Write COUNT characters from STRING to the output stream. */
581void
582_rl_output_some_chars (string, count)
9255ee31 583 const char *string;
d60d9f65
SS
584 int count;
585{
586 fwrite (string, 1, count, _rl_out_stream);
587}
588
589/* Move the cursor back. */
590int
591_rl_backspace (count)
592 int count;
593{
594 register int i;
595
30083a32 596#ifndef __MSDOS__
9255ee31 597 if (_rl_term_backspace)
d60d9f65 598 for (i = 0; i < count; i++)
9255ee31 599 tputs (_rl_term_backspace, 1, _rl_output_character_function);
d60d9f65 600 else
30083a32 601#endif
d60d9f65
SS
602 for (i = 0; i < count; i++)
603 putc ('\b', _rl_out_stream);
604 return 0;
605}
606
607/* Move to the start of the next line. */
608int
9255ee31 609rl_crlf ()
d60d9f65
SS
610{
611#if defined (NEW_TTY_DRIVER)
9255ee31
EZ
612 if (_rl_term_cr)
613 tputs (_rl_term_cr, 1, _rl_output_character_function);
d60d9f65
SS
614#endif /* NEW_TTY_DRIVER */
615 putc ('\n', _rl_out_stream);
616 return 0;
617}
618
619/* Ring the terminal bell. */
620int
9255ee31 621rl_ding ()
d60d9f65
SS
622{
623 if (readline_echoing_p)
624 {
d60d9f65
SS
625 switch (_rl_bell_preference)
626 {
627 case NO_BELL:
628 default:
629 break;
630 case VISIBLE_BELL:
30083a32
EZ
631#ifdef __MSDOS__
632 ScreenVisualBell ();
633 break;
634#else
9255ee31 635 if (_rl_visible_bell)
d60d9f65 636 {
9255ee31 637 tputs (_rl_visible_bell, 1, _rl_output_character_function);
d60d9f65
SS
638 break;
639 }
30083a32 640#endif
d60d9f65
SS
641 /* FALLTHROUGH */
642 case AUDIBLE_BELL:
643 fprintf (stderr, "\007");
644 fflush (stderr);
645 break;
646 }
d60d9f65
SS
647 return (0);
648 }
649 return (-1);
650}
651
652/* **************************************************************** */
653/* */
654/* Controlling the Meta Key and Keypad */
655/* */
656/* **************************************************************** */
657
658void
659_rl_enable_meta_key ()
660{
1b17e766 661#if !defined (__DJGPP__)
9255ee31
EZ
662 if (term_has_meta && _rl_term_mm)
663 tputs (_rl_term_mm, 1, _rl_output_character_function);
771578d1 664#endif
d60d9f65
SS
665}
666
667void
668_rl_control_keypad (on)
669 int on;
670{
1b17e766 671#if !defined (__DJGPP__)
9255ee31
EZ
672 if (on && _rl_term_ks)
673 tputs (_rl_term_ks, 1, _rl_output_character_function);
674 else if (!on && _rl_term_ke)
675 tputs (_rl_term_ke, 1, _rl_output_character_function);
771578d1 676#endif
d60d9f65 677}
9255ee31
EZ
678
679/* **************************************************************** */
680/* */
681/* Controlling the Cursor */
682/* */
683/* **************************************************************** */
684
685/* Set the cursor appropriately depending on IM, which is one of the
686 insert modes (insert or overwrite). Insert mode gets the normal
687 cursor. Overwrite mode gets a very visible cursor. Only does
688 anything if we have both capabilities. */
689void
690_rl_set_cursor (im, force)
691 int im, force;
692{
b0f0a30e 693#ifndef __MSDOS__
9255ee31
EZ
694 if (_rl_term_ve && _rl_term_vs)
695 {
696 if (force || im != rl_insert_mode)
697 {
698 if (im == RL_IM_OVERWRITE)
699 tputs (_rl_term_vs, 1, _rl_output_character_function);
700 else
701 tputs (_rl_term_ve, 1, _rl_output_character_function);
702 }
703 }
b0f0a30e 704#endif
9255ee31 705}
This page took 0.295465 seconds and 4 git commands to generate.