curses bkgd problem

Lee Harr missive at frontiernet.net
Tue Mar 9 23:08:19 CET 2004


On 2004-03-09, Gandalf <gandalf at geochemsource.com> wrote:
>
>
> Gandalf wrote:
>
>> stdscr = curses.initscr() # Get standard screen
>> curses.start_color()      # Uses colors
>> stdscr.bkgd(' ',curses.COLOR_BLUE ) # Set background of the main window
>> curses.noecho()           # Do not echo input
>> curses.cbreak()           # CBreak mode: process keys immediately (no 
>> ENTER)
>> stdscr.keypad(1)          # keypad mode: parse control sequences
>> stdscr.redrawwin()
>> stdscr.refresh()
>>
>> However, it is displaying $ characters in black instead of displaying 
>> a blue background full of spaces.
>> This must be a problem with my bkgd call since this works fine:
>>
>> curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
>> stdscr.addstr(0, 0, curses.longname(), curses.color_pair(1) )
>> stdscr.refresh()
>>
> Now I'm doing this:
>
> def clrscr():
>     global stdscr
>     (maxy,maxx) = stdscr.getmaxyx()
>     line = ' ' * (maxx-1)
>     for row in range(maxy):
>         stdscr.addstr(row, 0, line, curses.color_pair(1) )
>
> which works fine except that the right side of the screen is still black.
> It is a very clumsy solution. Any ideas?
>
>   G
>


Here is a way that lets you fill in that right column ...


import curses

def main(scr):
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
    clear2(scr, 1)
    c = scr.getch()
        
def clear(scr, pair):
    (maxy,maxx) = scr.getmaxyx()
    line = ' ' * (maxx-1)
    for row in range(maxy):
        scr.addstr(row, 0, line, curses.color_pair(pair) )
    
def clear2(scr, pair):
    scr.attron(curses.color_pair(pair))
    (h, w) = scr.getmaxyx()
    for y in range(h-1):
        for x in range(w):
            scr.move(y, x)
            scr.addch(' ')

def clear3(scr, pair):
    scr.attron(curses.color_pair(pair))
    scr.box()
    (h, w) = scr.getmaxyx()
    for y in range(1, h-1):
        for x in range(1, w-1):
            scr.move(y, x)
            scr.addch(' ')

curses.wrapper(main)



My own project does not use it like this (with the width going all the
way up to maxy) so there may have been other problems associated...

The way I do it is to use scr.box() like here in clear3()

If you don't want the line around the box, I think you can redefine
the characters used to draw the box.




More information about the Python-list mailing list