What's the correct way to print a line to the bottom of a terminal window that can handle resizing?
import curses
from curses import wrapper
def main(stdscr):
inp = 0
y,x = stdscr.getmaxyx()
stdscr.clear()
stdscr.nodelay(1)
while inp != 48 and inp != 27:
stdscr.addnstr(y-1,0, 'I AM KILL TERMINAL WHEN RESIZE AAAAAAAH', x)
inp = stdscr.getch()
wrapper(main)
Once I resize the terminal to less columns then the length of the string it tries to wrap onto the next line and errors out. I can't see anything in the documentation about disabling wrapping.
I've tried to update my max y,x values before the addstr function.
while inp != 48 and inp != 27:
if (y,x) != stdscr.getmaxyx():
y,x = stdscr.getmaxyx()
stdscr.addnstr(y-1,0, 'I AM KILL TERMINAL WHEN RESIZE AAAAAAAH', x)
inp = stdscr.getch()
I've also tried capturing SIGWINCH
while inp != 48 and inp != 27:
def resize_handler(signum, frame):
stdscr.erase()
stdscr.refresh()
termsize = shutil.get_terminal_size()
curses.resizeterm(termsize[1],termsize[0])
y,x = stdscr.getmaxyx()
signal.signal(signal.SIGWINCH, resize_handler)
stdscr.addnstr(y-1,0, 'I AM KILL TERMINAL WHEN RESIZE AAAAAAAH', x)
inp = stdscr.getch()
But neither of these seem to capture the terminal update early enough.