]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42174: fallback to sane values if the columns or lines are 0 in get_terminal_size...
authorFilipe Laíns <lains@riseup.net>
Tue, 19 Oct 2021 18:42:13 +0000 (19:42 +0100)
committerGitHub <noreply@github.com>
Tue, 19 Oct 2021 18:42:13 +0000 (20:42 +0200)
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>
Doc/library/shutil.rst
Lib/shutil.py
Misc/NEWS.d/next/Library/2021-10-19-01-30-57.bpo-42174.O2w9bi.rst [new file with mode: 0644]

index 11c6707492167299e666628d49765187b1a4fb3e..22d6dba9e1a9c61afa6294b869acd7269f718359 100644 (file)
@@ -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/
 
index e544498fca7c84a2aae64f4ba918c009fc0606de..949e024853c1d2ff4e1d3900860ba2141fd8bd84 100644 (file)
@@ -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 (file)
index 0000000..412582d
--- /dev/null
@@ -0,0 +1,2 @@
+:meth:`shutil.get_terminal_size` now falls back to sane values if the column
+or line count are 0.