Skip to content

Commit 3daf824

Browse files
gh-85796: Build the curses module on Windows against PDCurses
The curses and _curses_panel modules are built when PDCURSES_DIR points to a PDCursesMod source tree, linking it as a shared library so both modules share one screen and panel stack. PDCurses has no terminfo database, so PC/pdcurses supplies the entry points the module needs. curses.pdcurses_version reports the library version, as ncurses_version already does. What PDCurses provides is declared in one block, in the same HAVE_CURSES_* terms that configure defines on Unix. window.encoding follows the program locale, or is UTF-8 where PDCurses is built to force it. A cell holds a character on a wide build and a locale byte on a narrow one, whichever library provides it. test_curses covers the differences: PDCurses has its own color model, supports one screen per process, and reports some errors differently. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 0b083c4 commit 3daf824

13 files changed

Lines changed: 1063 additions & 219 deletions

File tree

Doc/library/curses.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,17 @@ The :mod:`!curses` module defines the following data members:
22112211

22122212
.. versionadded:: 3.8
22132213

2214+
.. data:: pdcurses_version
2215+
2216+
A named tuple containing the three components of the PDCurses library
2217+
version: *major*, *minor*, and *patch*. All values are integers. The
2218+
components can also be accessed by name, so ``curses.pdcurses_version[0]``
2219+
is equivalent to ``curses.pdcurses_version.major`` and so on.
2220+
2221+
Availability: if the PDCurses library is used.
2222+
2223+
.. versionadded:: next
2224+
22142225
.. data:: COLORS
22152226

22162227
The maximum number of colors the terminal can support.

Include/py_curses.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
# define PDC_NCMOUSE
4444
#endif
4545

46+
/* <windows.h>, which Python.h includes, defines MOUSE_MOVED as a console input
47+
flag; PDCurses gives the name to a mouse event mask of its own. The module
48+
uses the curses one, so drop the Windows definition before the header below
49+
redefines it. */
50+
#ifdef MOUSE_MOVED
51+
# undef MOUSE_MOVED
52+
#endif
53+
4654
/* On Solaris/illumos, the SVr4 <curses.h> does "typedef char bool;", which
4755
clashes with C's bool from <stdbool.h>. Define _BOOL to suppress it, and
4856
include <stdbool.h> for the bool the header then needs. ncurses ignores

Lib/test/test_curses.py

Lines changed: 234 additions & 109 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :mod:`curses` and :mod:`curses.panel` modules can now be built on Windows
2+
against a user-supplied `PDCurses <https://pdcurses.org/>`_ library by pointing
3+
the ``PDCURSES_DIR`` environment variable at its source tree.

0 commit comments

Comments
 (0)