1 /****************************************************************************
2 * Copyright 2020-2021,2023 Thomas E. Dickey *
3 * Copyright 1998-2014,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 * and: Juergen Pfeifer 2009 *
35 ****************************************************************************/
40 ** The routines to handle option setting.
44 #include <curses.priv.h>
47 #define CUR SP_TERMTYPE
50 MODULE_ID("$Id: lib_options.c,v 1.83 2023/04/29 18:56:12 tom Exp $")
53 idlok(WINDOW *win, bool flag)
56 T((T_CALLED("idlok(%p,%d)"), (void *) win, flag));
59 SCREEN *sp = _nc_screen_of(win);
61 #ifdef USE_TERM_DRIVER
66 win->_idlok = (flag && (NCURSES_SP_NAME(has_il) (NCURSES_SP_ARG)
67 || change_scroll_region));
75 idcok(WINDOW *win, bool flag)
77 T((T_CALLED("idcok(%p,%d)"), (void *) win, flag));
80 SCREEN *sp = _nc_screen_of(win);
81 sp->_nc_sp_idcok = win->_idcok = (flag && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG));
87 NCURSES_SP_NAME(halfdelay) (NCURSES_SP_DCLx int t)
89 T((T_CALLED("halfdelay(%p,%d)"), (void *) SP_PARM, t));
91 if (t < 1 || t > 255 || !SP_PARM || !IsValidTIScreen(SP_PARM))
94 NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
95 IsCbreak(SP_PARM) = t + 1;
103 return NCURSES_SP_NAME(halfdelay) (CURRENT_SCREEN, t);
108 nodelay(WINDOW *win, bool flag)
110 T((T_CALLED("nodelay(%p,%d)"), (void *) win, flag));
123 notimeout(WINDOW *win, bool f)
125 T((T_CALLED("notimeout(%p,%d)"), (void *) win, f));
135 wtimeout(WINDOW *win, int delay)
137 T((T_CALLED("wtimeout(%p,%d)"), (void *) win, delay));
146 keypad(WINDOW *win, bool flag)
148 T((T_CALLED("keypad(%p,%d)"), (void *) win, flag));
151 win->_use_keypad = flag;
152 returnCode(_nc_keypad(_nc_screen_of(win), flag));
158 meta(WINDOW *win GCC_UNUSED, bool flag)
161 SCREEN *sp = (win == 0) ? CURRENT_SCREEN : _nc_screen_of(win);
163 /* Ok, we stay relaxed and don't signal an error if win is NULL */
164 T((T_CALLED("meta(%p,%d)"), (void *) win, flag));
166 /* Ok, we stay relaxed and don't signal an error if win is NULL */
169 sp->_use_meta = flag;
170 #ifdef USE_TERM_DRIVER
171 if (IsTermInfo(sp)) {
173 NCURSES_PUTP2("meta_on", meta_on);
175 NCURSES_PUTP2("meta_off", meta_off);
180 NCURSES_PUTP2("meta_on", meta_on);
182 NCURSES_PUTP2("meta_off", meta_off);
190 /* curs_set() moved here to narrow the kernel interface */
193 NCURSES_SP_NAME(curs_set) (NCURSES_SP_DCLx int vis)
196 T((T_CALLED("curs_set(%p,%d)"), (void *) SP_PARM, vis));
198 if (SP_PARM != 0 && vis >= 0 && vis <= 2) {
199 int cursor = SP_PARM->_cursor;
203 #ifdef USE_TERM_DRIVER
204 code = CallDriver_1(SP_PARM, td_cursorSet, vis);
206 if (IsValidTIScreen(SP_PARM)) {
209 code = NCURSES_PUTP2_FLUSH("cursor_visible",
213 code = NCURSES_PUTP2_FLUSH("cursor_normal",
217 code = NCURSES_PUTP2_FLUSH("cursor_invisible",
226 code = (cursor == -1 ? 1 : cursor);
227 SP_PARM->_cursor = vis;
237 return (NCURSES_SP_NAME(curs_set) (CURRENT_SCREEN, vis));
242 NCURSES_SP_NAME(typeahead) (NCURSES_SP_DCLx int fd)
244 T((T_CALLED("typeahead(%p, %d)"), (void *) SP_PARM, fd));
245 if (SP_PARM && IsValidTIScreen(SP_PARM)) {
246 SP_PARM->_checkfd = fd;
257 return NCURSES_SP_NAME(typeahead) (CURRENT_SCREEN, fd);
264 ** Return TRUE if the current terminal has the given key
268 #if NCURSES_EXT_FUNCS
270 has_key_internal(int keycode, TRIES * tp)
274 else if (tp->value == keycode)
277 return (has_key_internal(keycode, tp->child)
278 || has_key_internal(keycode, tp->sibling));
281 #ifdef USE_TERM_DRIVER
283 TINFO_HAS_KEY(SCREEN *sp, int keycode)
285 return IsValidTIScreen(sp) ?
286 has_key_internal(keycode, sp->_keytry) : 0;
290 NCURSES_SP_NAME(has_key) (NCURSES_SP_DCLx int keycode)
292 T((T_CALLED("has_key(%p,%d)"), (void *) SP_PARM, keycode));
293 returnCode(SP != 0 ? has_key_internal(keycode, SP_PARM->_keytry) : FALSE);
300 return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode);
304 #endif /* NCURSES_EXT_FUNCS */
307 NCURSES_SP_NAME(_nc_putp_flush) (NCURSES_SP_DCLx
308 const char *name, const char *value)
310 int rc = NCURSES_PUTP2(name, value);
317 #if 0 && NCURSES_SP_FUNCS
319 _nc_putp_flush(const char *name, const char *value)
321 return NCURSES_SP_NAME(_nc_putp_flush) (CURRENT_SCREEN, name, value);
325 /* Turn the keypad on/off
327 * Note: we flush the output because changing this mode causes some terminals
328 * to emit different escape sequences for cursor and keypad keys. If we don't
329 * flush, then the next wgetch may get the escape sequence that corresponds to
330 * the terminal state _before_ switching modes.
333 _nc_keypad(SCREEN *sp, int flag)
340 * We might have this situation in a multithreaded application that
341 * has wgetch() reading in more than one thread. putp() and below
342 * may use SP explicitly.
344 if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
347 /* cannot use use_screen(), since that is not in tinfo library */
348 _nc_lock_global(curses);
349 save_sp = CURRENT_SCREEN;
351 rc = _nc_keypad(sp, flag);
352 _nc_set_screen(save_sp);
353 _nc_unlock_global(curses);
357 #ifdef USE_TERM_DRIVER
358 rc = CallDriver_1(sp, td_kpad, flag);
360 sp->_keypad_on = flag;
363 (void) NCURSES_PUTP2_FLUSH("keypad_xmit", keypad_xmit);
364 } else if (keypad_local) {
365 (void) NCURSES_PUTP2_FLUSH("keypad_local", keypad_local);
368 if (flag && !sp->_tried) {
372 sp->_keypad_on = flag;