@@ -206,17 +206,15 @@ The module :mod:`!curses` defines the following functions:
206206
207207.. function :: erasechar()
208208
209- Return the user's current erase character as a one-byte bytes object. Under Unix operating systems this
210- is a property of the controlling tty of the curses program, and is not set by
211- the curses library itself.
209+ Return the user's current erase character as a raw byte, a :class: `bytes `
210+ object of length 1. See also :func: `erasewchar `.
212211
213212
214213.. function :: erasewchar()
215214
216- Return the user's current erase character as a one-character string.
217- This is the wide-character variant of :func: `erasechar `. Availability
218- depends on building Python against a wide-character-aware version of the
219- underlying curses library.
215+ Return the user's current erase character as a one-character :class: `str `.
216+ Under Unix operating systems this is a property of the controlling tty of the
217+ curses program, and is not set by the curses library itself.
220218
221219 .. versionadded :: next
222220
@@ -348,6 +346,13 @@ The module :mod:`!curses` defines the following functions:
348346 a key with that value.
349347
350348
349+ .. function :: has_mouse()
350+
351+ Return ``True `` if the mouse driver has been successfully initialized.
352+
353+ .. versionadded :: next
354+
355+
351356.. function :: define_key(definition, keycode)
352357
353358 Define an escape sequence *definition *, a string, as a key that generates
@@ -493,17 +498,15 @@ The module :mod:`!curses` defines the following functions:
493498
494499.. function :: killchar()
495500
496- Return the user's current line kill character as a one-byte bytes object. Under Unix operating systems
497- this is a property of the controlling tty of the curses program, and is not set
498- by the curses library itself.
501+ Return the user's current line kill character as a raw byte, a :class: `bytes `
502+ object of length 1. See also :func: `killwchar `.
499503
500504
501505.. function :: killwchar()
502506
503- Return the user's current line kill character as a one-character string.
504- This is the wide-character variant of :func: `killchar `. Availability
505- depends on building Python against a wide-character-aware version of the
506- underlying curses library.
507+ Return the user's current line kill character as a one-character :class: `str `.
508+ Under Unix operating systems this is a property of the controlling tty of the
509+ curses program, and is not set by the curses library itself.
507510
508511 .. versionadded :: next
509512
@@ -910,30 +913,39 @@ The module :mod:`!curses` defines the following functions:
910913.. function :: unctrl(ch)
911914
912915 Return a bytes object which is a printable representation of the character *ch *.
913- Control characters are represented as a caret followed by the character, for
914- example as `` b'^C' ``. Printing characters are left as they are .
916+ * ch * cannot be a character that does not fit in a single byte; use
917+ :func: ` wunctrl ` for those .
915918
916919
917920.. function :: wunctrl(ch)
918921
919- Return a string which is a printable representation of the wide character *ch *.
920- Control characters are represented as a caret followed by the character, for
921- example as `` '^C' ``. Printing characters are left as they are. This is the
922- wide-character variant of :func: ` unctrl `, returning a :class: ` str ` rather than
923- :class: ` bytes `. Availability depends on building Python against a
924- wide-character-aware version of the underlying curses library.
922+ Return a string which is a printable representation of the character *ch *;
923+ any attributes and color pair are ignored.
924+ ASCII control characters are represented as a caret followed by a character,
925+ for example as `` '^C' ``. Printing characters, including non-ASCII characters
926+ printable in the locale, are left as they are. The representation of other
927+ characters is defined by the underlying curses library.
925928
926929 .. versionadded :: next
927930
928931
929932.. function :: ungetch(ch)
930933
931- Push *ch * so the next :meth: `~window.getch ` will return it.
934+ Push *ch * so the next :meth: `~window.getch ` or :meth: `~window.get_wch ` will
935+ return it.
936+
937+ *ch * may be an integer (a key code or character code), a byte, or a string of
938+ length 1. A one-character string is pushed like :func: `unget_wch `; on a
939+ narrow build it must encode to a single byte.
932940
933941 .. note ::
934942
935943 Only one *ch * can be pushed before :meth: `!getch ` is called.
936944
945+ .. versionchanged :: next
946+ A one-character string argument is no longer required to encode to a single
947+ byte, except on a narrow build.
948+
937949
938950.. function :: update_lines_cols()
939951
@@ -953,6 +965,10 @@ The module :mod:`!curses` defines the following functions:
953965
954966 .. versionadded :: 3.3
955967
968+ .. versionchanged :: next
969+ Also available on a narrow build, where *ch * must encode to a single byte
970+ (an 8-bit locale).
971+
956972
957973.. function :: ungetmouse(id, x, y, z, bstate)
958974
@@ -1300,6 +1316,18 @@ Window objects
13001316 Previously it returned ``1 `` or ``0 `` instead of ``True `` or ``False ``.
13011317
13021318
1319+ .. method :: window.mouse_trafo(y, x, to_screen)
1320+
1321+ Convert between window-relative and screen-relative (``stdscr ``-relative) character-cell coordinates.
1322+ If *to_screen * is true, convert the window-relative coordinates *y *, *x * to screen-relative coordinates;
1323+ otherwise convert in the opposite direction.
1324+ The two coordinate systems differ when lines are reserved on the screen, for example for soft labels.
1325+
1326+ Return the converted coordinates as a ``(y, x) `` tuple, or ``None `` if they lie outside the window.
1327+
1328+ .. versionadded :: next
1329+
1330+
13031331.. attribute :: window.encoding
13041332
13051333 Encoding used to encode method arguments (Unicode strings and characters).
@@ -1323,15 +1351,17 @@ Window objects
13231351.. method :: window.getbkgd()
13241352
13251353 Return the given window's current background character/attribute pair.
1354+ Its components can be extracted like those of :meth: `inch `.
1355+ It cannot represent a background set with a wide character or with a color
1356+ pair outside the :func: `color_pair ` range; use :meth: `getbkgrnd ` for those.
13261357
13271358
13281359.. method :: window.getbkgrnd()
13291360
13301361 Return the given window's current background as a :class: `complexchar `.
1331- This is the wide-character variant of :meth: `getbkgd `: the returned object
1332- carries the background character together with its attributes and color pair,
1333- and the color pair is not limited to the value that fits in a
1334- :func: `color_pair `.
1362+ Unlike :meth: `getbkgd `, the returned object carries the background character
1363+ together with its attributes and color pair, and the color pair is not limited
1364+ to the value that fits in a :func: `color_pair `.
13351365
13361366 .. versionadded :: next
13371367
@@ -1342,16 +1372,23 @@ Window objects
13421372 range: function keys, keypad keys and so on are represented by numbers higher
13431373 than 255. In no-delay mode, return ``-1 `` if there is no input, otherwise
13441374 wait until a key is pressed.
1375+ A multibyte character is returned as its encoded bytes one at a time; use
1376+ :meth: `get_wch ` to read it as a single character.
13451377
13461378
13471379.. method :: window.get_wch([y, x])
13481380
13491381 Get a wide character. Return a character for most keys, or an integer for
1350- function keys, keypad keys, and other special keys.
1382+ function keys, keypad keys, and other special keys. Unlike :meth: `getch `, an
1383+ ordinary key is returned as a one-character :class: `str `.
13511384 In no-delay mode, raise an exception if there is no input.
13521385
13531386 .. versionadded :: 3.3
13541387
1388+ .. versionchanged :: next
1389+ Also available on a narrow build, where only a character representable as a
1390+ single byte (an 8-bit locale) can be returned.
1391+
13551392
13561393.. method :: window.getdelay()
13571394
@@ -1407,6 +1444,8 @@ Window objects
14071444 Read a bytes object from the user, with primitive line editing capacity.
14081445 At most *n * characters are read;
14091446 *n * defaults to and cannot exceed 2047.
1447+ A multibyte character is returned as its encoded bytes; use :meth: `get_wstr `
1448+ to read the input as a :class: `str `.
14101449
14111450 .. versionchanged :: 3.14
14121451 The maximum value for *n * was increased from 1023 to 2047.
@@ -1418,9 +1457,8 @@ Window objects
14181457 window.get_wstr(y, x, n)
14191458
14201459 Read a string from the user, with primitive line editing capacity.
1421- This is the wide-character variant of :meth: `getstr `: it returns a
1422- :class: `str ` rather than a :class: `bytes ` object, so it can return
1423- characters that are not representable in the window's encoding.
1460+ Unlike :meth: `getstr `, it can return characters that are not representable in
1461+ the window's encoding.
14241462 At most *n * characters are read; *n * defaults to and cannot exceed 2047.
14251463
14261464 .. versionadded :: next
@@ -1468,17 +1506,21 @@ Window objects
14681506
14691507.. method :: window.inch([y, x])
14701508
1471- Return the character at the given position in the window. The bottom 8 bits are
1472- the character proper, and upper bits are the attributes.
1509+ Return the character at the given position in the window.
1510+ The bottom 8 bits are the character proper and the upper bits are the attributes;
1511+ extract them with the :data: `A_CHARTEXT ` and :data: `A_ATTRIBUTES ` bit-masks,
1512+ and the color pair with :func: `pair_number `.
1513+ It cannot represent a cell holding combining characters, a character that does
1514+ not fit in a single byte, or a color pair outside the :func: `color_pair `
1515+ range; use :meth: `in_wch ` for those, which returns it as a :class: `complexchar `.
14731516
14741517
14751518.. method :: window.in_wch([y, x])
14761519
14771520 Return the complex character at the given position in the window as a
1478- :class: `complexchar `. This is the wide-character variant of :meth: `inch `:
1479- the returned object carries the cell's text (a spacing character optionally
1480- followed by combining characters) together with its attributes and color
1481- pair, none of which :meth: `inch ` can represent.
1521+ :class: `complexchar `. Unlike :meth: `inch `, the returned object carries the
1522+ cell's text (a spacing character optionally followed by combining characters)
1523+ together with its attributes and color pair.
14821524
14831525 .. versionadded :: next
14841526
@@ -1548,6 +1590,8 @@ Window objects
15481590 from the characters. If *n * is specified, :meth: `instr ` returns a string
15491591 at most *n * characters long (exclusive of the trailing NUL).
15501592 The maximum value for *n * is 2047.
1593+ A character not representable in the window's encoding cannot be returned;
1594+ use :meth: `in_wstr ` for those.
15511595
15521596 .. versionchanged :: 3.14
15531597 The maximum value for *n * was increased from 1023 to 2047.
@@ -1557,11 +1601,10 @@ Window objects
15571601 window.in_wstr(y, x[, n])
15581602
15591603 Return a string of characters, extracted from the window starting at the
1560- current cursor position, or at *y *, *x * if specified. This is the
1561- wide-character variant of :meth: `instr `: it returns a :class: `str ` rather
1562- than a :class: `bytes ` object, so it can return characters that are not
1563- representable in the window's encoding. Attributes and color information
1564- are stripped from the characters. The maximum value for *n * is 2047.
1604+ current cursor position, or at *y *, *x * if specified. Unlike :meth: `instr `,
1605+ it can return characters that are not representable in the window's encoding.
1606+ Attributes and color information are stripped from the characters. The
1607+ maximum value for *n * is 2047.
15651608
15661609 .. versionadded :: next
15671610
@@ -2624,6 +2667,11 @@ You can instantiate a :class:`Textbox` object as follows:
26242667 upper-left corner of the containing window, with coordinates ``(0, 0) ``.
26252668 The instance's :attr: `stripspaces ` flag is initially on.
26262669
2670+ .. versionchanged :: next
2671+ Entering and reading back the full Unicode range, including combining
2672+ characters, is now supported when curses is built with wide-character
2673+ support.
2674+
26272675 :class: `Textbox ` objects have the following methods:
26282676
26292677
@@ -2638,6 +2686,10 @@ You can instantiate a :class:`Textbox` object as follows:
26382686 string; whether blanks in the window are included is affected by the
26392687 :attr: `stripspaces ` attribute.
26402688
2689+ .. versionchanged :: next
2690+ *validate * is now called with a non-ASCII character as a string;
2691+ other keystrokes are still passed as an integer.
2692+
26412693
26422694 .. method :: do_command(ch)
26432695
0 commit comments