Skip to content

Commit 236e301

Browse files
FFY00ambv
andauthored
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 <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent 5742416 commit 236e301

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Doc/library/shutil.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ Querying the size of the output terminal
804804

805805
.. versionadded:: 3.3
806806

807+
.. versionchanged:: 3.11
808+
The ``fallback`` values are also used if :func:`os.get_terminal_size`
809+
returns zeroes.
810+
807811
.. _`fcopyfile`:
808812
http://www.manpagez.com/man/3/copyfile/
809813

Lib/shutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,9 +1372,9 @@ def get_terminal_size(fallback=(80, 24)):
13721372
# os.get_terminal_size() is unsupported
13731373
size = os.terminal_size(fallback)
13741374
if columns <= 0:
1375-
columns = size.columns
1375+
columns = size.columns or fallback[0]
13761376
if lines <= 0:
1377-
lines = size.lines
1377+
lines = size.lines or fallback[1]
13781378

13791379
return os.terminal_size((columns, lines))
13801380

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:meth:`shutil.get_terminal_size` now falls back to sane values if the column
2+
or line count are 0.

0 commit comments

Comments
 (0)