Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curses-like library for cross-platform console app in python

Tags:

I'm looking into developing a console application in python which should be able to run under Windows as well as Linux. For this, I'd really like to use a high-level console library like curses. However, as far as I know, curses is not available on Windows.

What other options do I have? Unfortunately, using cygwin under Windows is not an option...

Thanks for your help!

like image 656
andreas-h Avatar asked Aug 07 '09 14:08

andreas-h


People also ask

What is curses module in Python?

What is curses? ¶ The curses library supplies a terminal-independent screen-painting and keyboard-handling facility for text-based terminals; such terminals include VT100s, the Linux console, and the simulated terminal provided by various programs.


4 Answers

There is a wcurses. I've never tried it but it may meet your needs. It sounds like it doesn't have full curses compatibility, but may be close enough. Also it might not be using the DOS terminal, but opening a GUI window and drawing monospaced text inside.

Other windows text mode options are:

  • The console module;
  • wconio -- based on Borland's C conio library.

I believe both are windows only.

like image 159
ehempel Avatar answered Sep 20 '22 14:09

ehempel


I recently hit this issue for a package I was putting together (https://github.com/peterbrittain/asciimatics). I wasn't very happy with the solutions that required you to install (or worse) build separate binary executables like PDCurses or cygwin, so I created a unified API that provides console colours, cursor positioning and keyboard & mouse input for Windows, OSX and UNIX platforms.

This is now live and has been tested on CentOS 6/7 and Windows 7/8/10 and OSX 10.11. You can install it from PYPI using pip and then use the Screen class to control your console. As you can see from the project gallery, it should provide all your console needs, but if you need some extra features, please post an enhancement request on GitHub and I'll see what I can do.

like image 25
Peter Brittain Avatar answered Sep 22 '22 14:09

Peter Brittain


I don't know why people answer in question comments, but debustad is right, there is a prebuilt curses for Windows:

  • http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses

Note lots of other helpful libraries there too. After doing so, install pip and the (lesser known but excellent) bpython interactive interpreter to try it out immediately:

pip install bpython

I also recommend the Urwid library for something higher-level. Never tried it on Windows, but it should be possible with one of the curses packages.

like image 30
Gringo Suave Avatar answered Sep 20 '22 14:09

Gringo Suave


PDCurses works on Windows, but I don't know any Python wrapper. I wonder whether the curses module could be implemented on Windows with PDCurses?

like image 40
Bastien Léonard Avatar answered Sep 18 '22 14:09

Bastien Léonard