@@ -4458,6 +4458,100 @@ _curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)
44584458 Py_RETURN_NONE ;
44594459}
44604460
4461+ #if _NCURSES_EXTENDED_COLOR_FUNCS
4462+ /*[clinic input]
4463+ _curses.alloc_pair
4464+
4465+ fg: color_allow_default
4466+ Foreground color number.
4467+ bg: color_allow_default
4468+ Background color number.
4469+ /
4470+
4471+ Allocate a color pair for the given foreground and background colors.
4472+
4473+ If a color pair for the same colors already exists, return its number.
4474+ Otherwise allocate a new color pair and return its number.
4475+ [clinic start generated code]*/
4476+
4477+ static PyObject *
4478+ _curses_alloc_pair_impl (PyObject * module , int fg , int bg )
4479+ /*[clinic end generated code: output=6eb08cb643d4b5a2 input=b29bafd7b360fa35]*/
4480+ {
4481+ PyCursesStatefulInitialised (module );
4482+ PyCursesStatefulInitialisedColor (module );
4483+
4484+ int pair = alloc_pair (fg , bg );
4485+ if (pair < 0 ) {
4486+ curses_set_error (module , "alloc_pair" , NULL );
4487+ return NULL ;
4488+ }
4489+ return PyLong_FromLong (pair );
4490+ }
4491+
4492+ /*[clinic input]
4493+ _curses.find_pair
4494+
4495+ fg: color_allow_default
4496+ Foreground color number.
4497+ bg: color_allow_default
4498+ Background color number.
4499+ /
4500+
4501+ Return the number of a color pair for the given colors, or -1.
4502+
4503+ Return -1 if no color pair for this combination of foreground and
4504+ background colors has been allocated.
4505+ [clinic start generated code]*/
4506+
4507+ static PyObject *
4508+ _curses_find_pair_impl (PyObject * module , int fg , int bg )
4509+ /*[clinic end generated code: output=376026c2a3ac4a9b input=930feac14892c251]*/
4510+ {
4511+ PyCursesStatefulInitialised (module );
4512+ PyCursesStatefulInitialisedColor (module );
4513+
4514+ return PyLong_FromLong (find_pair (fg , bg ));
4515+ }
4516+
4517+ /*[clinic input]
4518+ _curses.free_pair
4519+
4520+ pair: pair
4521+ The number of the color pair to free.
4522+ /
4523+
4524+ Free a color pair allocated by alloc_pair().
4525+ [clinic start generated code]*/
4526+
4527+ static PyObject *
4528+ _curses_free_pair_impl (PyObject * module , int pair )
4529+ /*[clinic end generated code: output=61be0fb2e4bb4e4a input=d24df62feb4161c6]*/
4530+ {
4531+ PyCursesStatefulInitialised (module );
4532+ PyCursesStatefulInitialisedColor (module );
4533+
4534+ return curses_check_err (module , free_pair (pair ), "free_pair" , NULL );
4535+ }
4536+
4537+ /*[clinic input]
4538+ _curses.reset_color_pairs
4539+
4540+ Discard all color-pair definitions.
4541+ [clinic start generated code]*/
4542+
4543+ static PyObject *
4544+ _curses_reset_color_pairs_impl (PyObject * module )
4545+ /*[clinic end generated code: output=117e68c6614e1d06 input=57c1cf7e5447e1ac]*/
4546+ {
4547+ PyCursesStatefulInitialised (module );
4548+ PyCursesStatefulInitialisedColor (module );
4549+
4550+ reset_color_pairs ();
4551+ Py_RETURN_NONE ;
4552+ }
4553+ #endif /* _NCURSES_EXTENDED_COLOR_FUNCS */
4554+
44614555/* Refresh the private copy of the screen encoding from a freshly created
44624556 stdscr window object. Returns 0 on success, -1 with an exception set. */
44634557static int
@@ -6241,6 +6335,7 @@ _curses_has_extended_color_support_impl(PyObject *module)
62416335/* List of functions defined in the module */
62426336
62436337static PyMethodDef cursesmodule_methods [] = {
6338+ _CURSES_ALLOC_PAIR_METHODDEF
62446339 _CURSES_BAUDRATE_METHODDEF
62456340 _CURSES_BEEP_METHODDEF
62466341 _CURSES_CAN_CHANGE_COLOR_METHODDEF
@@ -6258,8 +6353,10 @@ static PyMethodDef cursesmodule_methods[] = {
62586353 _CURSES_ERASEWCHAR_METHODDEF
62596354 _CURSES_FILTER_METHODDEF
62606355 _CURSES_NOFILTER_METHODDEF
6356+ _CURSES_FIND_PAIR_METHODDEF
62616357 _CURSES_FLASH_METHODDEF
62626358 _CURSES_FLUSHINP_METHODDEF
6359+ _CURSES_FREE_PAIR_METHODDEF
62636360 _CURSES_GETMOUSE_METHODDEF
62646361 _CURSES_UNGETMOUSE_METHODDEF
62656362 _CURSES_GETSYX_METHODDEF
@@ -6301,6 +6398,7 @@ static PyMethodDef cursesmodule_methods[] = {
63016398 _CURSES_PUTP_METHODDEF
63026399 _CURSES_QIFLUSH_METHODDEF
63036400 _CURSES_RAW_METHODDEF
6401+ _CURSES_RESET_COLOR_PAIRS_METHODDEF
63046402 _CURSES_RESET_PROG_MODE_METHODDEF
63056403 _CURSES_RESET_SHELL_MODE_METHODDEF
63066404 _CURSES_RESETTY_METHODDEF
0 commit comments