Reputation: 10685
How can I get the status of the terminal from a Python program? I want the program to stop printing lines to the screen when the screen is full and wait for user input.
Upvotes: 2
Views: 296
Reputation: 17312
If you need more control over the terminal window, and assuming you're on Linux/*BSD/MacOSX, then you will need to use curses for that. This is just a simple example:
import curses
stdscr = curses.initscr()
stdscr.getmaxyx() #returns the width and height of the terminal screen
stdscr.getyx() #returns the current x,y position.
You should check the library reference for more functions.
Upvotes: 2
Reputation: 36514
The simplest (no code) way to accomplish that is to pipe your program's output through a pager program like less
or more
(assuming *nix), like:
import random
while 1:
print random.randint(0, 0xffffffff)
python infinty.py | less
...gives output like:
848605718
899092472
2576425641
3098821373
259379057
164782822
416064876
2488878735
1216764788
2682214542
531576871
2175787865
869960770
:
...and waits for user input.
Upvotes: 5