This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Unsupported provider

classification
Title: curses for windows (alternative patch)
Type: enhancement Stage: patch review
Components: Extension Modules, Windows Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Mario Figueiredo, Prasun Ratn, Taylor.Marks, Trundle, cgohlke, christoph.baumgartner, ipatrol, jkloth, jmb, loewis, maarten, paul.moore, rpetrov, techtonik, ulfalizer, zhirsch
Priority: normal Keywords: patch

Created on 2008-05-16 06:38 by techtonik, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
curses_win_port.patch.txt techtonik, 2008-05-16 06:38
curses_win_compile.bat techtonik, 2008-05-16 06:39
python-pdcurses.patch zhirsch, 2009-01-26 00:49
python-pdcurses-2.patch zhirsch, 2009-03-09 09:56
python-pdcurses-3.patch jmb, 2009-10-21 07:24
pdcurses-changes.patch Prasun Ratn, 2011-01-23 11:49 Changes to Lib/test/test_curses.py Modules/_cursesmodule.c PC/mkstemp.c PC/pyconfig.h PCbuild/_curses.vcproj PCbuild/_curses_panel.vcproj PCbuild/pcbuild.sln PCbuild/pdcurses.vcproj PCbuild/pythoncore.vcproj
pdcurses.patch Prasun Ratn, 2011-01-23 11:50 pdcurses source
Messages (23)
msg66920 - (view) Author: anatoly techtonik (techtonik) Date: 2008-05-16 06:38
Make curses available on Windows by using PDCurses library. Alternative
patch for issue 1005895 using current trunk.

Attached .bat file is used to compile it under MinGW, but I'd be glad to
know how to integrate the patch into Python build system.

PDCurses includes support for mouse functions compatible with ncurses,
but to turn it on if requires to define NCURSES_MOUSE_VERSION to 2
before <curses.h> is included. I am not familiar with configure.* stuff,
so I've just pasted required definitions into _cursesmodule.c
With attached .bat file it works by external definition.

Some functions, such as initterm are not available on Windows platform
and were defined out.

I hope that curses module will be included in next Python 2.6
msg67288 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-05-24 09:51
The patch, in its current form, is incomplete. Can you please provide:

a) a VS 2008 project file, which builds both the curses module and the
   pdcurses library, fetching the sources for that from ../../pdcurses (or 
   some such); the project file should be structured similar to all the 
   other project files in PCbuild
b) a patch to PCbuild/readme.txt, with instructions on how to build the 
   extension
msg80554 - (view) Author: Zach Hirsch (zhirsch) Date: 2009-01-26 00:49
Here's a patch against the head of trunk that adds vcproj files for
_curses and _curses_panel, modifies (slightly) the test suite and
_cursesmodule.c (again, slightly) to get Python to work with pdcurses on
windows. I also added a blurb to PCbuild\readme.txt.

With this, test_curses.py passes and I'm able to run all the curses
demos that come with Python's source.
msg82781 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2009-02-26 22:22
I can't say anything about the Windows build aspects.  Some observations
about the curses/test_curses changes:

* test_curses: I'd be happier to see the 'if' statement as sys.platform
!= 'win32' and (not term or term == 'unknown')  -- easier to read.

* test_curses: does putp() make PDCurses crash, or is it not available?
 If the latter, I'd prefer to see 'if hasattr(curses, "putp"): <putp
test>'.    Same for the tparm() test.

* Given that you include term.h and IRIX included term.h, I wonder if we
should make _cursesmodule.c include term.h on all platforms that have
it, and then fix the resulting breakage claimed by the comment (if any).

* Is setupterm() a no-up on Windows?  Maybe the function just shouldn't
be defined on Windows, then, so that user code can check for the
function's existence.
msg83365 - (view) Author: Zach Hirsch (zhirsch) Date: 2009-03-09 09:56
> * test_curses: I'd be happier to see the 'if' statement as sys.platform
> != 'win32' and (not term or term == 'unknown')  -- easier to read.

OK, fixed.

> * test_curses: does putp() make PDCurses crash, or is it not available?
>  If the latter, I'd prefer to see 'if hasattr(curses, "putp"): <putp
test>'.    Same for the tparm() test.

They're stubs in pdcurses that always return an error. I'm not sure
which is better in this case -- make them available through the curses
module but always raise an exception on Windows, or make them
unavailable and have it be an AttributeError if something tries to call
them on Windows.

> * Given that you include term.h and IRIX included term.h, I wonder if we
> should make _cursesmodule.c include term.h on all platforms that have
it, and then fix the resulting breakage claimed by the comment (if any).

Yea, it was actually really easy to resolve the conflicts. I've done
that, and tested the result on Linux and OS X 10.4.

> * Is setupterm() a no-up on Windows?  Maybe the function just shouldn't
> be defined on Windows, then, so that user code can check for the
function's existence.

PDCurses does the same thing for setupterm as it does for putp/tparm
(and a number of other unsupported functions) -- always returns an
error. However, the curses module keeps track of whether it's been
initialized based on whether setupterm has been called, so I think it
makes sense to keep setupterm available but not call PDCurses's
setupterm function on Windows.
msg94309 - (view) Author: (jmb) Date: 2009-10-21 07:24
I've built a package for python 2.6 using a slightly modified version of
this patch. I've uploaded it here: http://jeberger.free.fr/python/

I'm attaching my version of the patch here. I had to make two
modifications for it to work:
- Change all references to _ISPAD into _PAD (obviously this needs to be
done better since what I did will break the ncurses compatibility);
- Change "(long) (n << 8)" into "COLOR_PAIR (n)". This should be
compatible between curses implementations.

With this package, I've been able to run the Mercurial "crecord"
extension on Windows.
msg114011 - (view) Author: (ipatrol) Date: 2010-08-15 21:26
Any progress yat?
msg114013 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-08-15 21:30
It can't go into 2.x anymore.
msg114370 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-19 15:54
Brian or Tim any interest in this?
msg114399 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-08-19 18:46
I'll pick it up for the moment to shepherd it along because I'm reasonably keen to see a Windows curses in the stdlib. However, I'm no expert in curses and I don't promise to do anything immediate with it.
msg114740 - (view) Author: Roumen Petrov (rpetrov) * Date: 2010-08-23 21:48
-1 for PDCurses
msg114770 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-08-24 07:27
I have no strong opinion, Roumen, (and no experience with the package) 
but why -1 from you?
msg114778 - (view) Author: Roumen Petrov (rpetrov) * Date: 2010-08-24 11:42
Recent ncurses pass python tests with only one small update (part of patch to issue 3871):
=====================================
--- ./Lib/test/test_curses.py.MINGW	2010-08-09 00:03:48.000000000 +0300
+++ ./Lib/test/test_curses.py	2010-08-09 00:05:38.000000000 +0300
@@ -167,11 +167,16 @@
     curses.delay_output(1)
     curses.echo() ; curses.echo(1)
 
-    f = tempfile.TemporaryFile()
+    fx = tempfile.TemporaryFile()
+    # cf tempfile.py TemporaryFile vs NamedTemporaryFile
+    if os.name != 'posix' or os.sys.platform == 'cygwin':
+        f = fx.file
+    else:
+        f = fx
     stdscr.putwin(f)
     f.seek(0)
     curses.getwin(f)
-    f.close()
+    fx.close()
 
     curses.halfdelay(1)
     curses.intrflush(1)
=====================================
About TERM environment variable - I don't have time to test ncurses if is not set.

Also PDCurses is not updated since 2008.
msg116224 - (view) Author: anatoly techtonik (techtonik) Date: 2010-09-12 18:43
PDCurses is not updated, because it is considered stable and mature library that has been tested on Windows platform by many roguelikes. I doubt that ncurses hackers care about Windows compatibility more than just to make it run.
msg126887 - (view) Author: Prasun Ratn (Prasun Ratn) Date: 2011-01-23 11:49
What is the status of this bug?

I tried to build the svn trunk with patches provided by zhirsch but I had problems applying the patches. I went ahead and made a new patch which is pretty similar to the earlier patch (mentioned above). The one change is that I implemented mkstemp() so putwin() and getwin() work.
msg128191 - (view) Author: Christoph Gohlke (cgohlke) Date: 2011-02-08 21:47
Curses binaries for Python 2.5, 2.6, 2.7, 3.1 and 3.2, win32 and win-amd64, are available at <http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses>.
msg185746 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2013-04-01 17:21
@Christoph Gohlke any chance of providing a build for 3.3?
msg222640 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-09 21:20
Can this be closed as curses binaries for Python 2.5, 2.6, 2.7, 3.1, 3.2, 3.3 and 3.4, win32 and win-amd64, are available at <http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses>, plus there is also https://pypi.python.org/pypi/UniCurses/1.2 ?
msg236384 - (view) Author: Taylor Marks (Taylor.Marks) Date: 2015-02-21 18:22
Python is supposed to be cross platform. This has been a major incompatibility issue between Windows and *nix and you think this patch, which has been ready for nearly 7 years now, should simply get discarded because the fix is available from pip?

I think there are two possible remedies to this:
 - Accept this patch.
 - Remove curses from the Python standard library for *nix (breaks backwards compatibility for *nix, but fixes compatibility between Windows and *nix going forward.)
msg237855 - (view) Author: Mario Figueiredo (Mario Figueiredo) Date: 2015-03-11 09:18
This patch is a huge improvement over the current situation, which is we don't have a cross-platform curses implementation in the standard library.

The alternatives listed by Mark aren't sufficient. For the two reasons given below:

- The implementation at http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses does not support unicode characters, which is a big limitation in today's general computing tasks.

- The UniCurses module isn't compatible with the curses standard lib implementation since it wraps curses/pdcurses and does not provide python own wrappers like the ability of addstr to accept encoded byte strings. This essentially makes UniCurses a 3rd-party library requirements regardless of the operating system, which is always nice to have but does not help the batteries included principles behind python standard library.

Conclusion:
Please implement this patch ASAP. It's been many years since it was made available. It works, it passes all tests and we all benefit if we close this python cross-compatibility issue.
msg237857 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2015-03-11 10:00
The patch would need updating to be applicable. Minimum changes I would expect to be required:

1. Update to build for Python 3.5 (the patch will *not* be included in earlier versions, as it is a new feature), which means it needs the Visual Studio 2015 build files updating.
2. Rather than wholesale dumping a curses implementation into the Python source (which is what pdcurses.patch seems to do) the appropriate curses source should be fetched via the externals.bat script, like the other external dependencies.
3. Documentation. At a minimum "available in Windows from Python X.Y", but probably also document any differences from Unix, which from the comments here are likely to exist if the patch uses pdcurses on Windows.
4. Tests. Again, make sure that any functionality that differs is properly covered on Windows, or skip specific Unix-only functionality.

That's quite a lot of changes, in practice.

Unless someone is going to step up and do all of that (and keep it maintained until it gets merged, which probably won't be till 3.6) *and* there's one of the core devs willing to support the code going forward once its committed, then I think closing this as "won't fix" and referring to the external packages is the best solution.

A documentation patch to https://docs.python.org/3.4/howto/curses.html ("Curses programming with Python") which explained how to set up one of the external curses modules on Windows, and how to write cross-platform code that uses the core implementation on Unix and the 3rd party module on Windows, would be immensely useful for people interested in this patch. Probably far more so than pushing for this patch to go in, in all honesty, as it's easier to do and would be useful to people on older versions of Python as well.
msg349089 - (view) Author: Ulf Magnusson (ulfalizer) Date: 2019-08-05 23:03
Just as an FYI, there is a repository for building curses wheels for Windows at https://github.com/zephyrproject-rtos/windows-curses, based on patches from here and Gohlke's work.

Building wheels is less straightforward than it used to be, e.g. due to term.h disappearing from PDCurses.

We also make wheels available on PyPI.
msg375683 - (view) Author: Maarten (maarten) * Date: 2020-08-20 01:41
Current ncurses master is buildable on Visual Studio, using msys2.

It should be possible to create a vcxproject and integrate it in the Visual Studio build.
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47138
2021-04-05 14:37:31jklothsetnosy: + jkloth
2020-08-20 01:41:35maartensetnosy: + maarten
messages: + msg375683
2019-08-05 23:03:51ulfalizersetnosy: + ulfalizer
messages: + msg349089
2019-03-15 22:26:53BreamoreBoysetnosy: - BreamoreBoy
2015-03-11 10:00:34paul.mooresetmessages: + msg237857
2015-03-11 09:18:56Mario Figueiredosetnosy: + Mario Figueiredo
messages: + msg237855
2015-02-21 18:22:55Taylor.Markssetnosy: + Taylor.Marks
messages: + msg236384
2014-12-31 16:25:52akuchlingsetnosy: - akuchling
2014-07-09 21:20:43BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222640
2014-02-03 15:47:28BreamoreBoysetnosy: - BreamoreBoy
2013-11-05 10:08:47christoph.baumgartnersetnosy: + christoph.baumgartner
2013-10-24 10:00:33tim.goldensetnosy: - tim.golden
2013-07-31 15:10:03tim.goldensetassignee: tim.golden ->
2013-04-01 17:21:39BreamoreBoysetmessages: + msg185746
2011-02-08 21:47:32cgohlkesetnosy: loewis, akuchling, paul.moore, techtonik, tim.golden, rpetrov, zhirsch, Trundle, cgohlke, jmb, ipatrol, BreamoreBoy, Prasun Ratn
messages: + msg128191
2011-01-23 11:50:57Prasun Ratnsetfiles: + pdcurses.patch
nosy: loewis, akuchling, paul.moore, techtonik, tim.golden, rpetrov, zhirsch, Trundle, cgohlke, jmb, ipatrol, BreamoreBoy, Prasun Ratn
2011-01-23 11:49:11Prasun Ratnsetfiles: + pdcurses-changes.patch
nosy: + Prasun Ratn
messages: + msg126887

2010-12-30 22:40:27georg.brandlsetnosy: loewis, akuchling, paul.moore, techtonik, tim.golden, rpetrov, zhirsch, Trundle, cgohlke, jmb, ipatrol, BreamoreBoy
versions: + Python 3.3, - Python 3.2
2010-10-09 06:58:35cgohlkesetnosy: + cgohlke
2010-09-12 22:02:27brian.curtinsetnosy: - brian.curtin
2010-09-12 18:43:42techtoniksetmessages: + msg116224
2010-08-24 11:42:15rpetrovsetmessages: + msg114778
2010-08-24 07:27:29tim.goldensetmessages: + msg114770
2010-08-24 01:13:38Trundlesetnosy: + Trundle
2010-08-23 21:48:31rpetrovsetnosy: + rpetrov
messages: + msg114740
2010-08-19 18:46:23tim.goldensetassignee: tim.golden
messages: + msg114399
2010-08-19 15:54:37BreamoreBoysetnosy: + tim.golden, brian.curtin, BreamoreBoy

messages: + msg114370
stage: patch review
2010-08-15 21:30:57loewissetmessages: + msg114013
versions: + Python 3.2, - Python 2.6, Python 2.7
2010-08-15 21:26:59ipatrolsetversions: + Python 2.7
nosy: + ipatrol

messages: + msg114011

components: + Windows
type: enhancement
2009-10-21 07:24:18jmbsetfiles: + python-pdcurses-3.patch

messages: + msg94309
2009-10-19 13:02:36jmbsetnosy: + jmb
2009-03-23 20:55:30paul.mooresetnosy: + paul.moore
2009-03-09 09:56:53zhirschsetfiles: + python-pdcurses-2.patch

messages: + msg83365
2009-02-26 22:23:00akuchlingsetmessages: + msg82781
2009-02-26 22:12:14akuchlingsetnosy: + akuchling
2009-01-26 00:49:37zhirschsetfiles: + python-pdcurses.patch
nosy: + zhirsch
messages: + msg80554
keywords: + patch
2008-05-24 09:51:38loewissetnosy: + loewis
messages: + msg67288
2008-05-16 06:39:47techtoniksetfiles: + curses_win_compile.bat
2008-05-16 06:38:26techtonikcreate