diff options
author | Filipe Laíns <lains@riseup.net> | 2021-10-19 18:42:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-19 18:42:13 (GMT) |
commit | 236e301b8ad9b78ee880baf12e98a826113dc59b (patch) | |
tree | c95fae5ee2518e73a0ac59b6eaf7f64e63e3cf20 | |
parent | 574241632bd19e56ed488ee4d8999aefc6a8d7cd (diff) | |
download | cpython-236e301b8ad9b78ee880baf12e98a826113dc59b.zip cpython-236e301b8ad9b78ee880baf12e98a826113dc59b.tar.gz cpython-236e301b8ad9b78ee880baf12e98a826113dc59b.tar.bz2 |
bpo-42174: fallback to sane values if the columns or lines are 0 in get_terminal_size (GH-29046)
I considered only falling back when both were 0, but that still seems
wrong, and the highly popular rich[1] library does it this way, so I
thought we should probably inherit that behavior.
[1] https://github.com/willmcgugan/rich
Signed-off-by: Filipe Laíns <lains@riseup.net>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
-rw-r--r-- | Doc/library/shutil.rst | 4 | ||||
-rw-r--r-- | Lib/shutil.py | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 11c6707..22d6dba 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -804,6 +804,10 @@ Querying the size of the output terminal .. versionadded:: 3.3 + .. versionchanged:: 3.11 + The ``fallback`` values are also used if :func:`os.get_terminal_size` + returns zeroes. + .. _`fcopyfile`: http://www.manpagez.com/man/3/copyfile/ diff --git a/Lib/shutil.py b/Lib/shutil.py index e544498..949e024 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1372,9 +1372,9 @@ def get_terminal_size(fallback=(80, 24)): # os.get_terminal_size() is unsupported size = os.terminal_size(fallback) if columns <= 0: - columns = size.columns + columns = size.columns or fallback[0] if lines <= 0: - lines = size.lines + lines = size.lines or fallback[1] return os.terminal_size((columns, lines)) diff --git a/Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst b/Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst new file mode 100644 index 0000000..412582d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst @@ -0,0 +1,2 @@ +:meth:`shutil.get_terminal_size` now falls back to sane values if the column +or line count are 0. |