@@ -28,6 +28,8 @@ Linux and the BSD variants of Unix.
2828
2929 Whenever the documentation mentions a *character * it can be specified
3030 as an integer, a one-character Unicode string or a one-byte byte string.
31+ An integer is the code of a single encoded byte, optionally combined with
32+ attributes and a color pair, as returned by :meth: `window.inch `.
3133
3234 Whenever the documentation mentions a *character string * it can be specified
3335 as a Unicode string or a byte string.
@@ -484,8 +486,8 @@ The module :mod:`curses` defines the following functions:
484486.. function :: putp(str)
485487
486488 Equivalent to ``tputs(str, 1, putchar) ``; emit the value of a specified
487- terminfo capability for the current terminal. Note that the output of :func: ` putp `
488- always goes to standard output.
489+ terminfo capability, a bytes object, for the current terminal.
490+ Note that the output of :func: ` putp ` always goes to standard output.
489491
490492 :func: `setupterm ` (or :func: `initscr `) must be called first.
491493
@@ -656,7 +658,7 @@ The module :mod:`curses` defines the following functions:
656658.. function :: tparm(str[, ...])
657659
658660 Instantiate the bytes object *str * with the supplied parameters, where *str * should
659- be a parameterized string obtained from the terminfo database. For example,
661+ be a parameterized byte string obtained from the terminfo database. For example,
660662 ``tparm(tigetstr("cup"), 5, 3) `` could result in ``b'\033[6;4H' ``, the exact
661663 result depending on terminal type. Up to nine integer parameters may be supplied.
662664
@@ -677,7 +679,8 @@ The module :mod:`curses` defines the following functions:
677679
678680.. function :: unctrl(ch)
679681
680- Return a bytes object which is a printable representation of the character *ch *.
682+ Return a bytes object which is a printable representation of the character *ch *;
683+ any attributes and color pair are ignored.
681684 Control characters are represented as a caret followed by the character, for
682685 example as ``b'^C' ``. Printing characters are left as they are.
683686
@@ -686,6 +689,9 @@ The module :mod:`curses` defines the following functions:
686689
687690 Push *ch * so the next :meth: `~window.getch ` will return it.
688691
692+ *ch * may be an integer (a key code or the code of an encoded byte), a byte,
693+ or a string of length 1 which encodes to a single byte.
694+
689695 .. note ::
690696
691697 Only one *ch * can be pushed before :meth: `!getch ` is called.
@@ -703,6 +709,9 @@ The module :mod:`curses` defines the following functions:
703709
704710 Push *ch * so the next :meth: `~window.get_wch ` will return it.
705711
712+ *ch * may be an integer (a character code, not a key code) or a string of
713+ length 1.
714+
706715 .. note ::
707716
708717 Only one *ch * can be pushed before :meth: `!get_wch ` is called.
@@ -988,27 +997,58 @@ Window objects
988997
989998.. method :: window.getch([y, x])
990999
991- Get a character. Note that the integer returned does *not * have to be in ASCII
992- range: function keys, keypad keys and so on are represented by numbers higher
993- than 255. In no-delay mode, return ``-1 `` if there is no input, otherwise
994- wait until a key is pressed.
1000+ Read a key press, after moving the cursor to *y *, *x * if specified,
1001+ and return it as an integer.
1002+ The window is refreshed first if it is not a pad and was modified since
1003+ the last refresh.
1004+ Wait until a key is pressed, or return ``-1 `` if the read is non-blocking
1005+ or times out (see :meth: `nodelay ` and :meth: `timeout `).
1006+
1007+ An ordinary key is returned as the code of a single byte of its encoding
1008+ in the current locale,
1009+ so a character encoded with several bytes takes several calls.
1010+ For example, in a UTF-8 locale ``'é' `` is read as ``195 ``, then ``169 ``.
1011+ Use :meth: `get_wch ` to read it as a single character.
1012+
1013+ In keypad mode (see :meth: `keypad `) function keys and other special keys
1014+ are returned as one of the :ref: `KEY_* constants <curses-key-constants >`,
1015+ which cannot be mistaken for an ordinary key.
1016+ Otherwise, or if their escape sequence does not arrive in time
1017+ (see :meth: `notimeout ` and :func: `set_escdelay `),
1018+ their bytes are returned one at a time.
1019+
1020+ In echo mode (see :func: `echo `) the key is added to the window as by
1021+ :meth: `addch `; special keys are not echoed.
9951022
9961023
9971024.. method :: window.get_wch([y, x])
9981025
999- Get a wide character. Return a character for most keys, or an integer for
1000- function keys, keypad keys, and other special keys.
1001- In no-delay mode, raise an exception if there is no input.
1026+ Read a key press, after moving the cursor to *y *, *x * if specified,
1027+ and return it as a one-character :class: `str `.
1028+ The window is refreshed first if it is not a pad and was modified since
1029+ the last refresh.
1030+ Wait until a key is pressed, or raise :exc: `error ` if the read is
1031+ non-blocking or times out (see :meth: `nodelay ` and :meth: `timeout `).
1032+
1033+ In keypad mode (see :meth: `keypad `) function keys and other special keys
1034+ are returned as one of the :ref: `KEY_* constants <curses-key-constants >`,
1035+ an integer.
1036+ Otherwise, or if their escape sequence does not arrive in time
1037+ (see :meth: `notimeout ` and :func: `set_escdelay `),
1038+ their characters are returned one at a time.
1039+
1040+ In echo mode (see :func: `echo `) the key is added to the window as by
1041+ :meth: `addch `; special keys are not echoed.
10021042
10031043 .. versionadded :: 3.3
10041044
10051045
10061046.. method :: window.getkey([y, x])
10071047
1008- Get a character, returning a string instead of an integer, as :meth: ` getch `
1009- does. Function keys, keypad keys and other special keys return a multibyte
1010- string containing the key name. In no-delay mode, raise an exception if
1011- there is no input.
1048+ Read a key press as :meth: ` getch ` does, but return it as a :class: ` str `:
1049+ an ordinary key as a one-character string, the byte decoded as Latin-1,
1050+ and a special key as its name, such as `` 'KEY_UP' `` (see :func: ` keyname `).
1051+ Raise :exc: ` error ` instead of returning `` -1 `` if there is no input.
10121052
10131053
10141054.. method :: window.getmaxyx()
@@ -1028,9 +1068,12 @@ Window objects
10281068 window.getstr(y, x)
10291069 window.getstr(y, x, n)
10301070
1031- Read a bytes object from the user, with primitive line editing capacity.
1032- At most *n * characters are read (1023 by default).
1033- The maximum value for *n * is 1023.
1071+ Read a line of input from the user, with primitive line editing capacity,
1072+ after moving the cursor to *y *, *x * if specified.
1073+ Return it as a bytes object, in the encoding of the current locale
1074+ and without the terminating newline.
1075+ At most *n * bytes are read;
1076+ *n * defaults to and cannot exceed 1023.
10341077
10351078
10361079.. method :: window.getyx()
@@ -1128,11 +1171,11 @@ Window objects
11281171.. method :: window.instr([n])
11291172 window.instr(y, x[, n])
11301173
1131- Return a bytes object of characters, extracted from the window starting at the
1132- current cursor position, or at *y *, *x * if specified, and stopping at the end
1133- of the line. Attributes and color information are stripped
1134- from the characters. If * n * is specified, :meth: ` instr ` returns a string
1135- at most *n * characters long (exclusive of the trailing NUL) .
1174+ Read the text of the window from the current cursor position,
1175+ or from *y *, *x * if specified, to the end of the line,
1176+ and return it as a bytes object, in the encoding of the current locale.
1177+ Attributes and color pairs are stripped.
1178+ At most *n * bytes are read; * n * defaults to and cannot exceed 1023 .
11361179
11371180
11381181.. method :: window.is_linetouched(line)
@@ -1153,6 +1196,8 @@ Window objects
11531196 If *flag * is ``True ``, escape sequences generated by some keys (keypad, function keys)
11541197 will be interpreted by :mod: `curses `. If *flag * is ``False ``, escape sequences will be
11551198 left as is in the input stream.
1199+ Keypad mode is disabled by default, but :func: `wrapper ` enables it for the
1200+ main window.
11561201
11571202
11581203.. method :: window.leaveok(flag)
@@ -1505,6 +1550,8 @@ by some methods.
15051550| | color-pair field information |
15061551+-------------------------+-------------------------------+
15071552
1553+ .. _curses-key-constants :
1554+
15081555Keys are referred to by integer constants with names starting with ``KEY_ ``.
15091556The exact keycaps available are system dependent.
15101557
0 commit comments