@@ -3825,6 +3825,100 @@ _curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)
38253825 Py_RETURN_NONE ;
38263826}
38273827
3828+ #if _NCURSES_EXTENDED_COLOR_FUNCS
3829+ /*[clinic input]
3830+ _curses.alloc_pair
3831+
3832+ fg: color_allow_default
3833+ Foreground color number.
3834+ bg: color_allow_default
3835+ Background color number.
3836+ /
3837+
3838+ Allocate a color pair for the given foreground and background colors.
3839+
3840+ If a color pair for the same colors already exists, return its number.
3841+ Otherwise allocate a new color pair and return its number.
3842+ [clinic start generated code]*/
3843+
3844+ static PyObject *
3845+ _curses_alloc_pair_impl (PyObject * module , int fg , int bg )
3846+ /*[clinic end generated code: output=6eb08cb643d4b5a2 input=b29bafd7b360fa35]*/
3847+ {
3848+ PyCursesStatefulInitialised (module );
3849+ PyCursesStatefulInitialisedColor (module );
3850+
3851+ int pair = alloc_pair (fg , bg );
3852+ if (pair < 0 ) {
3853+ curses_set_error (module , "alloc_pair" , NULL );
3854+ return NULL ;
3855+ }
3856+ return PyLong_FromLong (pair );
3857+ }
3858+
3859+ /*[clinic input]
3860+ _curses.find_pair
3861+
3862+ fg: color_allow_default
3863+ Foreground color number.
3864+ bg: color_allow_default
3865+ Background color number.
3866+ /
3867+
3868+ Return the number of a color pair for the given colors, or -1.
3869+
3870+ Return -1 if no color pair for this combination of foreground and
3871+ background colors has been allocated.
3872+ [clinic start generated code]*/
3873+
3874+ static PyObject *
3875+ _curses_find_pair_impl (PyObject * module , int fg , int bg )
3876+ /*[clinic end generated code: output=376026c2a3ac4a9b input=930feac14892c251]*/
3877+ {
3878+ PyCursesStatefulInitialised (module );
3879+ PyCursesStatefulInitialisedColor (module );
3880+
3881+ return PyLong_FromLong (find_pair (fg , bg ));
3882+ }
3883+
3884+ /*[clinic input]
3885+ _curses.free_pair
3886+
3887+ pair: pair
3888+ The number of the color pair to free.
3889+ /
3890+
3891+ Free a color pair allocated by alloc_pair().
3892+ [clinic start generated code]*/
3893+
3894+ static PyObject *
3895+ _curses_free_pair_impl (PyObject * module , int pair )
3896+ /*[clinic end generated code: output=61be0fb2e4bb4e4a input=d24df62feb4161c6]*/
3897+ {
3898+ PyCursesStatefulInitialised (module );
3899+ PyCursesStatefulInitialisedColor (module );
3900+
3901+ return curses_check_err (module , free_pair (pair ), "free_pair" , NULL );
3902+ }
3903+
3904+ /*[clinic input]
3905+ _curses.reset_color_pairs
3906+
3907+ Discard all color-pair definitions.
3908+ [clinic start generated code]*/
3909+
3910+ static PyObject *
3911+ _curses_reset_color_pairs_impl (PyObject * module )
3912+ /*[clinic end generated code: output=117e68c6614e1d06 input=57c1cf7e5447e1ac]*/
3913+ {
3914+ PyCursesStatefulInitialised (module );
3915+ PyCursesStatefulInitialisedColor (module );
3916+
3917+ reset_color_pairs ();
3918+ Py_RETURN_NONE ;
3919+ }
3920+ #endif /* _NCURSES_EXTENDED_COLOR_FUNCS */
3921+
38283922/* Refresh the private copy of the screen encoding from a freshly created
38293923 stdscr window object. Returns 0 on success, -1 with an exception set. */
38303924static int
@@ -5328,6 +5422,7 @@ _curses_has_extended_color_support_impl(PyObject *module)
53285422/* List of functions defined in the module */
53295423
53305424static PyMethodDef cursesmodule_methods [] = {
5425+ _CURSES_ALLOC_PAIR_METHODDEF
53315426 _CURSES_BAUDRATE_METHODDEF
53325427 _CURSES_BEEP_METHODDEF
53335428 _CURSES_CAN_CHANGE_COLOR_METHODDEF
@@ -5344,8 +5439,10 @@ static PyMethodDef cursesmodule_methods[] = {
53445439 _CURSES_ERASECHAR_METHODDEF
53455440 _CURSES_FILTER_METHODDEF
53465441 _CURSES_NOFILTER_METHODDEF
5442+ _CURSES_FIND_PAIR_METHODDEF
53475443 _CURSES_FLASH_METHODDEF
53485444 _CURSES_FLUSHINP_METHODDEF
5445+ _CURSES_FREE_PAIR_METHODDEF
53495446 _CURSES_GETMOUSE_METHODDEF
53505447 _CURSES_UNGETMOUSE_METHODDEF
53515448 _CURSES_GETSYX_METHODDEF
@@ -5382,6 +5479,7 @@ static PyMethodDef cursesmodule_methods[] = {
53825479 _CURSES_PUTP_METHODDEF
53835480 _CURSES_QIFLUSH_METHODDEF
53845481 _CURSES_RAW_METHODDEF
5482+ _CURSES_RESET_COLOR_PAIRS_METHODDEF
53855483 _CURSES_RESET_PROG_MODE_METHODDEF
53865484 _CURSES_RESET_SHELL_MODE_METHODDEF
53875485 _CURSES_RESETTY_METHODDEF
0 commit comments