0

I tried to print colorful output using python3 curses:

#!/usr/bin/env python3

import curses

def main(stdscr):
    curses.start_color()
    curses.use_default_colors()
    # 0 is always black
    for i in range(0, curses.COLORS):
        curses.init_pair(i + 1, i, -1)

    for i in range(1, curses.COLORS + 1):
        stdscr.addstr("A", curses.color_pair(i))
    stdscr.addch("\n")
    for i in range(1, curses.COLORS + 1):
        stdscr.addch("A", curses.color_pair(i))
    stdscr.addch("\n")
    stdscr.addstr(str(curses.COLORS))
    stdscr.refresh()
    stdscr.getch()

curses.wrapper(main)

However, the output on my system(urxvt), only the first line is colorful(printed using addstr), the second line is white.

How to fix this?

JiaHao Xu
  • 2,452
  • 16
  • 31
  • Lots of possibilities. Here's one: the terminal description uses a different number of colors (such as 16 or 256) than the terminal actually supports (88 or 256, etc). – Thomas Dickey Mar 29 '19 at 00:45
  • Can you please show me the code that does this in the answer? – JiaHao Xu Mar 29 '19 at 03:21

0 Answers0