gh-133139: Add curses.assume_default_colors() (GH-133145)
This is a refinement of the curses.use_default_colors() function which allows to change the color pair 0.
This commit is contained in:
@@ -4720,15 +4720,12 @@ _curses_use_env_impl(PyObject *module, int flag)
|
||||
/*[clinic input]
|
||||
_curses.use_default_colors
|
||||
|
||||
Allow use of default values for colors on terminals supporting this feature.
|
||||
|
||||
Use this to support transparency in your application. The default color
|
||||
is assigned to the color number -1.
|
||||
Equivalent to assume_default_colors(-1, -1).
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_curses_use_default_colors_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=a3b81ff71dd901be input=656844367470e8fc]*/
|
||||
/*[clinic end generated code: output=a3b81ff71dd901be input=99ff0b7c69834d1f]*/
|
||||
{
|
||||
int code;
|
||||
|
||||
@@ -4744,6 +4741,39 @@ _curses_use_default_colors_impl(PyObject *module)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_curses.assume_default_colors
|
||||
fg: int
|
||||
bg: int
|
||||
/
|
||||
|
||||
Allow use of default values for colors on terminals supporting this feature.
|
||||
|
||||
Assign terminal default foreground/background colors to color number -1.
|
||||
Change the definition of the color-pair 0 to (fg, bg).
|
||||
|
||||
Use this to support transparency in your application.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_curses_assume_default_colors_impl(PyObject *module, int fg, int bg)
|
||||
/*[clinic end generated code: output=54985397a7d2b3a5 input=7fe301712ef3e9fb]*/
|
||||
{
|
||||
int code;
|
||||
|
||||
PyCursesStatefulInitialised(module);
|
||||
PyCursesStatefulInitialisedColor(module);
|
||||
|
||||
code = assume_default_colors(fg, bg);
|
||||
if (code != ERR) {
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
cursesmodule_state *state = get_cursesmodule_state(module);
|
||||
PyErr_SetString(state->error, "assume_default_colors() returned ERR");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif /* STRICT_SYSV_CURSES */
|
||||
|
||||
|
||||
@@ -4902,6 +4932,7 @@ static PyMethodDef cursesmodule_methods[] = {
|
||||
_CURSES_UNGET_WCH_METHODDEF
|
||||
_CURSES_USE_ENV_METHODDEF
|
||||
_CURSES_USE_DEFAULT_COLORS_METHODDEF
|
||||
_CURSES_ASSUME_DEFAULT_COLORS_METHODDEF
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user