Re: Is shutil.get_terminal_size useless?

2017-02-01 Thread Chris Angelico
On Thu, Feb 2, 2017 at 12:24 PM, Steve D'Aprano wrote: etc, etc, etc, etc. It's not a proxy for "being piped" - it's that when your output isn't going to a terminal, asking "what is my terminal size" isn't particularly productive. >>> >>> Then

Re: Is shutil.get_terminal_size useless?

2017-02-01 Thread Steve D'Aprano
On Sat, 28 Jan 2017 11:53 pm, Peter Otten wrote: [...] >> I see that as "Hey look, we can fool shutil into returning >> absolute garbage instead of the terminal size!" > > There are valid reasons for temporarily altering the number of columns, > like writing to a file or preparing a code sample.

Re: Is shutil.get_terminal_size useless?

2017-02-01 Thread Steve D'Aprano
On Sun, 29 Jan 2017 04:58 am, Chris Angelico wrote: > On Sun, Jan 29, 2017 at 3:15 AM, Steve D'Aprano > wrote: >> On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote: >> >>> On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano >>> wrote:

Re: Is shutil.get_terminal_size useless?

2017-01-30 Thread Paul Moore
On Monday, 30 January 2017 05:37:32 UTC, Steven D'Aprano wrote: > On Monday 30 January 2017 08:12, Serhiy Storchaka wrote: > > > On 28.01.17 10:03, Steve D'Aprano wrote: > >> Is shutil.get_terminal_size useless? When, if ever, should I use it in > >> preference to

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Wildman via Python-list
ault: > > > [steve@ando ~]$ python3.5 test_gts.py | cat > shutil: os.terminal_size(columns=999, lines=999) > os: os.terminal_size(columns=116, lines=29) > > > while the os version gives the correct result. > > Is shutil.get_terminal_size useless? When, if ever, shoul

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Steven D'Aprano
On Monday 30 January 2017 08:12, Serhiy Storchaka wrote: > On 28.01.17 10:03, Steve D'Aprano wrote: >> Is shutil.get_terminal_size useless? When, if ever, should I use it in >> preference to the os version? If the shutil version is broken, can it be >> fixed?

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread eryk sun
On Mon, Jan 30, 2017 at 2:16 AM, Steve D'Aprano <steve+pyt...@pearwood.info> wrote: > On Mon, 30 Jan 2017 08:12 am, Serhiy Storchaka wrote: > >> On 28.01.17 10:03, Steve D'Aprano wrote: >>> Is shutil.get_terminal_size useless? When, if ever, should I use it in >&

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 08:12 am, Serhiy Storchaka wrote: > On 28.01.17 10:03, Steve D'Aprano wrote: >> Is shutil.get_terminal_size useless? When, if ever, should I use it in >> preference to the os version? If the shutil version is broken, can it be >> fixed?

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Serhiy Storchaka
On 28.01.17 10:03, Steve D'Aprano wrote: Is shutil.get_terminal_size useless? When, if ever, should I use it in preference to the os version? If the shutil version is broken, can it be fixed? Read the history of shutil.get_terminal_size(). All this was discussed. -- https://mail.python.org

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Grant Edwards wrote: > On 2017-01-29, Marko Rauhamaa wrote: > >> Mount? As a regular user? > > Yes, using a "fuse" use-space filesystem, you can mount things as a > normal user. There are a couple ISO9660 fuse implemenations. But, you

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Chris Angelico : > On Mon, Jan 30, 2017 at 3:44 AM, Marko Rauhamaa wrote: >> Mount? As a regular user? > > Let me see, how much effort are you prepared to go to in order to do > this as a "regular user"... because at some point, "sudo" becomes only > one of

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 4:08 AM, Grant Edwards wrote: > As long as you've got the disk space available, the simplest option is > to unpack the .iso into a directory, modify the files, and then use > mkisofs to create the new .iso image. > > I've written scripts like

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Marko Rauhamaa wrote: > Mount? As a regular user? Yes, using a "fuse" use-space filesystem, you can mount things as a normal user. There are a couple ISO9660 fuse implemenations. But, you can't modify a mounted ISO9660 filesystem. I have read about how to use

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa wrote: >>> Grant Edwards : >>> On 2017-01-29, Marko Rauhamaa wrote: > I *have*

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 3:44 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa wrote: >>> Grant Edwards : >>> On 2017-01-29, Marko Rauhamaa

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Chris Angelico : > On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa wrote: >> Grant Edwards : >> >>> On 2017-01-29, Marko Rauhamaa wrote: I *have* been longing for a serial console in linux distros. >>> >>>

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Chris Angelico
On Mon, Jan 30, 2017 at 3:28 AM, Marko Rauhamaa wrote: > Grant Edwards : > >> On 2017-01-29, Marko Rauhamaa wrote: >>> I *have* been longing for a serial console in linux distros. >> >> Well, all it takes is a tweak to the bootloader

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Grant Edwards : > On 2017-01-29, Marko Rauhamaa wrote: >> I *have* been longing for a serial console in linux distros. > > Well, all it takes is a tweak to the bootloader to add a kernel > "command-line" parameter... Can you give me a short Python

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Grant Edwards
On 2017-01-29, Marko Rauhamaa wrote: > Grant Edwards : > >> On 2017-01-28, Marko Rauhamaa wrote: >> >>> (Although if I were to design an operating system, I don't know if I >>> would bother with controlling terminals, job control or

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Marko Rauhamaa
Grant Edwards : > On 2017-01-28, Marko Rauhamaa wrote: > >> (Although if I were to design an operating system, I don't know if I >> would bother with controlling terminals, job control or chirping >> modems.) > > I've been using serial ports on Unix

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Grant Edwards
On 2017-01-28, Marko Rauhamaa wrote: > (Although if I were to design an operating system, I don't know if I > would bother with controlling terminals, job control or chirping > modems.) I've been using serial ports on Unix for 35 years, and maintaining serial drivers for Linux

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Marko Rauhamaa
Chris Angelico : > On Sun, Jan 29, 2017 at 7:04 AM, eryk sun wrote: >> Now let's get rid of the terminal via setsid: >> >>$ echo spam | >> > 2>&1 setsid python3 -c 'import os >> > fd = os.open("/dev/tty", os.O_RDONLY) >> >

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Chris Angelico
On Sun, Jan 29, 2017 at 7:04 AM, eryk sun wrote: > Now let's get rid of the terminal via setsid: > >$ echo spam | > > 2>&1 setsid python3 -c 'import os > > fd = os.open("/dev/tty", os.O_RDONLY) > > print(os.get_terminal_size(fd))' | > > cat > Traceback

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread eryk sun
On Sat, Jan 28, 2017 at 5:58 PM, Chris Angelico wrote: > Processes in the middle of pipelines *do not have* terminals. No, in the following case stderr is a terminal: $ echo spam | > python3 -c 'import os > print(os.get_terminal_size(2))' | > cat

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Marko Rauhamaa
Chris Angelico : > Background processes don't have terminal access. Whether it's a daemon > or something started as "commandname >/dev/null 2>/dev/null &" from bash, it doesn't have access to a terminal. A nitpick: a process running in the background or a process with no open

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Chris Angelico
On Sun, Jan 29, 2017 at 3:15 AM, Steve D'Aprano wrote: > On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote: > >> On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano >> wrote: >>> The terminal size doesn't change just because I'm piping output

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Grant Edwards
On 2017-01-28, Steve D'Aprano wrote: > On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote: > >> On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano >> wrote: >>> The terminal size doesn't change just because I'm piping output to >>> another

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Michael Torrie
On 01/28/2017 09:15 AM, Steve D'Aprano wrote: > Then explain why os.get_terminal_size() returns the correct answer. Basically you were asking two different questions there. shutil.get_terminal_size always asks the question of size of the terminal that the standard output file handle is connected

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Michael Torrie
On 01/28/2017 09:15 AM, Steve D'Aprano wrote: > Then get_terminal_size() should raise, unless you explicitly ask for a > default size. Which it does if you call it on the standard out file handle, which is the default, and for most applications, the most useful. --

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Michael Torrie
On 01/28/2017 09:03 AM, Michael Torrie wrote: > On 01/28/2017 04:00 AM, Steve D'Aprano wrote: >>> $ COLUMNS=123 python3 test_gts.py | cat >>> shutil: os.terminal_size(columns=123, lines=999) >>> os: os.terminal_size(columns=72, lines=48) > > Interesting. On my machine with Python 3.4, calling >

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote: > On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano > 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

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Michael Torrie
On 01/28/2017 04:00 AM, Steve D'Aprano wrote: >> $ COLUMNS=123 python3 test_gts.py | cat >> shutil: os.terminal_size(columns=123, lines=999) >> os: os.terminal_size(columns=72, lines=48) Interesting. On my machine with Python 3.4, calling os.get_terminal_size() and piping the output results in

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Grant Edwards
On 2017-01-28, Steve D'Aprano wrote: > Right: I want to know what the terminal window is sized to. What do you mean by "the terminal"? Do you mean the device to which the program's output is connected? Since output is what you have control over, and what's width you

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Peter Otten
Steve D'Aprano wrote: >> One potential advantage of shutil.get_terminal_size() is that you can >> affect it with an environment variable: >> >> $ python3 test_gts.py | cat >> shutil: os.terminal_size(columns=999, lines=999) >> os: os.terminal_size(columns=72, lines=48) >> >> $ COLUMNS=123 python3

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread eryk sun
On Sat, Jan 28, 2017 at 8:03 AM, Steve D'Aprano wrote: > print('shutil:', shutil.get_terminal_size(fallback=(999, 999))) > print('os:', os.get_terminal_size(0)) [snip] > But if I pipe the output to something else, the shutil version fails to > determine the correct

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Chris Angelico
On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano 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

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
On Sat, 28 Jan 2017 07:39 pm, Peter Otten wrote: > One potential advantage of shutil.get_terminal_size() is that you can > affect it with an environment variable: > > $ python3 test_gts.py | cat > shutil: os.terminal_size(columns=999, lines=999) > os: os.terminal_size(columns=72, lines=48) > >

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
On Sat, 28 Jan 2017 07:27 pm, Chris Angelico wrote: > On Sat, Jan 28, 2017 at 7:03 PM, Steve D'Aprano > wrote: >> But if I pipe the output to something else, the shutil version fails to >> determine the correct terminal size, and falls back on the default: >> >> >>

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Peter Otten
n3.5 test_gts.py | cat > shutil: os.terminal_size(columns=999, lines=999) > os: os.terminal_size(columns=116, lines=29) > > > while the os version gives the correct result. > > Is shutil.get_terminal_size useless? When, if ever, should I use it in > pref

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Chris Angelico
On Sat, Jan 28, 2017 at 7:03 PM, Steve D'Aprano wrote: > But if I pipe the output to something else, the shutil version fails to > determine the correct terminal size, and falls back on the default: > > > [steve@ando ~]$ python3.5 test_gts.py | cat > shutil:

Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
result. Is shutil.get_terminal_size useless? When, if ever, should I use it in preference to the os version? If the shutil version is broken, can it be fixed? Thanks to Bernardas Ališauskas: http://granitosaurus.rocks/getting-terminal-size.html -- Steve “Cheer up,” they said, “things could