-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argparse: terminal width is not detected properly #57250
Comments
COLUMNS is a shell variable (updated whenever the window size Why COLUMNS is not exported? Because it can change during the lifetime |
I see that adding a separate module was proposed in issue bpo-8408, which was rejected/closed. I don't have the rights to reopen, so I'll continue here. bpo-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. |
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). |
I'd feel more comfortable with the argparse fix if it were simply calling "os.get_terminal_size()". I recommend that you:
Once that is fixed, then the argparse fix should be simple. |
Issue bpo-13609 created, but I don't have permission to edit the dependencies. |
New version to use after bpo-13609 is implemented: patch2.diff |
OK, I guess that this could now be closed, since 13609 has been commited. I'm attaching a patch which updates the tests to the new $COLUMNS logic. |
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. |
For now the user could add this to his module: import os, shutil
os.environ['COLUMNS'] = str(shutil.get_terminal_size().columns) |
What's holding up the merging of this patch? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: