About | Professional | Arts | Entertainment | Links

Curses Programming

The original curses is a terminal control library for Unix-like systems, allowing to write text-based applications without writing directly for any specific terminal type. ncurses replaced it later. A similar idea for DOS is conio.

Applications

Curses was needed for C in Windows and Android (using Cxxdroid), and for Python in Windows and Android (using Pydroid 3). In the case of Android, Cxxdroid already allows the use of ncurses, while Python in *nix/Android already includes curses in its standard library. For C in Windows, PDcurses was selected, though it required being built from source code. For Python, the windows-curses package was selected.

The next section discusses only what required intervention.

Building & Adaptation

PDCurses Build & Use

PDCurses is a curses port for Windows. A suitable binary or library couldn't be found, so it had to be built.

Started downloading the latest release from the GitHub repository. Since it will be used in Code::Blocks and Visual Studio, different builds would be needed.

Visual Studio Build

A x64 Native Tools Command Prompt was opened, and following the instructions in the wincon folder's README file, we start by setting:

set PDCURSES_SRCDIR=<directory>

for the base PDCurses directory. We can also change the current directory to a newly created out directory, where the object files and output will placed. We then run:

nmake -f <path-to-make-file>Makefile.vc WIDE=Y UTF8=Y

You get a bunch of .obj files (which can be safely deleted) and a pdcurses.lib file, which can then be linked to your project.

Use in a Visual Studio Project

After creating a console app, the curses.h must be added and referenced, the pdcurses.lib file must be kept near and the project must be made aware of the library linking. In the Project Properties page, Configuration Properties > VC++ Directories > Library Directories must be updated appending the path to the library. Also, the library file name must be appended in Configuration Properties > Linker > Input > Additional Dependencies.

MinGW Build

For Code::Blocks, a MinGW compatible build toolset is needed. Since the MinGW package distributed with Code::Blocks doesn't include make, it was necessary to download an pre-built MinGW toolchain. w64devkit was installed (having the latest GCC/MinGW-w64 versions) and the build run was similar to the Visual Studio one, using the Makefile (no extension) file to build it. This time, you get a pdcurses.a library file.

Use in a Code::Blocks Project

After creating a project, the curses.h must be added and referenced, the pdcurses.lib file must be kept near and the project must be made aware of the library linking. Access menus Project > Properties and in the Project settings tab, select the last button, Project's build options. In the Linker settings tab, add the library file to the Link libraries list. Also, make sure that the path to the library is added in the Search directories tab, Compiler and Linker lists.

The Python windows-curses Package

Since the Windows version of Python doesn't include the curses module, we will add the 3rd party package windows-curses. After creating and activating a venv to test, we enter:

pip install windows-curses

We can then import the module as the standard curses module via:

import curses

and use it normally.

Documentation & Links

General curses Documentation

PDCurses Documentation & Repository

Python curses Documentation

Python windows-curses Package Documentation & Repository

Page last modified December 28, 2024.

Big Floating Image