Is shutil.get_terminal_size useless?
grant.b.edwards at gmail.com
Sat Jan 28 12:53:11 EST 2017
On 2017-01-28, Steve D'Aprano <steve+python at pearwood.info> wrote:
> On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote:
>> On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano
>> <steve+python at pearwood.info> wrote:
>>> The terminal size doesn't change just because I'm piping output to
>>> another process. Using the terminal size as a proxy for "being piped" is
>>> sheer insanity.
>> In a sense, there _is no_ terminal size when you're being piped to
>> another process.
> In which sense, and why do you think it is relevant?
> There clearly is a terminal, because that's where I'm running the
> code. Regardless of whether I pipe it to grep or cat or something
> else, the output from *that* process still ends up in the same
> terminal that I typed the command in.
I'm sorry, it's not at all obvious to me (or, apparently to the author
of shutil.get_terminal_size) that the output is going to end up in the
terminal where you typed the command. The output might just as easily
end up in a file or in a completely different terminal (possibly on a
> I acknowledge that there are cases where there is no terminal.
And cases where there is a different terminal entirely.
To me, the current behavior of shutil.get_terminal_size seems to be
the most useful.
More information about the Python-list