Home | History | Annotate | Download | only in libcurses
History log of /src/lib/libcurses/getch.c
RevisionDateAuthorComments
 1.79  14-May-2024  uwe curse: constify define_key() argument

define_key() is ncurses extension and ncurses defines its first
argument as "const char *". Follow suit.

PR lib/58254
 1.78  19-Oct-2021  blymn Fix for PR pkg/55931
Don't move the cursor when getch is called if input is not going to
be echoed. Lynx uses the cursor to mark the current selection in a
pop-up, previously the cursor was being relocated when getch was called
which broke the Lynx item marking.
 1.77  06-Sep-2021  rin Style fixes most for __CTRACE().
 1.76  06-Sep-2021  rin Expand __CTRACE() to __nothing #ifndef DEBUG.

Remove most of #ifdef DEBUG around __CTRACE() calls.

No binary changes, except for line numbers for assert().
 1.75  06-Jul-2020  uwe Pads are not to be automatically refreshed on input.

X/Open Curses says in the documentation for newpad():

Automatic refreshes of pads (e.g., from scrolling or echoing of
input) do not occur.

And in the documentation for get*():

If the current or specified window is not a pad, and it has been
moved or modified since the last refresh operation, then it will be
refreshed before another character is read.

From Michael Forney in PR lib/55457
 1.74  14-May-2020  simonb KNF nit.
 1.73  09-Jun-2019  blymn branches: 1.73.2;
Rework previous fix for getch cursor position when cursor is moved
without refresh. If the window is not dirty but the window cursor
position does not match curscr then move the cursor. This fixes
the issues seen in PR lib/54263.
 1.72  20-May-2019  blymn Back out incorrect fix for PR 53617 and fix it in a different way.
Keep track of the cursor location, if getch is called without a refresh
and without pending updates (dirty windows) then move the cursor to the
correct location directly. Doing this prevents unnecessary refreshes.
 1.71  14-Mar-2019  rin Rename global variable "state" to "_cursesi_state".

Until now, if application happens to have a global variable of the same
name, it was overridden by curses routines. This is the scenario in
which aspell crashes when linked to our curses, reported in pkg/44005.

We need to wipe out global/static variables like "_cursesi_state" or
"wstate" for thread safety. But it would be a future task...

XXX pullup to netbsd-8 and netbsd-7
 1.70  28-Sep-2018  roy curses: resizeterm(3) should always send KEY_RESIZE

Fixes #53636

OK kamil@
 1.69  27-Sep-2018  roy curses: call resizeterm if getch issues KEY_RESIZE

This fixes PR #53633.
 1.68  27-Sep-2018  roy curses: unify resize handling in getch

Instead of testing each fgetc call for resize event, add the wrapper
__fgetc_resize to simplify the logic.
While here, ensure that get_wch uses the correct input stream which
may or may not be stdin.
 1.67  26-Sep-2018  kamil Correct detecting of terminal resize in curses(3) with keypad(,TRUE)

A previous change fixed only keypad(,FALSE) scenarios.

Handle catching terminal resize in INKEY_NORM and INKEY_ASSEMBLING (in the
middle of assembling a key code from passed codes) as both accept keys with
fgetc(3) and both can be in theory interrupted with a resize.

PR lib/53615
 1.66  18-Sep-2018  rin PR lib/53615

getch() and get_wch() should return KEY_RESIZE when interrupted by SIGWINCH.

OK roy
 1.65  31-Jan-2017  roy branches: 1.65.4; 1.65.10; 1.65.12;
Move ESCDELAY to curses.c so all globals are close to each other.
Remove _reentrant and use ESCDELAY and TABSIZE as we're not really
reentrant.
 1.64  30-Jan-2017  roy Check _cursesi_term is set in a few places and sprinkle some static.
 1.63  30-Jan-2017  roy If either set_escdelay(3) or set_tabsize(3) are called, set _reentrant
to ensure we use the saved value for the sceen.

This effectively makes ESCDELAY and TABSIZE read-only when either
of these functions are called.
 1.62  06-Jan-2017  roy branches: 1.62.2;
KNF.
Normalise coding style.
White space police.
Sprinkle some extra braces to make the flow more clear.

No functional changes.
 1.61  05-Jan-2017  roy Add the set_escdelay(3) and set_tabsize(3) ncurses extensions.
 1.60  01-Jan-2017  roy Implement ncurses extension has_key.
 1.59  21-Apr-2012  roy branches: 1.59.10; 1.59.14;
Add capfile(5) to describe the termcap format.
Adjust various man pages and other documentation to point to capfile(5)
instead of termcap(5).
Remove getcap(3) as curses hasn't been building it for a long time.
Punt wrterm.c as tset no longer uses it.
 1.58  21-Apr-2011  blymn branches: 1.58.4;
Fix deleting a key definition, it did not work. Also improve tracing
of key definition deletion.
 1.57  07-Dec-2010  joerg Since limit and l are both unsigned, comparing to 0 doesn't work, so compare
the values directly.
 1.56  05-Nov-2010  blymn Don't echo key symbols.
 1.55  03-Feb-2010  roy Userland now builds and uses terminfo instead of termcap.

OK: core@, jdc@
 1.54  04-Nov-2009  dsl Read input from the correct FILE.
 1.53  01-Nov-2009  dsl Move calls to __restore_termios() into the failing path of the functions
that fail - instead of in most of the callers.
All rather pointless if tcsetattr() fails to set the mode we want we
are very unlikely to be able to restore any later on.
 1.52  09-Feb-2009  jdc Fix bug where a single ESC was not recognised when in keypad() mode.
Noticed by abs@.
 1.51  14-Apr-2008  jdc branches: 1.51.8; 1.51.10;
Add extra debugging information.
 1.50  08-Dec-2007  jdc Keep pushed-back characters locally. Fixes problems where KEY_* symbols
are pushed back. Should fix the arrow keys part of PR pkg/37173.

While we are here, make getch() and get_wch() check for resize immediately,
instead of reading a key, checking for resize and then having to push-back
the just read key.
 1.49  28-Aug-2007  blymn Fix a crash caused by having a single NULL character as a string capability.
This fix is about the best we can do given the current interfaces. We
could extend the cgetcap(3) interfaces with a function that would return
a character count and handle this in libterm which would provide a more
complete fix and allow a NULL character in a string capability.
 1.48  28-May-2007  blymn branches: 1.48.4;
Merge in wide curses code done as a Summer of Code project by
Ruibiao Qiu.
 1.47  21-Jan-2007  jdc Add debug "areas" that allow selective debugging by setting the
"CURSES_TRACE_MASK" environment variable. Postive vales include
debug areas, negative values exclude them.
 1.46  25-Jul-2006  christos branches: 1.46.6;
PR/34011: Julian Coleman: Limit timeout to 25.5 seconds.
 1.45  19-Mar-2006  christos Coverity CID 1246: Don't allow getc == -1 to propagate as an array index.
 1.44  22-Mar-2004  jdc Add KEY_RESIZE support and a SIGWINCH handler.
Fixes PR bin/20032.
This requires a change to KEY_MAX, which affects libform and libmenu, so we
need to change libcurses major number.
 1.43  16-Mar-2004  jdc Minor style change.
 1.42  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.41  08-Apr-2003  jdc Add ESCDELAY variable to control the inter-key delay in escape sequences.
Fixes PR 20031 by Thomas Klausner.
 1.40  05-Apr-2003  jdc Keep the cr->nl translation state in a separate variable, so that we can
do the translation ourselves (if the tty didn't do it for us).
Add debugging to track functions that change tty state.

Fixes PR 20834 by Stephen Borrill.
 1.39  17-Feb-2003  dsl Fix resize of windows with subwins.
Let window size be given as a -ver number => lines from bottom.
Fix trace calls of pointers
(approved by Brett Lumn)
 1.38  23-Dec-2002  jdc Increase default delay when assembling key sequences. This seems to
eliminate the occasional non-recognition of key sequences over remote
connections.
Okayed by blymn.
 1.37  22-Oct-2002  blymn Added the ncurses extensions define_key and keyok.
 1.36  02-Jan-2002  blymn branches: 1.36.2;
Remove extraneous tabs from blank lines.
 1.35  02-Dec-2001  blymn * Major change to add support for the newterm/set_term functions.
* Added fix to getch.c suggested by Gabriel Rosenkoetter (thanks :-)
 1.34  01-Nov-2001  tron Remove bogus call to free(3) which caused several warning messages in
application using our "curses" library after the latest change to
memory management in the "c" library.
 1.33  10-Jan-2001  blymn Fixed casting bug in array indexing, a signed char was being sign
extended when cast to unsigned, made the cast "unsigned char"
 1.32  23-Sep-2000  itojun do not call wrefresh() uncondintionally from wgetch(). call it only
when the window was touched (is_wintouched()).
the previous behavior damaged existing applications, especially when it issues
lots of subwindow manipulation and mvcur().

it was introduced in 1.23 -> 1.24 or sometime before.
 1.31  31-Jul-2000  itojun free region got from t_getstr(). we will experience memory leak if
we call initscr() multiple times (rare, but it's better to be pedant).
 1.30  31-Jul-2000  itojun fix 8bit cleanness of getch() and wgetch(). never use char variable against
stdio functions which return "int" (including getchar()).
the bug was introduced in 1.9 -> 1.10. fixes PR10723.
 1.29  25-May-2000  jdc branches: 1.29.4;
Send 'ks' sequence from first call to keypad(win, TRUE) only and not from
wgetch(). Don't send 'ke' sequence from keypad(win, FALSE) or wgetch().
This makes us compatible with Solaris.
Suggested by ITOH Yasufumi.
 1.28  17-May-2000  jdc Send, if necessary, 'ks' or 'ke' sequences from keypad() and wgetch().
Fixes PR 10116.
 1.27  01-May-2000  blymn * Made erasechar and killchar into functions
* Modified __init_getch to use termcap handle that has been allocated
(_cursesi_genbuf) instead of refetching it.
* Make wgetstr support erase - this is not a full blown SUSv2 version
but it is a start.
 1.26  27-Apr-2000  mycroft No, really, make sure ECHO is cleared in cbreak() mode too.
 1.25  27-Apr-2000  jdc Add extra KEY_* definitions (from SUSv2).
Fix `gcc -Wuninitialized`.
 1.24  23-Apr-2000  blymn * Fixed bug in copywin which was copying more than it should.
* Changed call to wrefresh in wgetch to be before input read.
* Changed default old cursor mode to be high vis in curs_set
* Added documentation for various new functions to fns.doc.
 1.23  22-Apr-2000  thorpej Fully initialize the structure allocated in new_keymap().
 1.22  22-Apr-2000  blymn * Added ungetch
* Converted inkey and getch to use getchar instead of read so ungetch
will work.
 1.21  18-Apr-2000  jdc Make sure we don't read a negative character value (again).
 1.20  17-Apr-2000  blymn Multiple fixes:
* Added Bill's fixes for errors when compiling with WARNS=1
* Incorporated fixes to make usage of unctrl consistent in debug and
made improvements to ctrace - it now timestamps it's output better.
* Reduced the number of mallocs done by __init_getch by allocating key
structs in bunches instead of singly.
* Removed the shadowing of global declarations in newwin and subwin
functions
 1.19  15-Apr-2000  jdc Add a missing __restore_termios() in an error return.
Don't display the character on curscr if the terminal has echo on :
- doing so will break the tracking of curscr->cury|x if we've just refreshed
a non-fullscreen window
- with echo on, the terminal displays the character for us anyway
 1.18  15-Apr-2000  blymn Added functions to replace what were previously macros in curses.h
(this is a requirement of SUSv2) - the old macro behaviour can be
restored by defining _CURSES_USE_MACROS.
Changed function prototypes to use ANSI style.
All externally visible functions now have ANSI style declarations.
 1.17  12-Apr-2000  jdc Make sure we don't read a negative character value.
 1.16  11-Apr-2000  blymn Made data structures opaque
 1.15  07-Dec-1999  simonb branches: 1.15.2;
Only unctrl() the first 256 input values.

This and the previous curses patches were from Brett Lymn.
 1.14  28-Jun-1999  simonb branches: 1.14.4;
Get rid of the evil trailing spaces and tabs.
 1.13  15-Jun-1999  simonb Make a few private variables and functions static.
 1.12  06-Jun-1999  pk Re-arrange some code to approach our regular style.
 1.11  06-Jun-1999  pk Hang on to the termcap buffer that we have tgetent() fill.
(someone ows me two hours worth of beer for this... :-)
 1.10  13-Apr-1999  mrg Upgrades the standard NetBSD curses library to provide some
of the SYSV curses facilities. The added features are the collapsing
of arrow and function keysequences (as defined by termcap for the
terminal) into symbolic code returns thus relieving the application of
recognising multi-character key sequences. Other features are the
capability to perform a timed wait for a key (good for when you are
not sure if there is a keypress ready or not) and the capability for
turning off the inter-key timeout when assembling multi-character
function keys.

this work was done by Julian Coleman <J.D.Coleman@newcastle.ac.uk>
and blymn@baea.com.au (Brett Lymn). i'm just integrating it. thanks
HEAPS guys!
 1.9  03-Feb-1998  perry remove obsolete register declarations
 1.8  22-Jul-1997  mikel RCSid police, fix warnings
 1.7  17-Aug-1994  cgd branches: 1.7.2;
clean up import
 1.6  09-Nov-1993  cgd repeat after me: "I hate rcs ids"
 1.5  09-Nov-1993  cgd update to new version from berkeley. doesn't compile yet, nor
does it have rcsid's. this is for diffs.
 1.4  07-Aug-1993  mycroft New version from uunet.
 1.3  01-Aug-1993  mycroft Add RCS identifiers.
 1.2  09-Jul-1993  alm added Andrew Chernov's patch set:
Standard curses library use eight bit for standout mode, so
8-bit characters displays like highlighted 7-bit characters.

This patch produce library which is fully compatible with all curses
programs and add 8-bit chars to all input/display functions.
---
I don't think, that any programs wish to use internal curses
attribute _STANDOUT directly, in expressions like:
addch( ch | _STANDOUT );
Normal interface use standout() and standend() functions instead.
Many programs use 'char' type (with sign extention) for input characters
and sign extention becomes _STANDOUT mode in this case.
So, I refuse this future and allow 8-bit characters for programs,
which is designed for 7-bit only ('char' type using instead of
'unsigned char').
---
This small patch fix unpleasant standard curses bug:
curses can't expand TAB at all (but tries).
A man who wrote this curses misplace SYNC_IN and SYNCH_OUT,
this patch exchange macro calls.

This patch useful for standard 7-bit curses too, for this
you must delete '_' symbol before waddbytes and apply patch.
---
Oh, NO! This curses are really buggy!

This small patch fix following problem:
[ assumed scrollok(stdscr, TRUE) ]
when addch(ch) at lower right corner of screen, curses are realy
gone mad instead if simple scrolling... Curses code assumed that
this will be done correctly, but implement it with two bugs.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  17-Aug-1994  cgd new libcurses, from new nvi
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.2  17-Aug-1994  cgd clean up import
 1.7.2.1  17-Aug-1994  cgd file getch.c was added on branch netbsd-1-0 on 1994-08-17 21:52:18 +0000
 1.14.4.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.2.2  27-Mar-2000  jdc Handle characters with top bit set.
 1.15.2.1  09-Jan-2000  jdc Changes to make libcurses SUS v2 compatible.
 1.29.4.3  29-Sep-2000  itojun pullup 1.31 -> 1.32 (approved by releng-1-5)

>do not call wrefresh() uncondintionally from wgetch(). call it only
>when the window was touched (is_wintouched()).
>the previous behavior damaged existing applications, especially when it issues
>lots of subwindow manipulation and mvcur().
>
>it was introduced in 1.23 -> 1.24 or sometime before.
 1.29.4.2  03-Aug-2000  itojun pullup 1.30 -> 1.31 (approved by releng-1-5)

> free region got from t_getstr(). we will experience memory leak if
> we call initscr() multiple times (rare, but it's better to be pedant).
 1.29.4.1  03-Aug-2000  itojun pullup 1.29 -> 1.30 (approved by releng-1-5)

> fix 8bit cleanness of getch() and wgetch(). never use char variable against
> stdio functions which return "int" (including getchar()).
> the bug was introduced in 1.9 -> 1.10. fixes PR10723.
 1.36.2.1  16-Jun-2003  grant Apply patch (requested by jdc in ticket #1244):

Keep the cr->nl translation state in a separate variable, so that we can
do the translation ourselves (if the tty didn't do it for us).
Add debugging to track functions that change tty state.
 1.46.6.3  25-Jan-2007  blymn * rearrange code to ensure that SET_WCOL() is called after attributes
are copied/set.

* fix some instances where attributes were being checked without
masking with WA_ATTRIBUTES

* Replace another instance of non-spacing character copying with function
call.
 1.46.6.2  21-Jan-2007  jdc Apply the changes that add debug "areas" on HEAD to the wcurses branch.
Add correspending changes to the debug code that is only present on the branch.
 1.46.6.1  21-Jan-2007  blymn Wide curses merge
 1.48.4.2  09-Jan-2008  matt sync with HEAD
 1.48.4.1  06-Nov-2007  matt sync with HEAD
 1.51.10.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.51.8.1  18-Feb-2009  snj Pull up following revision(s) (requested by jdc in ticket #451):
lib/libcurses/getch.c: revision 1.52
Fix bug where a single ESC was not recognised when in keypad() mode.
Noticed by abs@.
 1.58.4.1  23-May-2012  yamt sync with head.
 1.59.14.2  20-Mar-2017  pgoyette Sync with HEAD
 1.59.14.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.59.10.1  15-Mar-2019  martin Pull up following revision(s) (requested by rin in ticket #1686):

lib/libcurses/get_wch.c: revision 1.21
lib/libcurses/getch.c: revision 1.71

Rename global variable "state" to "_cursesi_state".

Until now, if application happens to have a global variable of the same
name, it was overridden by curses routines. This is the scenario in
which aspell crashes when linked to our curses, reported in pkg/44005.

We need to wipe out global/static variables like "_cursesi_state" or
"wstate" for thread safety. But it would be a future task...

XXX pullup to netbsd-8 and netbsd-7
 1.62.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.65.12.1  10-Jun-2019  christos Sync with HEAD
 1.65.10.1  30-Sep-2018  pgoyette Ssync with HEAD
 1.65.4.4  15-Mar-2019  martin Pull up following revision(s) (requested by rin in ticket #1214):

lib/libcurses/get_wch.c: revision 1.21
lib/libcurses/getch.c: revision 1.71

Rename global variable "state" to "_cursesi_state".

Until now, if application happens to have a global variable of the same
name, it was overridden by curses routines. This is the scenario in
which aspell crashes when linked to our curses, reported in pkg/44005.

We need to wipe out global/static variables like "_cursesi_state" or
"wstate" for thread safety. But it would be a future task...

XXX pullup to netbsd-8 and netbsd-7
 1.65.4.3  03-Oct-2018  martin Pull up following revision(s) (requested by roy in ticket #1043):

lib/libcurses/resize.c: revision 1.27
lib/libcurses/get_wch.c: revision 1.19
lib/libcurses/getch.c: revision 1.70

curses: resizeterm(3) should always send KEY_RESIZE

Fixes #53636

OK kamil@
 1.65.4.2  27-Sep-2018  martin Pull up following revision(s) (requested by roy in ticket #1042):
lib/libcurses/getch.c: revision 1.68
lib/libcurses/getch.c: revision 1.69
lib/libcurses/get_wch.c: revision 1.17
lib/libcurses/get_wch.c: revision 1.18
lib/libcurses/curses_private.h: revision 1.63
curses: unify resize handling in getch
Instead of testing each fgetc call for resize event, add the wrapper
__fgetc_resize to simplify the logic.
While here, ensure that get_wch uses the correct input stream which
may or may not be stdin.
curses: call resizeterm if getch issues KEY_RESIZE
This fixes PR #53633.
 1.65.4.1  27-Sep-2018  martin Pull up following revision(s) (requested by kamil in ticket #1039):

lib/libcurses/getch.c: revision 1.66
lib/libcurses/getch.c: revision 1.67
lib/libcurses/tstp.c: revision 1.43
lib/libcurses/get_wch.c: revision 1.15
lib/libcurses/get_wch.c: revision 1.16

PR lib/53615
getch() and get_wch() should return KEY_RESIZE when interrupted by SIGWIN=
CH.

OK roy

-

PR lib/53615
Before invoking a previous signal handler, make sure it is not SIG_*.
Fix potential crash with SIGWINCH.

OK roy

-

Correct detecting of terminal resize in curses(3) with keypad(,TRUE)
A previous change fixed only keypad(,FALSE) scenarios.

-

Handle catching terminal resize in INKEY_NORM and INKEY_ASSEMBLING (in the
middle of assembling a key code from passed codes) as both accept keys with
fgetc(3) and both can be in theory interrupted with a resize.

PR lib/53615
 1.73.2.1  07-Jul-2020  martin Pull up following revision(s) (requested by uwe in ticket #987):

lib/libcurses/get_wch.c: revision 1.24
lib/libcurses/getch.c: revision 1.75

Pads are not to be automatically refreshed on input.

X/Open Curses says in the documentation for newpad():
Automatic refreshes of pads (e.g., from scrolling or echoing of
input) do not occur.

And in the documentation for get*():
If the current or specified window is not a pad, and it has been
moved or modified since the last refresh operation, then it will be
refreshed before another character is read.

From Michael Forney in PR lib/55457

RSS XML Feed