Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69f31eb

Browse files
committed
[Patch #739124] Add use_default_colors() to curses module
1 parent a54b92b commit 69f31eb

6 files changed

Lines changed: 44 additions & 3 deletions

File tree

Doc/lib/libcurses.tex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,15 @@ \subsection{Functions \label{curses-functions}}
537537
size if \envvar{LINES} and \envvar{COLUMNS} are not set).
538538
\end{funcdesc}
539539

540+
\begin{funcdesc}{use_default_colors}{}
541+
Allow use of default values for colors on terminals supporting this
542+
feature. Use this to support transparency in your
543+
application. The default color is assigned to the color number -1.
544+
After calling this function,
545+
\function{init_pair(x, curses.COLOR_RED, -1)} initializes, for instance,
546+
color pair \var{x} to a red foreground color on the default background.
547+
\end{funcdesc}
548+
540549
\subsection{Window Objects \label{curses-window-objects}}
541550

542551
Window objects, as returned by \function{initscr()} and

Doc/whatsnew/whatsnew24.tex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ \section{New, Improved, and Deprecated Modules}
6969

7070
\begin{itemize}
7171

72-
\item Descriptions go here.
73-
72+
\item The \module{curses} modules now supports the ncurses extension
73+
\function{use_default_colors()}. On platforms where the terminal
74+
supports transparency, this makes it possible to use a transparent background.
75+
(Contributed by J\"org Lehmann.)
76+
7477
\end{itemize}
7578

7679

Lib/test/test_curses.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ def module_funcs(stdscr):
181181
curses.pair_content(curses.COLOR_PAIRS)
182182
curses.pair_number(0)
183183

184+
if hasattr(curses, 'use_default_colors'):
185+
curses.use_default_colors()
186+
184187
if hasattr(curses, 'keyname'):
185188
curses.keyname(13)
186189

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ Inyeol Lee
325325
John J. Lee
326326
Luc Lefebvre
327327
Kip Lehman
328+
Joerg Lehmann
328329
Marc-Andre Lemburg
329330
William Lewis
330331
Robert van Liere

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Extension modules
2222

2323
- The signal module now exposes SIGRTMIN and SIGRTMAX (if available).
2424

25+
- curses module now supports use_default_colors(). [patch #739124]
26+
2527
Library
2628
-------
2729

Modules/_cursesmodule.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ unsupported functions:
4747
resizeterm restartterm ripoffline scr_dump
4848
scr_init scr_restore scr_set scrl set_curterm set_term setterm
4949
tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
50-
use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
50+
vidattr vidputs waddchnstr waddchstr wchgat
5151
wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
5252
5353
Low-priority:
@@ -2354,6 +2354,26 @@ PyCurses_Use_Env(PyObject *self, PyObject *args)
23542354
return Py_None;
23552355
}
23562356

2357+
#ifndef STRICT_SYSV_CURSES
2358+
static PyObject *
2359+
PyCurses_Use_Default_Colors(PyObject *self)
2360+
{
2361+
int code;
2362+
2363+
PyCursesInitialised
2364+
PyCursesInitialisedColor
2365+
2366+
code = use_default_colors();
2367+
if (code != ERR) {
2368+
Py_INCREF(Py_None);
2369+
return Py_None;
2370+
} else {
2371+
PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
2372+
return NULL;
2373+
}
2374+
}
2375+
#endif /* STRICT_SYSV_CURSES */
2376+
23572377
/* List of functions defined in the module */
23582378

23592379
static PyMethodDef PyCurses_methods[] = {
@@ -2434,6 +2454,9 @@ static PyMethodDef PyCurses_methods[] = {
24342454
{"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
24352455
{"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
24362456
{"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
2457+
#ifndef STRICT_SYSV_CURSES
2458+
{"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
2459+
#endif
24372460
{NULL, NULL} /* sentinel */
24382461
};
24392462

0 commit comments

Comments
 (0)