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

Zbyszek Szmek report at bugs.python.org
Tue Jan 31 00:25:45 CET 2012


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

Updated version following comments by Victor Stinner: termsize.diff.7

- os.get_terminal_size() is moved to shutil.get_terminal_size()
- some small doc updates

Victor STINNER wrote:
>> I noticed that bash uses $LINES, not $ROWS. I have renamed rows to
>> lines everywhere, to follow existing convention.
> The stty program has "rows" and "columns" commands to set the terminal
Yes, also struct winsize uses 'rows' and 'cols'. But since we use the variable $LINES, it seems better to use 'lines'.

Thanks for the link to SUSv2! I've added a link in the docs, since it adds a nice justification to the COLUMNS/query/fallback behaviour.

Now get_terminal_size() lives in shutil. I don't think it matters much, but I see the point of keeping os clean.

I also looked at some programs, to see who behaves how.
dpkg -> COLUMNS first
aptitude -> ignores COLUMNS
git -> COLUMNS first
systemctl, loginctl, systemd-cgls (systemd cmdline interface) -> COLUMNS first
less, w ->  ioctl, COLUMNS as fallback

(Of course this is very unscientific, because I just picked some programs at random which I remembered to care about the terminal size).
I guess that the case of 'less' is special, because less is very
much dependent on the terminal and does quite a lot of manipulations on it. Otherwise, taking COLUMNS as highest priority seems well established, even if not universal.

----------
Added file: http://bugs.python.org/file24373/termsize.diff.7

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


More information about the Python-bugs-list mailing list