1/* $FreeBSD: head/contrib/libreadline/terminal.c 165675 2006-12-31 09:22:31Z ache $ */
2/* terminal.c -- controlling the terminal with termcap. */
3
4/* Copyright (C) 1996-2006 Free Software Foundation, Inc.
5
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
8
9 The GNU Readline Library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2, or
12 (at your option) any later version.
--- 49 unchanged lines hidden (view full) ---
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#if defined (__MINGW32__)
71# include <windows.h>
72# include <wincon.h>
73
74static void _win_get_screensize PARAMS((int *, int *));
75#endif
76
77#if defined (__EMX__)
78static void _emx_get_screensize PARAMS((int *, int *));
79#endif
80
81#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay)
82#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc)
83
84/* If the calling application sets this to a non-zero value, readline will
85 use the $LINES and $COLUMNS environment variables to set its idea of the
86 window size before interrogating the kernel. */
87int rl_prefer_env_winsize = 0;
88
89/* **************************************************************** */
90/* */
91/* Terminal and Termcap */
92/* */
93/* **************************************************************** */
94
95static char *term_buffer = (char *)NULL;
--- 25 unchanged lines hidden (view full) ---
121char *_rl_term_ic;
122char *_rl_term_ip;
123char *_rl_term_IC;
124
125/* How to delete characters. */
126char *_rl_term_dc;
127char *_rl_term_DC;
128
129char *_rl_term_forward_char;
130
131/* How to go up a line. */
132char *_rl_term_up;
133
134/* A visible bell; char if the terminal can be made to flash the screen. */
135static char *_rl_visible_bell;
136
137/* Non-zero means the terminal can auto-wrap lines. */
--- 54 unchanged lines hidden (view full) ---
192
193 if (swp)
194 *swp = sz[0];
195 if (shp)
196 *shp = sz[1];
197}
198#endif
199
200#if defined (__MINGW32__)
201static void
202_win_get_screensize (swp, shp)
203 int *swp, *shp;
204{
205 HANDLE hConOut;
206 CONSOLE_SCREEN_BUFFER_INFO scr;
207
208 hConOut = GetStdHandle (STD_OUTPUT_HANDLE);
209 if (hConOut != INVALID_HANDLE_VALUE)
210 {
211 if (GetConsoleScreenBufferInfo (hConOut, &scr))
212 {
213 *swp = scr.dwSize.X;
214 *shp = scr.srWindow.Bottom - scr.srWindow.Top + 1;
215 }
216 }
217}
218#endif
219
220/* Get readline's idea of the screen size. TTY is a file descriptor open
221 to the terminal. If IGNORE_ENV is true, we do not pay attention to the
222 values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being
223 non-null serve to check whether or not we have initialized termcap. */
224void
225_rl_get_screen_size (tty, ignore_env)
226 int tty, ignore_env;
227{
--- 8 unchanged lines hidden (view full) ---
236 if (ioctl (tty, TIOCGWINSZ, &window_size) == 0)
237 {
238 wc = (int) window_size.ws_col;
239 wr = (int) window_size.ws_row;
240 }
241#endif /* TIOCGWINSZ */
242
243#if defined (__EMX__)
244 _emx_get_screensize (&wc, &wr);
245#elif defined (__MINGW32__)
246 _win_get_screensize (&wc, &wr);
247#endif
248
249 if (ignore_env || rl_prefer_env_winsize == 0)
250 {
251 _rl_screenwidth = wc;
252 _rl_screenheight = wr;
253 }
254 else
--- 133 unchanged lines hidden (view full) ---
388 { "kh", &_rl_term_kh }, /* home */
389 { "kl", &_rl_term_kl },
390 { "kr", &_rl_term_kr },
391 { "ks", &_rl_term_ks }, /* start keypad mode */
392 { "ku", &_rl_term_ku },
393 { "le", &_rl_term_backspace },
394 { "mm", &_rl_term_mm },
395 { "mo", &_rl_term_mo },
396 { "nd", &_rl_term_forward_char },
397 { "pc", &_rl_term_pc },
398 { "up", &_rl_term_up },
399 { "vb", &_rl_visible_bell },
400 { "vs", &_rl_term_vs },
401 { "ve", &_rl_term_ve },
402};
403
404#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string))
--- 80 unchanged lines hidden (view full) ---
485 _rl_term_cr = "\r";
486 _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
487 _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
488 _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
489 _rl_term_kh = _rl_term_kH = _rl_term_kI = _rl_term_kD = (char *)NULL;
490 _rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL;
491 _rl_term_mm = _rl_term_mo = (char *)NULL;
492 _rl_term_ve = _rl_term_vs = (char *)NULL;
493 _rl_term_forward_char = (char *)NULL;
494 _rl_terminal_can_insert = term_has_meta = 0;
495
496 /* Reasonable defaults for tgoto(). Readline currently only uses
497 tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we
498 change that later... */
499 PC = '\0';
500 BC = _rl_term_backspace = "\b";
501 UP = _rl_term_up;
--- 231 unchanged lines hidden ---
2/* terminal.c -- controlling the terminal with termcap. */
3
4/* Copyright (C) 1996-2006 Free Software Foundation, Inc.
5
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
8
9 The GNU Readline Library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2, or
12 (at your option) any later version.
--- 49 unchanged lines hidden (view full) ---
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#if defined (__MINGW32__)
71# include <windows.h>
72# include <wincon.h>
73
74static void _win_get_screensize PARAMS((int *, int *));
75#endif
76
77#if defined (__EMX__)
78static void _emx_get_screensize PARAMS((int *, int *));
79#endif
80
81#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay)
82#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc)
83
84/* If the calling application sets this to a non-zero value, readline will
85 use the $LINES and $COLUMNS environment variables to set its idea of the
86 window size before interrogating the kernel. */
87int rl_prefer_env_winsize = 0;
88
89/* **************************************************************** */
90/* */
91/* Terminal and Termcap */
92/* */
93/* **************************************************************** */
94
95static char *term_buffer = (char *)NULL;
--- 25 unchanged lines hidden (view full) ---
121char *_rl_term_ic;
122char *_rl_term_ip;
123char *_rl_term_IC;
124
125/* How to delete characters. */
126char *_rl_term_dc;
127char *_rl_term_DC;
128
129char *_rl_term_forward_char;
130
131/* How to go up a line. */
132char *_rl_term_up;
133
134/* A visible bell; char if the terminal can be made to flash the screen. */
135static char *_rl_visible_bell;
136
137/* Non-zero means the terminal can auto-wrap lines. */
--- 54 unchanged lines hidden (view full) ---
192
193 if (swp)
194 *swp = sz[0];
195 if (shp)
196 *shp = sz[1];
197}
198#endif
199
200#if defined (__MINGW32__)
201static void
202_win_get_screensize (swp, shp)
203 int *swp, *shp;
204{
205 HANDLE hConOut;
206 CONSOLE_SCREEN_BUFFER_INFO scr;
207
208 hConOut = GetStdHandle (STD_OUTPUT_HANDLE);
209 if (hConOut != INVALID_HANDLE_VALUE)
210 {
211 if (GetConsoleScreenBufferInfo (hConOut, &scr))
212 {
213 *swp = scr.dwSize.X;
214 *shp = scr.srWindow.Bottom - scr.srWindow.Top + 1;
215 }
216 }
217}
218#endif
219
220/* Get readline's idea of the screen size. TTY is a file descriptor open
221 to the terminal. If IGNORE_ENV is true, we do not pay attention to the
222 values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being
223 non-null serve to check whether or not we have initialized termcap. */
224void
225_rl_get_screen_size (tty, ignore_env)
226 int tty, ignore_env;
227{
--- 8 unchanged lines hidden (view full) ---
236 if (ioctl (tty, TIOCGWINSZ, &window_size) == 0)
237 {
238 wc = (int) window_size.ws_col;
239 wr = (int) window_size.ws_row;
240 }
241#endif /* TIOCGWINSZ */
242
243#if defined (__EMX__)
244 _emx_get_screensize (&wc, &wr);
245#elif defined (__MINGW32__)
246 _win_get_screensize (&wc, &wr);
247#endif
248
249 if (ignore_env || rl_prefer_env_winsize == 0)
250 {
251 _rl_screenwidth = wc;
252 _rl_screenheight = wr;
253 }
254 else
--- 133 unchanged lines hidden (view full) ---
388 { "kh", &_rl_term_kh }, /* home */
389 { "kl", &_rl_term_kl },
390 { "kr", &_rl_term_kr },
391 { "ks", &_rl_term_ks }, /* start keypad mode */
392 { "ku", &_rl_term_ku },
393 { "le", &_rl_term_backspace },
394 { "mm", &_rl_term_mm },
395 { "mo", &_rl_term_mo },
396 { "nd", &_rl_term_forward_char },
397 { "pc", &_rl_term_pc },
398 { "up", &_rl_term_up },
399 { "vb", &_rl_visible_bell },
400 { "vs", &_rl_term_vs },
401 { "ve", &_rl_term_ve },
402};
403
404#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string))
--- 80 unchanged lines hidden (view full) ---
485 _rl_term_cr = "\r";
486 _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
487 _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
488 _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
489 _rl_term_kh = _rl_term_kH = _rl_term_kI = _rl_term_kD = (char *)NULL;
490 _rl_term_ks = _rl_term_ke = _rl_term_at7 = (char *)NULL;
491 _rl_term_mm = _rl_term_mo = (char *)NULL;
492 _rl_term_ve = _rl_term_vs = (char *)NULL;
493 _rl_term_forward_char = (char *)NULL;
494 _rl_terminal_can_insert = term_has_meta = 0;
495
496 /* Reasonable defaults for tgoto(). Readline currently only uses
497 tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we
498 change that later... */
499 PC = '\0';
500 BC = _rl_term_backspace = "\b";
501 UP = _rl_term_up;
--- 231 unchanged lines hidden ---