Curses: Character in bottom right corner
Michael P. Reilly
arcege at shore.net
Thu Nov 4 16:06:14 EST 1999
Gerrit Holl <gerrit.holl at pobox.com> wrote:
: Hello,
: can someone explain me why the following doesn't work:
: --- *** ---
: #!/usr/bin/python
: import curses
: def main(stdscr):
: maxy, maxx = stdscr.getmaxyx()
: stdscr.addstr(maxy-1, maxx-1, "s", curses.A_NORMAL)
: stdscr.refresh()
: if __name__ == '__main__':
: import curses, traceback
: try:
: stdscr=curses.initscr()
: curses.noecho()
: curses.cbreak()
: stdscr.keypad(1)
: main(stdscr) # Enter the main loop
: stdscr.keypad(0)
: curses.echo()
: curses.nocbreak()
: curses.endwin() # Terminate curses
: except:
: stdscr.keypad(0)
: curses.echo() ; curses.nocbreak()
: curses.endwin()
: traceback.print_exc() # Print the exception
: --- *** ---
: I'm getting this error:
: 17:05:23:192/693:gerrit at gerrit:~/oefen/python/ncurses$ python test.py
: Traceback (innermost last):
: File "test.py", line 18, in ?
: main(stdscr) # Enter the main loop
: File "test.py", line 7, in main
: stdscr.addstr(maxy-1, maxx-1, "s", curses.A_NORMAL)
: error: [mv]waddstr() returned ERR
: It seems that he thinks it falls of the screen, but if I make either x or
: y smaller (not both!) it does work, so if I change line 7 to something like
: follows, it works.
: stdscr.addstr(maxy-2, maxx-1, "s", curses.A_NORMAL)
: stdscr.addstr(maxy-1, maxx-2, "s", curses.A_NORMAL)
: What am I doing wrong?
You aren't really doing anything wrong. It's just that curses doesn't
let you write to the last character on the screen for historical (and
in some cases, practical) purposes. On many terminals, writing to the
last character (right-most, bottom-most) causes the terminal itself to
scroll, corrupting what curses has written and what it thinks is being
displayed. So even on terminals that allow positioning a character
there, curses will not allow it.
Try setting stdscr.scrollok(0) before doing anything else.
Wishing-he-knew-where-his-curses-book-was-ly yours,
-Arcege
More information about the Python-list
mailing list