@@ -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.
@@ -490,8 +492,8 @@ The module :mod:`!curses` defines the following functions:
490492.. function :: putp(str)
491493
492494 Equivalent to ``tputs(str, 1, putchar) ``; emit the value of a specified
493- terminfo capability for the current terminal. Note that the output of :func: ` putp `
494- always goes to standard output.
495+ terminfo capability, a bytes object, for the current terminal.
496+ Note that the output of :func: ` putp ` always goes to standard output.
495497
496498 :func: `setupterm ` (or :func: `initscr `) must be called first.
497499
@@ -662,7 +664,7 @@ The module :mod:`!curses` defines the following functions:
662664.. function :: tparm(str[, ...])
663665
664666 Instantiate the bytes object *str * with the supplied parameters, where *str * should
665- be a parameterized string obtained from the terminfo database. For example,
667+ be a parameterized byte string obtained from the terminfo database. For example,
666668 ``tparm(tigetstr("cup"), 5, 3) `` could result in ``b'\033[6;4H' ``, the exact
667669 result depending on terminal type. Up to nine integer parameters may be supplied.
668670
@@ -683,7 +685,8 @@ The module :mod:`!curses` defines the following functions:
683685
684686.. function :: unctrl(ch)
685687
686- Return a bytes object which is a printable representation of the character *ch *.
688+ Return a bytes object which is a printable representation of the character *ch *;
689+ any attributes and color pair are ignored.
687690 Control characters are represented as a caret followed by the character, for
688691 example as ``b'^C' ``. Printing characters are left as they are.
689692
@@ -692,6 +695,9 @@ The module :mod:`!curses` defines the following functions:
692695
693696 Push *ch * so the next :meth: `~window.getch ` will return it.
694697
698+ *ch * may be an integer (a key code or the code of an encoded byte), a byte,
699+ or a string of length 1 which encodes to a single byte.
700+
695701 .. note ::
696702
697703 Only one *ch * can be pushed before :meth: `!getch ` is called.
@@ -709,6 +715,9 @@ The module :mod:`!curses` defines the following functions:
709715
710716 Push *ch * so the next :meth: `~window.get_wch ` will return it.
711717
718+ *ch * may be an integer (a character code, not a key code) or a string of
719+ length 1.
720+
712721 .. note ::
713722
714723 Only one *ch * can be pushed before :meth: `!get_wch ` is called.
@@ -989,27 +998,58 @@ Window objects
989998
990999.. method :: window.getch([y, x])
9911000
992- Get a character. Note that the integer returned does *not * have to be in ASCII
993- range: function keys, keypad keys and so on are represented by numbers higher
994- than 255. In no-delay mode, return ``-1 `` if there is no input, otherwise
995- wait until a key is pressed.
1001+ Read a key press, after moving the cursor to *y *, *x * if specified,
1002+ and return it as an integer.
1003+ The window is refreshed first if it is not a pad and was modified since
1004+ the last refresh.
1005+ Wait until a key is pressed, or return ``-1 `` if the read is non-blocking
1006+ or times out (see :meth: `nodelay ` and :meth: `timeout `).
1007+
1008+ An ordinary key is returned as the code of a single byte of its encoding
1009+ in the current locale,
1010+ so a character encoded with several bytes takes several calls.
1011+ For example, in a UTF-8 locale ``'é' `` is read as ``195 ``, then ``169 ``.
1012+ Use :meth: `get_wch ` to read it as a single character.
1013+
1014+ In keypad mode (see :meth: `keypad `) function keys and other special keys
1015+ are returned as one of the :ref: `KEY_* constants <curses-key-constants >`,
1016+ which cannot be mistaken for an ordinary key.
1017+ Otherwise, or if their escape sequence does not arrive in time
1018+ (see :meth: `notimeout ` and :func: `set_escdelay `),
1019+ their bytes are returned one at a time.
1020+
1021+ In echo mode (see :func: `echo `) the key is added to the window as by
1022+ :meth: `addch `; special keys are not echoed.
9961023
9971024
9981025.. method :: window.get_wch([y, x])
9991026
1000- Get a wide character. Return a character for most keys, or an integer for
1001- function keys, keypad keys, and other special keys.
1002- In no-delay mode, raise an exception if there is no input.
1027+ Read a key press, after moving the cursor to *y *, *x * if specified,
1028+ and return it as a one-character :class: `str `.
1029+ The window is refreshed first if it is not a pad and was modified since
1030+ the last refresh.
1031+ Wait until a key is pressed, or raise :exc: `error ` if the read is
1032+ non-blocking or times out (see :meth: `nodelay ` and :meth: `timeout `).
1033+
1034+ In keypad mode (see :meth: `keypad `) function keys and other special keys
1035+ are returned as one of the :ref: `KEY_* constants <curses-key-constants >`,
1036+ an integer.
1037+ Otherwise, or if their escape sequence does not arrive in time
1038+ (see :meth: `notimeout ` and :func: `set_escdelay `),
1039+ their characters are returned one at a time.
1040+
1041+ In echo mode (see :func: `echo `) the key is added to the window as by
1042+ :meth: `addch `; special keys are not echoed.
10031043
10041044 .. versionadded :: 3.3
10051045
10061046
10071047.. method :: window.getkey([y, x])
10081048
1009- Get a character, returning a string instead of an integer, as :meth: ` getch `
1010- does. Function keys, keypad keys and other special keys return a multibyte
1011- string containing the key name. In no-delay mode, raise an exception if
1012- there is no input.
1049+ Read a key press as :meth: ` getch ` does, but return it as a :class: ` str `:
1050+ an ordinary key as a one-character string, the byte decoded as Latin-1,
1051+ and a special key as its name, such as `` 'KEY_UP' `` (see :func: ` keyname `).
1052+ Raise :exc: ` error ` instead of returning `` -1 `` if there is no input.
10131053
10141054
10151055.. method :: window.getmaxyx()
@@ -1029,8 +1069,11 @@ Window objects
10291069 window.getstr(y, x)
10301070 window.getstr(y, x, n)
10311071
1032- Read a bytes object from the user, with primitive line editing capacity.
1033- At most *n * characters are read;
1072+ Read a line of input from the user, with primitive line editing capacity,
1073+ after moving the cursor to *y *, *x * if specified.
1074+ Return it as a bytes object, in the encoding of the current locale
1075+ and without the terminating newline.
1076+ At most *n * bytes are read;
10341077 *n * defaults to and cannot exceed 2047.
10351078
10361079 .. versionchanged :: 3.14
@@ -1132,12 +1175,11 @@ Window objects
11321175.. method :: window.instr([n])
11331176 window.instr(y, x[, n])
11341177
1135- Return a bytes object of characters, extracted from the window starting at the
1136- current cursor position, or at *y *, *x * if specified, and stopping at the end
1137- of the line. Attributes and color information are stripped
1138- from the characters. If *n * is specified, :meth: `instr ` returns a string
1139- at most *n * characters long (exclusive of the trailing NUL).
1140- The maximum value for *n * is 2047.
1178+ Read the text of the window from the current cursor position,
1179+ or from *y *, *x * if specified, to the end of the line,
1180+ and return it as a bytes object, in the encoding of the current locale.
1181+ Attributes and color pairs are stripped.
1182+ At most *n * bytes are read; *n * defaults to and cannot exceed 2047.
11411183
11421184 .. versionchanged :: 3.14
11431185 The maximum value for *n * was increased from 1023 to 2047.
@@ -1161,6 +1203,8 @@ Window objects
11611203 If *flag * is ``True ``, escape sequences generated by some keys (keypad, function keys)
11621204 will be interpreted by :mod: `!curses `. If *flag * is ``False ``, escape sequences will be
11631205 left as is in the input stream.
1206+ Keypad mode is disabled by default, but :func: `wrapper ` enables it for the
1207+ main window.
11641208
11651209
11661210.. method :: window.leaveok(flag)
@@ -1513,6 +1557,8 @@ by some methods.
15131557| | color-pair field information |
15141558+-------------------------+-------------------------------+
15151559
1560+ .. _curses-key-constants :
1561+
15161562Keys are referred to by integer constants with names starting with ``KEY_ ``.
15171563The exact keycaps available are system dependent.
15181564
0 commit comments