2

I'm pretty new to curses but I wrote a working little curses application. But after a while I noticed that my default terminal settings were changed during the session. The background color is a solid black, but I've configured a transparent terminal. Also the color looks more like white than grey.

My code, but I'm sure it's not related to the problem. I'm using debian wheezy with python 2.7.2

#!/usr/bin/env python

import curses

class Monitor:
    def __init__(self, screen):
        self.screen = screen
        self.height, self.width = self.screen.getmaxyx()
        self.screen.nodelay(1)

    def redraw(self):
        self.screen.clear()
        self.screen.addstr(1, 1, 'hai')
        self.screen.refresh()

    def main(self):
        while 1:
            key = self.screen.getch()
            if key == ord('q'): break
            self.redraw()

def main(stdscr):
    mon = Monitor(stdscr)
    mon.main()

if __name__ == '__main__':
    try:
        curses.wrapper(main)
    except KeyboardInterrupt:
        pass
4

1 に答える 1

11

以前から探していたので、これに答えるべきだと思いました。

ではmain()、追加する必要があります

curses.use_default_colors()

これにより、curses が上書きする代わりに端末の色が使用されます。これは、背景色が設定されていない場合、背景色が透明になることを意味します。

後で、たとえば代わり​​に透明な背景を持つ色のペアを作成する場合

curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)

使用する

curses.init_pair(1, curses.WHITE, -1)

これにより、デフォルトの背景、つまり透明が使用されます。

于 2012-05-28T15:05:33.560 に答える