[issue13609] Add "os.get_terminal_size()" function

Zbyszek Szmek report at bugs.python.org
Mon Jan 30 18:00:32 CET 2012


Zbyszek Szmek <zbyszek at in.waw.pl> added the comment:

Here's is an updated version: termsize.diff.6

Following Antoine Pitrou's comment get_terminal_size_raw is renamed back to query_terminal_size.

Tests are moved to test_os.py, and there's a new test for query_terminal_size -- the output from 'stty size' is parsed. If something fails (e.g. stty is not available), the test is skipped.

I noticed that bash uses $LINES, not $ROWS. I have renamed rows to lines everywhere, to follow existing convention.

The big remaining question seems to be one function vs. two functions.
I'm still convinced that the high-level two function is better. This issue originated in the argparse module, which can use proper terminal size to efficiently format messages. Of course argparse must use a function with a fallback -- if it cannot query, some default must be used. So argparse would implement the high-level function anyway. It might just as well be in os, available for others to be used. Anyway, the second function is 18 lines of python code (excluding docstring and whitespace) -- a bit too much to copy and paste.

----------
Added file: http://bugs.python.org/file24369/termsize.diff.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13609>
_______________________________________


More information about the Python-bugs-list mailing list