1 /****************************************************************************
2 * Copyright (c) 1998-2011,2013 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 * and: Juergen Pfeifer 2009 *
34 ****************************************************************************/
39 ** The routines to handle option setting.
43 #include <curses.priv.h>
46 #define CUR SP_TERMTYPE
49 MODULE_ID("$Id: lib_options.c,v 1.74 2013/01/12 16:44:17 tom Exp $")
52 idlok(WINDOW *win, bool flag)
55 T((T_CALLED("idlok(%p,%d)"), (void *) win, flag));
58 SCREEN *sp = _nc_screen_of(win);
59 if (sp && IsTermInfo(sp)) {
61 win->_idlok = (flag && (NCURSES_SP_NAME(has_il) (NCURSES_SP_ARG)
62 || change_scroll_region));
70 idcok(WINDOW *win, bool flag)
72 T((T_CALLED("idcok(%p,%d)"), (void *) win, flag));
75 SCREEN *sp = _nc_screen_of(win);
76 sp->_nc_sp_idcok = win->_idcok = (flag && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG));
82 NCURSES_SP_NAME(halfdelay) (NCURSES_SP_DCLx int t)
84 T((T_CALLED("halfdelay(%p,%d)"), (void *) SP_PARM, t));
86 if (t < 1 || t > 255 || !IsValidTIScreen(SP_PARM))
89 NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
90 SP_PARM->_cbreak = t + 1;
98 return NCURSES_SP_NAME(halfdelay) (CURRENT_SCREEN, t);
103 nodelay(WINDOW *win, bool flag)
105 T((T_CALLED("nodelay(%p,%d)"), (void *) win, flag));
118 notimeout(WINDOW *win, bool f)
120 T((T_CALLED("notimeout(%p,%d)"), (void *) win, f));
130 wtimeout(WINDOW *win, int delay)
132 T((T_CALLED("wtimeout(%p,%d)"), (void *) win, delay));
141 keypad(WINDOW *win, bool flag)
143 T((T_CALLED("keypad(%p,%d)"), (void *) win, flag));
146 win->_use_keypad = flag;
147 returnCode(_nc_keypad(_nc_screen_of(win), flag));
153 meta(WINDOW *win GCC_UNUSED, bool flag)
156 SCREEN *sp = (win == 0) ? CURRENT_SCREEN : _nc_screen_of(win);
158 /* Ok, we stay relaxed and don't signal an error if win is NULL */
159 T((T_CALLED("meta(%p,%d)"), (void *) win, flag));
161 /* Ok, we stay relaxed and don't signal an error if win is NULL */
164 sp->_use_meta = flag;
165 #ifdef USE_TERM_DRIVER
166 if (IsTermInfo(sp)) {
168 NCURSES_PUTP2("meta_on", meta_on);
170 NCURSES_PUTP2("meta_off", meta_off);
175 NCURSES_PUTP2("meta_on", meta_on);
177 NCURSES_PUTP2("meta_off", meta_off);
185 /* curs_set() moved here to narrow the kernel interface */
188 NCURSES_SP_NAME(curs_set) (NCURSES_SP_DCLx int vis)
191 T((T_CALLED("curs_set(%p,%d)"), (void *) SP_PARM, vis));
193 if (SP_PARM != 0 && vis >= 0 && vis <= 2) {
194 int cursor = SP_PARM->_cursor;
195 bool bBuiltIn = !IsTermInfo(SP_PARM);
202 code = NCURSES_PUTP2_FLUSH("cursor_visible",
206 code = NCURSES_PUTP2_FLUSH("cursor_normal",
210 code = NCURSES_PUTP2_FLUSH("cursor_invisible",
217 code = (cursor == -1 ? 1 : cursor);
218 SP_PARM->_cursor = vis;
228 return (NCURSES_SP_NAME(curs_set) (CURRENT_SCREEN, vis));
233 NCURSES_SP_NAME(typeahead) (NCURSES_SP_DCLx int fd)
235 T((T_CALLED("typeahead(%p, %d)"), (void *) SP_PARM, fd));
236 if (IsValidTIScreen(SP_PARM)) {
237 SP_PARM->_checkfd = fd;
248 return NCURSES_SP_NAME(typeahead) (CURRENT_SCREEN, fd);
255 ** Return TRUE if the current terminal has the given key
259 #if NCURSES_EXT_FUNCS
261 has_key_internal(int keycode, TRIES * tp)
265 else if (tp->value == keycode)
268 return (has_key_internal(keycode, tp->child)
269 || has_key_internal(keycode, tp->sibling));
272 #ifdef USE_TERM_DRIVER
274 TINFO_HAS_KEY(SCREEN *sp, int keycode)
276 return IsValidTIScreen(sp) ?
277 has_key_internal(keycode, sp->_keytry) : 0;
281 NCURSES_SP_NAME(has_key) (NCURSES_SP_DCLx int keycode)
283 T((T_CALLED("has_key(%p,%d)"), (void *) SP_PARM, keycode));
284 returnCode(SP != 0 ? has_key_internal(keycode, SP_PARM->_keytry) : FALSE);
291 return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode);
295 #endif /* NCURSES_EXT_FUNCS */
298 NCURSES_SP_NAME(_nc_putp_flush) (NCURSES_SP_DCLx
299 const char *name, const char *value)
301 int rc = NCURSES_PUTP2(name, value);
308 #if 0 && NCURSES_SP_FUNCS
310 _nc_putp_flush(const char *name, const char *value)
312 return NCURSES_SP_NAME(_nc_putp_flush) (CURRENT_SCREEN, name, value);
316 /* Turn the keypad on/off
318 * Note: we flush the output because changing this mode causes some terminals
319 * to emit different escape sequences for cursor and keypad keys. If we don't
320 * flush, then the next wgetch may get the escape sequence that corresponds to
321 * the terminal state _before_ switching modes.
324 _nc_keypad(SCREEN *sp, int flag)
331 * We might have this situation in a multithreaded application that
332 * has wgetch() reading in more than one thread. putp() and below
333 * may use SP explicitly.
335 if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
338 /* cannot use use_screen(), since that is not in tinfo library */
339 _nc_lock_global(curses);
340 save_sp = CURRENT_SCREEN;
342 rc = _nc_keypad(sp, flag);
343 _nc_set_screen(save_sp);
344 _nc_unlock_global(curses);
348 #ifdef USE_TERM_DRIVER
349 rc = CallDriver_1(sp, kpad, flag);
351 sp->_keypad_on = flag;
354 (void) NCURSES_PUTP2_FLUSH("keypad_xmit", keypad_xmit);
355 } else if (!flag && keypad_local) {
356 (void) NCURSES_PUTP2_FLUSH("keypad_local", keypad_local);
359 if (flag && !sp->_tried) {
363 sp->_keypad_on = flag;