0

I'm trying to make an interface in Curses in Python, but I was wondering how could I make it more portable when the window's terminal increases while the script is being executed.

For example, this code in a window (height:80,width:24):

#!/usr/bin/python

import curses
import time
stdscr = curses.initscr()
curses.cbreak()
curses.noecho()
stdscr.keypad(1)

try:
# Run your code here
    height,width = stdscr.getmaxyx()
    num = min(height,width)
    for x in range(num):
        stdscr.addch(x,x,'X')
    stdscr.refresh()
    time.sleep(3)
finally:
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()

would work and would be portable with any window (it would print many 'X' chars for the entire window's size), but if I resize it in a second time during its execution it wouldn't work and it would be empty for some parts of the terminal.

How can I make it work the way I want?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105

1 Answers1

0

You'd have to handle SIGWINCH (using ncurses) by calling getch, which will return KEY_RESIZE when ncurses gets interrupted by SIGWINCH.

Further reading:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105