Skip to content

Commit 1399fae

Browse files
authored
Merge branch 'main' into trampoline
2 parents ea00f75 + bbf7786 commit 1399fae

65 files changed

Lines changed: 4293 additions & 1656 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/deprecations/soft-deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ There are no plans to remove :term:`soft deprecated` APIs.
1919

2020
(Contributed by Gregory P. Smith in :gh:`86519` and
2121
Hugo van Kemenade in :gh:`148100`.)
22+
23+
* Using ``'F'`` and ``'D'`` format type codes of the :mod:`struct` module
24+
now are :term:`soft deprecated` in favor of two-letter forms ``'Zf'``
25+
and ``'Zd'``.
26+
(Contributed by Sergey B Kirpichev in :gh:`121249`.)

Doc/library/curses.rst

Lines changed: 210 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,40 @@ The module :mod:`!curses` defines the following functions:
696696
Save the current state of the terminal modes in a buffer, usable by
697697
:func:`resetty`.
698698

699+
.. function:: scr_dump(filename)
700+
701+
Write the current contents of the virtual screen to *filename*, which may be
702+
a string or a :term:`path-like object`. The file can later be read by
703+
:func:`scr_restore`, :func:`scr_init` or :func:`scr_set`. This is the
704+
whole-screen counterpart of :meth:`window.putwin`.
705+
706+
.. versionadded:: next
707+
708+
.. function:: scr_restore(filename)
709+
710+
Set the virtual screen to the contents of *filename*, which must have been
711+
written by :func:`scr_dump`. The next call to :func:`doupdate` or
712+
:meth:`window.refresh` restores the screen to those contents.
713+
714+
.. versionadded:: next
715+
716+
.. function:: scr_init(filename)
717+
718+
Initialize the assumed contents of the terminal from *filename*, which must
719+
have been written by :func:`scr_dump`. Use it when the terminal already
720+
displays those contents, for example after another program has drawn the
721+
screen, so that curses does not redraw what is already there.
722+
723+
.. versionadded:: next
724+
725+
.. function:: scr_set(filename)
726+
727+
Use *filename*, which must have been written by :func:`scr_dump`, as both
728+
the virtual screen and the assumed terminal contents. This combines the
729+
effects of :func:`scr_restore` and :func:`scr_init`.
730+
731+
.. versionadded:: next
732+
699733
.. function:: get_escdelay()
700734

701735
Retrieves the value set by :func:`set_escdelay`.
@@ -941,7 +975,8 @@ Window objects
941975

942976
.. versionchanged:: next
943977
A character may now be given as a string of a base character followed
944-
by combining characters, instead of only a single character.
978+
by combining characters, instead of only a single character, or as a
979+
:class:`complexchar` cell.
945980

946981

947982
.. method:: window.addnstr(str, n[, attr])
@@ -951,13 +986,21 @@ Window objects
951986
``(y, x)`` with attributes
952987
*attr*, overwriting anything previously on the display.
953988

989+
.. versionchanged:: next
990+
*str* may now also be a :class:`complexstr`; see :meth:`addstr`.
991+
954992

955993
.. method:: window.addstr(str[, attr])
956994
window.addstr(y, x, str[, attr])
957995

958996
Paint the character string *str* at ``(y, x)`` with attributes
959997
*attr*, overwriting anything previously on the display.
960998

999+
*str* may also be a :class:`complexstr`, in which case each cell carries its
1000+
own attributes and color pair, so *attr* must not be given. A
1001+
:class:`complexstr` obtained from :meth:`in_wchstr` is written back
1002+
unchanged.
1003+
9611004
.. note::
9621005

9631006
* Writing outside the window, subwindow, or pad raises :exc:`curses.error`.
@@ -970,6 +1013,9 @@ Window objects
9701013
not calling :meth:`!addstr` with a *str* that has embedded newlines;
9711014
instead, call :meth:`!addstr` separately for each line.
9721015

1016+
.. versionchanged:: next
1017+
*str* may now also be a :class:`complexstr`, as described above.
1018+
9731019

9741020
.. method:: window.attroff(attr)
9751021

@@ -1051,7 +1097,8 @@ Window objects
10511097
background character.
10521098

10531099
.. versionchanged:: next
1054-
Wide and combining characters are now accepted.
1100+
Wide and combining characters, and :class:`complexchar` cells, are now
1101+
accepted.
10551102

10561103

10571104
.. method:: window.bkgdset(ch[, attr])
@@ -1064,7 +1111,8 @@ Window objects
10641111
the character through any scrolling and insert/delete line/character operations.
10651112

10661113
.. versionchanged:: next
1067-
Wide and combining characters are now accepted.
1114+
Wide and combining characters, and :class:`complexchar` cells, are now
1115+
accepted.
10681116

10691117

10701118
.. method:: window.border([ls[, rs[, ts[, bs[, tl[, tr[, bl[, br]]]]]]]])
@@ -1100,7 +1148,8 @@ Window objects
11001148
+-----------+---------------------+-----------------------+
11011149

11021150
.. versionchanged:: next
1103-
Wide and combining characters are now accepted. A single call cannot mix
1151+
Wide and combining characters, and :class:`complexchar` cells, are now
1152+
accepted. A single call cannot mix
11041153
them with integer or byte characters.
11051154

11061155

@@ -1110,7 +1159,8 @@ Window objects
11101159
*bs* are *horch*. The default corner characters are always used by this function.
11111160

11121161
.. versionchanged:: next
1113-
Wide and combining characters are now accepted. A single call cannot mix
1162+
Wide and combining characters, and :class:`complexchar` cells, are now
1163+
accepted. A single call cannot mix
11141164
them with integer or byte characters.
11151165

11161166

@@ -1176,13 +1226,25 @@ Window objects
11761226
object for the derived window.
11771227

11781228

1229+
.. method:: window.dupwin()
1230+
1231+
Return a new window that is an exact duplicate of the window: it has the same
1232+
size, position, contents and attributes. Unlike a window created by
1233+
:meth:`subwin` or :meth:`derwin`, the duplicate is independent of the
1234+
original -- it has its own cell buffer, so later changes to one do not affect
1235+
the other.
1236+
1237+
.. versionadded:: next
1238+
1239+
11791240
.. method:: window.echochar(ch[, attr])
11801241

11811242
Add character *ch* with attribute *attr*, and immediately call :meth:`refresh`
11821243
on the window.
11831244

11841245
.. versionchanged:: next
1185-
Wide and combining characters are now accepted.
1246+
Wide and combining characters, and :class:`complexchar` cells, are now
1247+
accepted.
11861248

11871249

11881250
.. method:: window.enclose(y, x)
@@ -1221,6 +1283,20 @@ Window objects
12211283
Return the given window's current background character/attribute pair.
12221284

12231285

1286+
.. method:: window.getbkgrnd()
1287+
1288+
Return the given window's current background as a :class:`complexchar`.
1289+
This is the wide-character variant of :meth:`getbkgd`: the returned object
1290+
carries the background character together with its attributes and color pair,
1291+
and the color pair is not limited to the value that fits in a
1292+
:func:`color_pair`.
1293+
1294+
This method is only available if Python was built against a wide-character
1295+
version of the underlying curses library.
1296+
1297+
.. versionadded:: next
1298+
1299+
12241300
.. method:: window.getch([y, x])
12251301

12261302
Get a character. Note that the integer returned does *not* have to be in ASCII
@@ -1325,7 +1401,8 @@ Window objects
13251401
of the window if fewer than *n* cells are available.
13261402

13271403
.. versionchanged:: next
1328-
Wide and combining characters are now accepted.
1404+
Wide and combining characters, and :class:`complexchar` cells, are now
1405+
accepted.
13291406

13301407

13311408
.. method:: window.idcok(flag)
@@ -1356,6 +1433,20 @@ Window objects
13561433
the character proper, and upper bits are the attributes.
13571434

13581435

1436+
.. method:: window.in_wch([y, x])
1437+
1438+
Return the complex character at the given position in the window as a
1439+
:class:`complexchar`. This is the wide-character variant of :meth:`inch`:
1440+
the returned object carries the cell's text (a spacing character optionally
1441+
followed by combining characters) together with its attributes and color
1442+
pair, none of which :meth:`inch` can represent.
1443+
1444+
This method is only available if Python was built against a wide-character
1445+
version of the underlying curses library.
1446+
1447+
.. versionadded:: next
1448+
1449+
13591450
.. method:: window.insch(ch[, attr])
13601451
window.insch(y, x, ch[, attr])
13611452

@@ -1365,7 +1456,8 @@ Window objects
13651456
line being lost. The cursor position does not change.
13661457

13671458
.. versionchanged:: next
1368-
Wide and combining characters are now accepted.
1459+
Wide and combining characters, and :class:`complexchar` cells, are now
1460+
accepted.
13691461

13701462

13711463
.. method:: window.insdelln(nlines)
@@ -1392,6 +1484,9 @@ Window objects
13921484
cursor are shifted right, with the rightmost characters on the line being lost.
13931485
The cursor position does not change (after moving to *y*, *x*, if specified).
13941486

1487+
.. versionchanged:: next
1488+
*str* may now also be a :class:`complexstr`; see :meth:`insstr`.
1489+
13951490

13961491
.. method:: window.insstr(str[, attr])
13971492
window.insstr(y, x, str[, attr])
@@ -1401,6 +1496,12 @@ Window objects
14011496
shifted right, with the rightmost characters on the line being lost. The cursor
14021497
position does not change (after moving to *y*, *x*, if specified).
14031498

1499+
*str* may also be a :class:`complexstr`, in which case each cell carries its
1500+
own attributes and color pair, so *attr* must not be given.
1501+
1502+
.. versionchanged:: next
1503+
*str* may now also be a :class:`complexstr`, as described above.
1504+
14041505

14051506
.. method:: window.instr([n])
14061507
window.instr(y, x[, n])
@@ -1429,6 +1530,25 @@ Window objects
14291530
.. versionadded:: next
14301531

14311532

1533+
.. method:: window.in_wchstr([n])
1534+
window.in_wchstr(y, x[, n])
1535+
1536+
Return a :class:`complexstr` of the styled cells extracted from the window
1537+
starting at the current cursor position, or at *y*, *x* if specified, and
1538+
stopping at the end of the line. This is the variant of :meth:`instr` and
1539+
:meth:`in_wstr` that *keeps* each cell's attributes and color pair (those
1540+
methods strip the rendition). If *n* is specified, at most *n* cells are
1541+
returned. The maximum value for *n* is 2047.
1542+
1543+
The result can be written back unchanged with :meth:`addstr` (a read and a
1544+
re-write is a round-trip that preserves every cell's rendition).
1545+
1546+
This method is only available if Python was built against a wide-character
1547+
version of the underlying curses library.
1548+
1549+
.. versionadded:: next
1550+
1551+
14321552
.. method:: window.is_cleared()
14331553

14341554
Return the current value set by :meth:`clearok`.
@@ -1776,7 +1896,8 @@ Window objects
17761896
character *ch* with attributes *attr*.
17771897

17781898
.. versionchanged:: next
1779-
Wide and combining characters are now accepted.
1899+
Wide and combining characters, and :class:`complexchar` cells, are now
1900+
accepted.
17801901

17811902

17821903
.. _curses-screen-objects:
@@ -1833,6 +1954,86 @@ Screen objects
18331954
.. versionadded:: next
18341955

18351956

1957+
.. _curses-complexchar-objects:
1958+
1959+
Complex character objects
1960+
-------------------------
1961+
1962+
.. class:: complexchar(text, /, attr=0, pair=0)
1963+
1964+
A *complex character* (or *complexchar*) is an immutable styled
1965+
wide-character cell: a spacing character optionally followed by combining
1966+
characters, together with a set of attributes and a color pair.
1967+
1968+
*text* is the cell's text, *attr* a combination of the
1969+
:ref:`WA_* attributes <curses-wa-constants>` (equivalent to the matching
1970+
``A_*`` constants), and *pair* a color pair number. Unlike the packed
1971+
:class:`chtype <int>` used by :meth:`~window.inch` and the ``A_*`` methods,
1972+
the color pair is stored separately and is not limited to the value that
1973+
fits in a :func:`color_pair`.
1974+
1975+
Complex characters are returned by :meth:`window.in_wch` and
1976+
:meth:`window.getbkgrnd`, and are accepted (along with an integer, a byte
1977+
or a string) by the character-cell methods such as :meth:`window.addch`,
1978+
:meth:`window.insch`, :meth:`window.bkgd`, :meth:`window.border`,
1979+
:meth:`window.hline` and :meth:`window.vline`. A complex character already
1980+
carries its own rendition, so it cannot be combined with an explicit *attr*
1981+
argument.
1982+
1983+
:func:`str` returns the cell's text; two complex characters are equal when
1984+
their text, attributes and color pair all match.
1985+
1986+
This type is only available if Python was built against a wide-character
1987+
version of the underlying curses library.
1988+
1989+
.. attribute:: attr
1990+
1991+
The attributes of the character cell (read-only).
1992+
1993+
.. attribute:: pair
1994+
1995+
The color pair number of the character cell (read-only).
1996+
1997+
.. versionadded:: next
1998+
1999+
2000+
.. class:: complexstr(cells[, attr[, pair]])
2001+
2002+
A *complex character string* (or *complexstr*) is an immutable sequence of
2003+
styled wide-character cells -- the string counterpart of
2004+
:class:`complexchar` (as :class:`str` is to a single character).
2005+
2006+
If *cells* is a string, it is split into character cells (each a spacing
2007+
character optionally followed by combining characters), and *attr* (a
2008+
combination of the :ref:`WA_* attributes <curses-wa-constants>`) and *pair*
2009+
(a color pair number), if given, are applied to every cell.
2010+
2011+
Otherwise *cells* is an iterable whose items are themselves cells, each a
2012+
:class:`complexchar` or a string; each item then carries its own rendition,
2013+
and *attr* and *pair* must be omitted.
2014+
2015+
It is returned by :meth:`window.in_wchstr`, and accepted by
2016+
:meth:`window.addstr`, :meth:`~window.addnstr`, :meth:`~window.insstr` and
2017+
:meth:`~window.insnstr`, so a run read from a window can be written back
2018+
unchanged.
2019+
2020+
It behaves like an immutable sequence: ``len(s)`` is the number of cells,
2021+
``s[i]`` is the *i*-th cell as a :class:`complexchar`, slicing and
2022+
concatenation produce new :class:`!complexstr` instances, and iterating
2023+
yields the cells. :func:`str` returns the cells' text joined together, and
2024+
two complex character strings are equal when their cells all match. It is
2025+
hashable.
2026+
2027+
To build or edit a run of cells, use an ordinary :class:`list` of
2028+
:class:`complexchar` (or strings); a :class:`!complexstr` is the immutable
2029+
form returned by a read.
2030+
2031+
This type is only available if Python was built against a wide-character
2032+
version of the underlying curses library.
2033+
2034+
.. versionadded:: next
2035+
2036+
18362037
Constants
18372038
---------
18382039

Doc/library/io.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,17 @@ than raw I/O does.
771771

772772
Return :class:`bytes` containing the entire contents of the buffer.
773773

774+
.. method:: peek(size=0, /)
775+
776+
Return a copy of the buffer from the current position onwards without
777+
advancing the position.
778+
779+
If *size* is less than one or omitted, at most
780+
:data:`DEFAULT_BUFFER_SIZE` bytes are returned.
781+
Otherwise, at most *size* bytes are returned.
782+
Return an empty :class:`bytes` object at EOF.
783+
784+
.. versionadded:: next
774785

775786
.. method:: read1(size=-1, /)
776787

0 commit comments

Comments
 (0)