How to use terminal color palette with curses

后端 未结 6 1706
名媛妹妹
名媛妹妹 2021-01-30 13:45

I can\'t get the terminal color palette to work with curses.

import curses

def main(stdscr):
    curses.use_default_colors()
    for i in range(0,7):
        st         


        
6条回答
  •  -上瘾入骨i
    2021-01-30 14:24

    I don't have the rep-points to submit this as a comment to Chiel ten Brinke's excellent answer, so I'll offer here a more useful version of his color script:

    import curses
    def main(stdscr):
        curses.start_color()
        curses.use_default_colors()
        for i in range(0, curses.COLORS):
            curses.init_pair(i + 1, i, -1)
        stdscr.addstr(0, 0, '{0} colors available'.format(curses.COLORS))
        maxy, maxx = stdscr.getmaxyx()
        maxx = maxx - maxx % 5
        x = 0
        y = 1
        try:
            for i in range(0, curses.COLORS):
                stdscr.addstr(y, x, '{0:5}'.format(i), curses.color_pair(i))
                x = (x + 5) % maxx
                if x == 0:
                    y += 1
        except curses.ERR:
            pass
        stdscr.getch()
    curses.wrapper(main)
    

提交回复
热议问题