window.inch(0,0)
will return a value from reading the character at position (0,0) of the window that includes the attributes at that location. If you use stdscr
as the window you should get the current colors for the whole screen. Quoting the official documentation:
"Return the character at the given position in the window. The bottom 8 bits are the character proper, and upper bits are the attributes."
colors = stdscr.inch(0,0) & curses.A_COLOR
should extract the current colors for both foreground and background. Separating the foreground and background colors is something I am currently trying to figure out myself but haven't had much luck yet. On a Windows machine the curses implementation is PDCurses, and the source code for PDCurses seems to say that the two colors are combined in the leftmost byte of a 4-byte integer field, but I haven't confirmed that yet.
There is also window.getbkgd()
which the documentation says will:
"Return the given window’s current background character/attribute pair."
which is more than a little vague. I am working on nailing down exactly what that function actually returns, though it sounds a lot like the value returned from the inch
function.
HTH
Peter
[Edit] This sequence of curses calls reliably gives you the foreground and background color numbers. On *ix systems the defaults are fg=-1 and bg=-1 (-1 means "default" to the init_color() function) but on windows (python 3.8+, windows-curses 2.2.0) the default values are fg=7 (COLOR_WHITE) and bg=0 (COLOR_BLACK).
attr = stdscr.getbkgd()
stdscr.addstr("scrbkgd={:08X}={}\n".format(attr, attr))
pair = curses.pair_number(attr)
if platform.system() == "Windows":
pair = pair >> 16
fg, bg = curses.pair_content (pair)
stdscr.addstr("color(scrbkgd) fg={:08X}={},bg={:08X}={}\n".format(fg, fg, bg, bg))
stdscr.getch()