Curses C API

curses exposes a small C interface for extension modules.Consumers must include the header filepy_curses.h (which is notincluded by default byPython.h) andimport_curses() mustbe invoked, usually as part of the module initialisation function, to populatePyCurses_API.

Warning

Neither the C API nor the pure Pythoncurses module are compatiblewith subinterpreters.

import_curses()

Import the curses C API. The macro does not need a semi-colon to be called.

On success, populate thePyCurses_API pointer.

On failure, setPyCurses_API to NULL and set an exception.The caller must check if an error occurred viaPyErr_Occurred():

import_curses();// semi-colon is optional but recommendedif(PyErr_Occurred()){/* cleanup */}
void**PyCurses_API

Dynamically allocated object containing the curses C API.This variable is only available onceimport_curses succeeds.

PyCurses_API[0] corresponds toPyCursesWindow_Type.

PyCurses_API[1],PyCurses_API[2], andPyCurses_API[3]are pointers to predicate functions of typeint(*)(void).

When called, these predicates return whethercurses.setupterm(),curses.initscr(), andcurses.start_color() have been calledrespectively.

See also the convenience macrosPyCursesSetupTermCalled,PyCursesInitialised, andPyCursesInitialisedColor.

Note

The number of entries in this structure is subject to changes.Consider usingPyCurses_API_pointers to check ifnew fields are available or not.

PyCurses_API_pointers

The number of accessible fields (4) inPyCurses_API.This number is incremented whenever new fields are added.

PyTypeObjectPyCursesWindow_Type

Theheap type corresponding tocurses.window.

intPyCursesWindow_Check(PyObject*op)

Return true ifop is acurses.window instance, false otherwise.

The following macros are convenience macros expanding into C statements.In particular, they can only be used asmacro; ormacro, but notmacro() ormacro();.

PyCursesSetupTermCalled

Macro checking ifcurses.setupterm() has been called.

The macro expansion is roughly equivalent to:

{typedefint(*predicate_t)(void);predicate_twas_setupterm_called=(predicate_t)PyCurses_API[1];if(!was_setupterm_called()){returnNULL;}}
PyCursesInitialised

Macro checking ifcurses.initscr() has been called.

The macro expansion is roughly equivalent to:

{typedefint(*predicate_t)(void);predicate_twas_initscr_called=(predicate_t)PyCurses_API[2];if(!was_initscr_called()){returnNULL;}}
PyCursesInitialisedColor

Macro checking ifcurses.start_color() has been called.

The macro expansion is roughly equivalent to:

{typedefint(*predicate_t)(void);predicate_twas_start_color_called=(predicate_t)PyCurses_API[3];if(!was_start_color_called()){returnNULL;}}

Internal data

The following objects are exposed by the C API but should be consideredinternal-only.

PyCurses_CAPSULE_NAME

Name of the curses capsule to pass toPyCapsule_Import().

Internal usage only. Useimport_curses instead.