summaryrefslogtreecommitdiff
path: root/src/click/formatting.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-12-22 15:01:06 -0800
committerDavid Lord <davidism@gmail.com>2021-02-15 12:44:20 -0800
commit5ab1ac229558b40ac87a16ac80603d0330c2e6e1 (patch)
tree96cc3444c7cd29c1b539bb46ce59c09b910c2c7c /src/click/formatting.py
parentb28bc4c6439d7b01c011e72c09d80574fe75b85b (diff)
downloadclick-5ab1ac229558b40ac87a16ac80603d0330c2e6e1.tar.gz
Deprecate click.get_terminal_size() in favor of stdlib shutil.
Since Python 3.3, the stdlib provides the function shutil.get_terminal_size(). Now that the project has dropped Python 2 support, the compatibility shim is no longer necessary. The stdlib version returns a named tuple. So rather than indexing "0", can use the more self-documenting attribute "columns". Docs available at: https://docs.python.org/3/library/shutil.html#shutil.get_terminal_size
Diffstat (limited to 'src/click/formatting.py')
-rw-r--r--src/click/formatting.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/click/formatting.py b/src/click/formatting.py
index a298c2e..3edb09f 100644
--- a/src/click/formatting.py
+++ b/src/click/formatting.py
@@ -2,7 +2,6 @@ from contextlib import contextmanager
from ._compat import term_len
from .parser import split_opt
-from .termui import get_terminal_size
# Can force a width. This is used by the test system
FORCED_WIDTH = None
@@ -104,13 +103,15 @@ class HelpFormatter:
"""
def __init__(self, indent_increment=2, width=None, max_width=None):
+ import shutil
+
self.indent_increment = indent_increment
if max_width is None:
max_width = 80
if width is None:
width = FORCED_WIDTH
if width is None:
- width = max(min(get_terminal_size()[0], max_width) - 2, 50)
+ width = max(min(shutil.get_terminal_size().columns, max_width) - 2, 50)
self.width = width
self.current_indent = 0
self.buffer = []