Re: get the terminal's size

2019-01-16 Thread Akkana Peck
> On Mon, 14 Jan 2019 11:57:33 +, Alex Ternaute wrote: > > > Hi there, > > > > I want to know the number of columns of the terminal where python2 writes > > it's outputs. A couple days late to the party, a discussion of several ways I tried:

Re: get the terminal's size

2019-01-16 Thread Wildman via Python-list
On Mon, 14 Jan 2019 11:57:33 +, Alex Ternaute wrote: > Hi there, > > I want to know the number of columns of the terminal where python2 writes > it's outputs. > > In a terminal, I type > $ echo $COLUMNS > 100 > > But in Python, os.getenv("COLUMNS") gets nothing. > It gets nothing as well

Re: get the terminal's size

2019-01-16 Thread Grant Edwards
On 2019-01-16, Karen Shaeffer wrote: [fixed quoting and formatting] >> That will tell you the terminal size at the time Python was started. >> >> If the terminal size has changed while Python was running, those >> environment variables will be wrong. You need to use the TIOCGWINSZ >> ioctl

Re: get the terminal's size

2019-01-15 Thread Karen Shaeffer
That will tell you the terminal size at the time Python was started. If the terminal size has changed while Python was running, those environment variables will be wrong. You need to use the TIOCGWINSZ ioctl call: http://www.delorie.com/djgpp/doc/libc/libc_495.html And to detect the

Re: get the terminal's size

2019-01-15 Thread Cameron Simpson
On 15Jan2019 13:08, Alex Ternaute wrote: 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

Re: get the terminal's size

2019-01-15 Thread Alex Ternaute
Hi Cameron, >>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

Re: get the terminal's size

2019-01-15 Thread Cameron Simpson
On 15Jan2019 10:26, Alex Ternaute 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.

Re: get the terminal's size

2019-01-15 Thread Alex Ternaute
Hi thereĀ : > On 2019-01-14, Bob van der Poel wrote: >> http://stackoverflow.com/questions/566746/how-to-get-console-window- width-in-python Simple and direct, I think I'll use this one. Thanks a lot. John Doe : > and have a look at this one too: >

Re: get the terminal's size

2019-01-15 Thread Alex Ternaute
Hi Cameron, > 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. > If you don't want the cs.tty module, the ttysize code is just this: > > WinSize = namedtuple('WinSize', 'rows columns') > > def

Re: get the terminal's size

2019-01-14 Thread eryk sun
On 1/14/19, Schachner, Joseph wrote: > I just tested the fix I proposed, in Python 2.7.13 > > Code: > from win32api import GetSystemMetrics > > def main(): > print "Width =", GetSystemMetrics(0) > print "Height =", GetSystemMetrics(1) That gets the monitor size, i.e: SM_CXSCREEN (0)

Re: get the terminal's size

2019-01-14 Thread John Doe
On 2019-01-14, Bob van der Poel wrote: > try this: > > > http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python > and have a look at this one too: https://stackoverflow.com/questions/1396820/apt-like-column-output-python-library/1446973#1446973 > --

Re: get the terminal's size

2019-01-14 Thread Cameron Simpson
On 14Jan2019 17:16, Alex Ternaute wrote: Looking on the internet for a hint, I see that python3 has an os.get_terminal_size(). Use that then. Up to now I wanted to keep compatibility with a big bunch of code in Python2 that I do no maintain by myself. Well, I saw that get_terminal_size()

Re: get the terminal's size

2019-01-14 Thread Bob van der Poel
On Mon, Jan 14, 2019 at 4:57 AM Alex Ternaute wrote: > Hi there, > > I want to know the number of columns of the terminal where python2 writes > it's outputs. > > In a terminal, I type > $ echo $COLUMNS > 100 > > But in Python, os.getenv("COLUMNS") gets nothing. > It gets nothing as well if I

RE: get the terminal's size

2019-01-14 Thread Schachner, Joseph
al Message- From: Alex Ternaute Sent: Monday, January 14, 2019 6:58 AM To: python-list@python.org Subject: get the terminal's size Hi there, I want to know the number of columns of the terminal where python2 writes it's outputs. In a terminal, I type $ echo $COLUMNS 100 But in Python

Re: get the terminal's size

2019-01-14 Thread Grant Edwards
On 2019-01-14, Schachner, Joseph wrote: > Note sure why you couldn't capture $ echo $COLUMNS from a subprocess > call. You can. But, the subprocess is going to inherit the value from the Python program's environment, so it's just pointless complexity. -- Grant Edwards

RE: get the terminal's size

2019-01-14 Thread Schachner, Joseph
naute Sent: Monday, January 14, 2019 6:58 AM To: python-list@python.org Subject: get the terminal's size Hi there, I want to know the number of columns of the terminal where python2 writes it's outputs. In a terminal, I type $ echo $COLUMNS 100 But in Python, os.getenv("COLUMNS")

Re: get the terminal's size

2019-01-14 Thread Alex Ternaute
Hi, Grant Edwards : >>export COLUMNS LINES > That will tell you the terminal size at the time Python was started. Ok, I think tracking these changes in real time is not worth the work to be done using Python2. I think at last I'll rewrite this (little) programe in Python3 in order to use

Re: get the terminal's size

2019-01-14 Thread Alex Ternaute
Hi Thomas >> Looking on the internet for a hint, I see that python3 has an >> os.get_terminal_size(). > Use that then. Up to now I wanted to keep compatibility with a big bunch of code in Python2 that I do no maintain by myself. Well, I saw that get_terminal_size() follows the windows

Re: get the terminal's size

2019-01-14 Thread Grant Edwards
On 2019-01-14, Peter Otten <__pete...@web.de> wrote: > Grant Edwards wrote: > > os.environ["COLUMNS"] > >> [...] will tell you the terminal size at the time Python was started. > > I admit that none of my scripts is ambitious enough to try and track > changes in terminal size. > > But still,

Re: get the terminal's size

2019-01-14 Thread Peter Otten
Grant Edwards wrote: os.environ["COLUMNS"] > [...] will tell you the terminal size at the time Python was started. I admit that none of my scripts is ambitious enough to try and track changes in terminal size. But still, Grant's post prompted me to reread the doc and source of

Re: get the terminal's size

2019-01-14 Thread Grant Edwards
On 2019-01-14, Peter Otten <__pete...@web.de> wrote: > >> I want to know the number of columns of the terminal where python2 writes >> it's outputs. >> >> In a terminal, I type >> $ echo $COLUMNS >> 100 >> >> But in Python, os.getenv("COLUMNS") gets nothing. >> It gets nothing as well if I try

Re: get the terminal's size

2019-01-14 Thread Thomas Jollans
On 14/01/2019 12.57, Alex Ternaute wrote: > Hi there, > > I want to know the number of columns of the terminal where python2 writes > it's outputs. > > In a terminal, I type > $ echo $COLUMNS > 100 > > But in Python, os.getenv("COLUMNS") gets nothing. > It gets nothing as well if I try to read

Re: get the terminal's size

2019-01-14 Thread Alex Ternaute
Hi, Peter Otten : >> In a terminal, I type $ echo $COLUMNS 100 >> But in Python, os.getenv("COLUMNS") gets nothing. >> I feel that I'm missing something but what ? > $ export COLUMNS Thank you very much ! -- Aelx -- https://mail.python.org/mailman/listinfo/python-list

Re: get the terminal's size

2019-01-14 Thread Peter Otten
Alex Ternaute wrote: > Hi there, > > I want to know the number of columns of the terminal where python2 writes > it's outputs. > > In a terminal, I type > $ echo $COLUMNS > 100 > > But in Python, os.getenv("COLUMNS") gets nothing. > It gets nothing as well if I try to read the output of "echo

get the terminal's size

2019-01-14 Thread Alex Ternaute
Hi there, I want to know the number of columns of the terminal where python2 writes it's outputs. In a terminal, I type $ echo $COLUMNS 100 But in Python, os.getenv("COLUMNS") gets nothing. It gets nothing as well if I try to read the output of "echo $COLUMNS" from a subprocess. I feel that