get the terminal's size
Cameron Simpson
cs at cskk.id.au
Tue Jan 15 07:01:16 EST 2019
On 15Jan2019 10:26, Alex Ternaute <alex at lussinan.invalid> wrote:
>> My cs.tty module (on PyPI) has a ttysize function:
>> https://pypi.org/project/cs.tty/
>> which just parses the output of the stty command.
[...]
>Fine, indeed ! I've installed cs.ttyy.
>
>I just don't understand the reason why it takes "fd" as an argument.
"fd" may be a file descriptor or a file (from which it gets the
underlying fd).
>I tried : P = Popen(['stty', '-a'], stdout=subprocess.PIPE,
>universal_newlines=True) and it runs fine too, so the output seems not
>really related to that fd.
But it is! stty(1) fetches the terminal settings from its standard
input, so "fd" is used to supply this. In your Popen test case you
simply don't set the stdin parameter, so it is the Python process'
input. Which is usually what you want. But I want to be able to ask this
of any terminal file, thus the parameter.
Just pass 0 to ttysize, or sys.stdin. Arguably that should be a default
value.
>Btw I did not know about namedtuple, thanks for that too.
Yes, it is very handy.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list