An enhanced version of the tty module
The term package is an enhanced version of the standard library’s tty module. It provides context managers for temporarily switching the terminal to raw or cbreak mode and allows to retrieve the cursor position without having to resort to curses.
To resize the terminal window, we enter cbreak mode and write the new dimensions to the tty:
from term import opentty, cbreakmode with opentty() as tty: if tty is not None: with cbreakmode(tty, min=0): tty.write('\033[8;25;80t'); print 'terminal resized'
You may also want to look at the source code of getyx().
The terminal must be in canonical mode before any of the functions and context managers can be used. They are not meant for switching between e.g. raw and cbreak modes. Nesting context managers of the same type is allowed though.