@@ -27,6 +27,8 @@ Linux and the BSD variants of Unix.
2727
2828 Whenever the documentation mentions a *character * it can be specified
2929 as an integer, a one-character Unicode string or a one-byte byte string.
30+ An integer is the code of a single encoded byte, optionally combined with
31+ attributes and a color pair, as returned by :meth: `window.inch `.
3032
3133 Whenever the documentation mentions a *character string * it can be specified
3234 as a Unicode string or a byte string.
@@ -502,8 +504,8 @@ The module :mod:`!curses` defines the following functions:
502504.. function :: putp(str)
503505
504506 Equivalent to ``tputs(str, 1, putchar) ``; emit the value of a specified
505- terminfo capability for the current terminal. Note that the output of :func: ` putp `
506- always goes to standard output.
507+ terminfo capability, a bytes object, for the current terminal.
508+ Note that the output of :func: ` putp ` always goes to standard output.
507509
508510 :func: `setupterm ` (or :func: `initscr `) must be called first.
509511
@@ -674,7 +676,7 @@ The module :mod:`!curses` defines the following functions:
674676.. function :: tparm(str[, ...])
675677
676678 Instantiate the bytes object *str * with the supplied parameters, where *str * should
677- be a parameterized string obtained from the terminfo database. For example,
679+ be a parameterized byte string obtained from the terminfo database. For example,
678680 ``tparm(tigetstr("cup"), 5, 3) `` could result in ``b'\033[6;4H' ``, the exact
679681 result depending on terminal type. Up to nine integer parameters may be supplied.
680682
@@ -695,7 +697,8 @@ The module :mod:`!curses` defines the following functions:
695697
696698.. function :: unctrl(ch)
697699
698- Return a bytes object which is a printable representation of the character *ch *.
700+ Return a bytes object which is a printable representation of the character *ch *;
701+ any attributes and color pair are ignored.
699702 Control characters are represented as a caret followed by the character, for
700703 example as ``b'^C' ``. Printing characters are left as they are.
701704
@@ -704,6 +707,9 @@ The module :mod:`!curses` defines the following functions:
704707
705708 Push *ch * so the next :meth: `~window.getch ` will return it.
706709
710+ *ch * may be an integer (a key code or the code of an encoded byte), a byte,
711+ or a string of length 1 which encodes to a single byte.
712+
707713 .. note ::
708714
709715 Only one *ch * can be pushed before :meth: `!getch ` is called.
@@ -721,6 +727,9 @@ The module :mod:`!curses` defines the following functions:
721727
722728 Push *ch * so the next :meth: `~window.get_wch ` will return it.
723729
730+ *ch * may be an integer (a character code, not a key code) or a string of
731+ length 1.
732+
724733 .. note ::
725734
726735 Only one *ch * can be pushed before :meth: `!get_wch ` is called.
@@ -1001,27 +1010,58 @@ Window objects
10011010
10021011.. method :: window.getch([y, x])
10031012
1004- Get a character. Note that the integer returned does *not * have to be in ASCII
1005- range: function keys, keypad keys and so on are represented by numbers higher
1006- than 255. In no-delay mode, return ``-1 `` if there is no input, otherwise
1007- wait until a key is pressed.
1013+ Read a key press, after moving the cursor to *y *, *x * if specified,
1014+ and return it as an integer.
1015+ The window is refreshed first if it is not a pad and was modified since
1016+ the last refresh.
1017+ Wait until a key is pressed, or return ``-1 `` if the read is non-blocking
1018+ or times out (see :meth: `nodelay ` and :meth: `timeout `).
1019+
1020+ An ordinary key is returned as the code of a single byte of its encoding
1021+ in the current locale,
1022+ so a character encoded with several bytes takes several calls.
1023+ For example, in a UTF-8 locale ``'é' `` is read as ``195 ``, then ``169 ``.
1024+ Use :meth: `get_wch ` to read it as a single character.
1025+
1026+ In keypad mode (see :meth: `keypad `) function keys and other special keys
1027+ are returned as one of the :ref: `KEY_* constants <curses-key-constants >`,
1028+ which cannot be mistaken for an ordinary key.
1029+ Otherwise, or if their escape sequence does not arrive in time
1030+ (see :meth: `notimeout ` and :func: `set_escdelay `),
1031+ their bytes are returned one at a time.
1032+
1033+ In echo mode (see :func: `echo `) the key is added to the window as by
1034+ :meth: `addch `; special keys are not echoed.
10081035
10091036
10101037.. method :: window.get_wch([y, x])
10111038
1012- Get a wide character. Return a character for most keys, or an integer for
1013- function keys, keypad keys, and other special keys.
1014- In no-delay mode, raise an exception if there is no input.
1039+ Read a key press, after moving the cursor to *y *, *x * if specified,
1040+ and return it as a one-character :class: `str `.
1041+ The window is refreshed first if it is not a pad and was modified since
1042+ the last refresh.
1043+ Wait until a key is pressed, or raise :exc: `error ` if the read is
1044+ non-blocking or times out (see :meth: `nodelay ` and :meth: `timeout `).
1045+
1046+ In keypad mode (see :meth: `keypad `) function keys and other special keys
1047+ are returned as one of the :ref: `KEY_* constants <curses-key-constants >`,
1048+ an integer.
1049+ Otherwise, or if their escape sequence does not arrive in time
1050+ (see :meth: `notimeout ` and :func: `set_escdelay `),
1051+ their characters are returned one at a time.
1052+
1053+ In echo mode (see :func: `echo `) the key is added to the window as by
1054+ :meth: `addch `; special keys are not echoed.
10151055
10161056 .. versionadded :: 3.3
10171057
10181058
10191059.. method :: window.getkey([y, x])
10201060
1021- Get a character, returning a string instead of an integer, as :meth: ` getch `
1022- does. Function keys, keypad keys and other special keys return a multibyte
1023- string containing the key name. In no-delay mode, raise an exception if
1024- there is no input.
1061+ Read a key press as :meth: ` getch ` does, but return it as a :class: ` str `:
1062+ an ordinary key as a one-character string, the byte decoded as Latin-1,
1063+ and a special key as its name, such as `` 'KEY_UP' `` (see :func: ` keyname `).
1064+ Raise :exc: ` error ` instead of returning `` -1 `` if there is no input.
10251065
10261066
10271067.. method :: window.getmaxyx()
@@ -1041,8 +1081,11 @@ Window objects
10411081 window.getstr(y, x)
10421082 window.getstr(y, x, n)
10431083
1044- Read a bytes object from the user, with primitive line editing capacity.
1045- At most *n * characters are read;
1084+ Read a line of input from the user, with primitive line editing capacity,
1085+ after moving the cursor to *y *, *x * if specified.
1086+ Return it as a bytes object, in the encoding of the current locale
1087+ and without the terminating newline.
1088+ At most *n * bytes are read;
10461089 *n * defaults to and cannot exceed 2047.
10471090
10481091 .. versionchanged :: 3.14
@@ -1144,12 +1187,11 @@ Window objects
11441187.. method :: window.instr([n])
11451188 window.instr(y, x[, n])
11461189
1147- Return a bytes object of characters, extracted from the window starting at the
1148- current cursor position, or at *y *, *x * if specified, and stopping at the end
1149- of the line. Attributes and color information are stripped
1150- from the characters. If *n * is specified, :meth: `instr ` returns a string
1151- at most *n * characters long (exclusive of the trailing NUL).
1152- The maximum value for *n * is 2047.
1190+ Read the text of the window from the current cursor position,
1191+ or from *y *, *x * if specified, to the end of the line,
1192+ and return it as a bytes object, in the encoding of the current locale.
1193+ Attributes and color pairs are stripped.
1194+ At most *n * bytes are read; *n * defaults to and cannot exceed 2047.
11531195
11541196 .. versionchanged :: 3.14
11551197 The maximum value for *n * was increased from 1023 to 2047.
@@ -1173,6 +1215,8 @@ Window objects
11731215 If *flag * is ``True ``, escape sequences generated by some keys (keypad, function keys)
11741216 will be interpreted by :mod: `!curses `. If *flag * is ``False ``, escape sequences will be
11751217 left as is in the input stream.
1218+ Keypad mode is disabled by default, but :func: `wrapper ` enables it for the
1219+ main window.
11761220
11771221
11781222.. method :: window.leaveok(flag)
@@ -1525,6 +1569,8 @@ by some methods.
15251569| | color-pair field information |
15261570+-------------------------+-------------------------------+
15271571
1572+ .. _curses-key-constants :
1573+
15281574Keys are referred to by integer constants with names starting with ``KEY_ ``.
15291575The exact keycaps available are system dependent.
15301576
0 commit comments