msg144507 - (view) |
Author: Zbyszek Jędrzejewski-Szmek (zbysz) * |
Date: 2011-09-24 22:07 |
COLUMNS is a shell variable (updated whenever the window size changes), that usually isn't exported to programs. Therefore checking for COLUMNS in sys.environ will not work in the majority of cases. The proper check is to use the TIOCGWINSZ ioctl on stdout. Why COLUMNS is not exported? Because it can change during the lifetime of a program. Therefore it is better to use the dynamic ioctl. |
|
|
msg144521 - (view) |
Author: Zbyszek Jędrzejewski-Szmek (zbysz) * |
Date: 2011-09-25 10:01 |
I see that adding a separate module was proposed in issue #8408, which was rejected/closed. I don't have the rights to reopen, so I'll continue here. #8408 was proposing a new module, which seems a bit overkill, since the implementation for unix and windows is about 20 lines. I'm attaching a second version of the patch which works on windows (tested with python3.2.2 on XP). Thanks to techtonik for pointing to a windows imlementation. |
|
|
msg144523 - (view) |
Author: Denilson Figueiredo de Sá (denilsonsa) |
Date: 2011-09-25 14:18 |
> #8408 was proposing a new module, which seems a bit overkill If a module seems overkill, then maybe add this useful function to os module. Don't leave it private to argparse module. Maybe something along these lines: >>> import os >>> print(os.get_terminal_size()) (80, 25) Why do I believe a module could be better? Because I'd also like some way to detect when the terminal size has changed (without probing it all the time). |
|
|
msg149531 - (view) |
Author: Steven Bethard (bethard) *  |
Date: 2011-12-15 11:08 |
I'd feel more comfortable with the argparse fix if it were simply calling "os.get_terminal_size()". I recommend that you: * Create a new issue called, say "add os.get_terminal_size()" proposing just the single method. * Add that issue to the Dependencies of this issue. Once that is fixed, then the argparse fix should be simple. |
|
|
msg149587 - (view) |
Author: Denilson Figueiredo de Sá (denilsonsa) |
Date: 2011-12-16 01:05 |
Issue #13609 created, but I don't have permission to edit the dependencies. |
|
|
msg150728 - (view) |
Author: Zbyszek Jędrzejewski-Szmek (zbysz) * |
Date: 2012-01-06 13:04 |
New version to use after #13609 is implemented: patch2.diff |
|
|
msg153961 - (view) |
Author: Zbyszek Jędrzejewski-Szmek (zbysz) * |
Date: 2012-02-22 15:36 |
OK, I guess that this could now be closed, since 13609 has been commited. (It is currently reopened, but the proposed tweaks wouldn't influence the usage in argparse, even if accepted). I'm attaching a patch which updates the tests to the new $COLUMNS logic. Previously, unsetting COLUMNS would fix the width on 80, now setting COLUMNS=80 is the proper way to do this. |
|
|
msg223222 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2014-07-16 15:29 |
@Paul the attached patch is extremely simple and follows the work on #13609. Is it okay with you if the patch was committed? |
|
|
msg223298 - (view) |
Author: paul j3 (paul.j3) *  |
Date: 2014-07-16 23:30 |
The latest patch, using _shutil.get_terminal_size(), looks fine. It lets environ['COLUMNS'] have priority over the end user's terminal width, as demonstrated by the change to test_argparse. test_argparse doesn't test changing the actual terminal size, but I imagine that would be a pain to implement. |
|
|
msg223809 - (view) |
Author: paul j3 (paul.j3) *  |
Date: 2014-07-24 05:24 |
For now the user could add this to his module: import os, shutil os.environ['COLUMNS'] = str(shutil.get_terminal_size().columns) |
|
|
msg315274 - (view) |
Author: Julian Mehnle (jmehnle) |
Date: 2018-04-13 23:58 |
What's holding up the merging of this patch? |
|
|
msg322365 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2018-07-25 15:23 |
New changeset 74102c9a5f2327c4fc47feefa072854a53551d1f by Berker Peksag in branch 'master': bpo-13041: Use shutil.get_terminal_size() in argparse.HelpFormatter (GH-8459) https://github.com/python/cpython/commit/74102c9a5f2327c4fc47feefa072854a53551d1f |
|
|