◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
9 changes: 9 additions & 0 deletions Doc/library/curses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ The module :mod:`curses` defines the following functions:

Return ``True`` if the terminal can display colors; otherwise, return ``False``.


.. function:: has_ic()

Expand Down
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ New Modules
Improved Modules
================

glob
----

Expand Down
16 changes: 15 additions & 1 deletion Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def test_module_funcs(self):
curses.nocbreak, curses.noecho, curses.nonl,
curses.noqiflush, curses.noraw,
curses.reset_prog_mode, curses.termattrs,
curses.termname, curses.erasechar]:
with self.subTest(func=func.__qualname__):
func()
if hasattr(curses, 'filter'):
Expand Down @@ -292,6 +293,19 @@ def test_colors_funcs(self):
if hasattr(curses, 'use_default_colors'):
curses.use_default_colors()

@requires_curses_func('keyname')
def test_keyname(self):
curses.keyname(13)
Expand Down
2 changes: 2 additions & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ Geert Jansen
Jack Jansen
Hans-Peter Jansen
Bill Janssen
Jon Janzen
Thomas Jarosch
Juhana Jauhiainen
Expand Down Expand Up @@ -882,6 +883,7 @@ Sam Kimbrel
Tomohiko Kinebuchi
James King
W. Trevor King
Paul Kippes
Steve Kirsch
Sebastian Kirsche
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
194 changes: 166 additions & 28 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@ typedef chtype attr_t; /* No attr_t type is available */
#define STRICT_SYSV_CURSES
#endif

/*[clinic input]
module _curses
class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"
Expand Down Expand Up @@ -387,6 +412,104 @@ PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
return 0;
}

/* Function versions of the 3 functions for testing whether curses has been
initialised or not. */

Expand Down Expand Up @@ -2585,7 +2708,7 @@ NoArgOrFlagNoReturnFunctionBody(cbreak, flag)
/*[clinic input]
_curses.color_content

color_number: short
The number of the color (0 - COLORS).
/

Expand All @@ -2596,15 +2719,15 @@ which will be between 0 (no component) and 1000 (maximum amount of component).
[clinic start generated code]*/

static PyObject *
_curses_color_content_impl(PyObject *module, short color_number)
/*[clinic end generated code: output=cb15cf3120d4bfc1 input=5555abb1c11e11b7]*/
{
short r,g,b;

PyCursesInitialised;
PyCursesInitialisedColor;

if (color_content(color_number, &r, &g, &b) != ERR)
return Py_BuildValue("(iii)", r, g, b);
else {
PyErr_SetString(PyCursesError,
Expand All @@ -2616,7 +2739,7 @@ _curses_color_content_impl(PyObject *module, short color_number)
/*[clinic input]
_curses.color_pair

color_number: short
The number of the color (0 - COLORS).
/

Expand All @@ -2627,8 +2750,8 @@ other A_* attributes. pair_number() is the counterpart to this function.
[clinic start generated code]*/

static PyObject *
_curses_color_pair_impl(PyObject *module, short color_number)
/*[clinic end generated code: output=6a84cb6b29ecaf9a input=a9d3eb6f50e4dc12]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;
Expand Down Expand Up @@ -3027,13 +3150,13 @@ _curses_has_key_impl(PyObject *module, int key)
/*[clinic input]
_curses.init_color

color_number: short
The number of the color to be changed (0 - COLORS).
r: short
Red component (0 - 1000).
g: short
Green component (0 - 1000).
b: short
Blue component (0 - 1000).
/

@@ -3045,24 +3168,24 @@ most terminals; it is active only if can_change_color() returns 1.
[clinic start generated code]*/

static PyObject *
_curses_init_color_impl(PyObject *module, short color_number, short r,
short g, short b)
/*[clinic end generated code: output=280236f5efe9776a input=f3a05bd38f619175]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;

return PyCursesCheckERR(init_color(color_number, r, g, b), "init_color");
}

/*[clinic input]
_curses.init_pair

pair_number: short
The number of the color-pair to be changed (1 - (COLOR_PAIRS-1)).
fg: short
Foreground color number (0 - COLORS).
bg: short
Background color number (0 - COLORS).
/

Expand All @@ -3073,14 +3196,13 @@ all occurrences of that color-pair are changed to the new definition.
[clinic start generated code]*/

static PyObject *
_curses_init_pair_impl(PyObject *module, short pair_number, short fg,
short bg)
/*[clinic end generated code: output=9c2ce39c22f376b6 input=c9f0b11b17a2ac6d]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;

return PyCursesCheckERR(init_pair(pair_number, fg, bg), "init_pair");
}

static PyObject *ModDict;
Expand Down @@ -3697,23 +3819,23 @@ NoArgNoReturnFunctionBody(noraw)
/*[clinic input]
_curses.pair_content

pair_number: short
The number of the color pair (1 - (COLOR_PAIRS-1)).
/

Return a tuple (fg, bg) containing the colors for the requested color pair.
[clinic start generated code]*/

static PyObject *
_curses_pair_content_impl(PyObject *module, short pair_number)
/*[clinic end generated code: output=5a72aa1a28bbacf3 input=f4d7fec5643b976b]*/
{
short f, b;

PyCursesInitialised;
PyCursesInitialisedColor;

if (pair_content(pair_number, &f, &b)==ERR) {
PyErr_SetString(PyCursesError,
"Argument 1 was out of range. (1..COLOR_PAIRS-1)");
return NULL;
Expand Up @@ -4450,6 +4572,21 @@ make_ncurses_version(void)

#endif /* NCURSES_VERSION */


/* List of functions defined in the module */

@@ -4476,6 +4613,7 @@ static PyMethodDef PyCurses_methods[] = {
_CURSES_GETSYX_METHODDEF
_CURSES_GETWIN_METHODDEF
_CURSES_HAS_COLORS_METHODDEF
_CURSES_HAS_IC_METHODDEF
_CURSES_HAS_IL_METHODDEF
_CURSES_HAS_KEY_METHODDEF
Expand Down
Loading
Toggle all file notes Toggle all file annotations