summaryrefslogtreecommitdiff
path: root/src/_pytest/_io
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-04-29 15:12:32 +0300
committerRan Benita <ran@unusedvar.com>2020-04-30 16:44:02 +0300
commit6c1b6a09b878ea74796618d02e7a8222464e1b9a (patch)
tree62c0a18c0b3415e62038d3fe28621a571edd5374 /src/_pytest/_io
parentc749e44efc37c2792b0d1257930a24c74b4a7251 (diff)
downloadpytest-6c1b6a09b878ea74796618d02e7a8222464e1b9a.tar.gz
terminalwriter: simplify get_terminal_width()
The shutil.get_terminal_size() handles everything this did already.
Diffstat (limited to 'src/_pytest/_io')
-rw-r--r--src/_pytest/_io/terminalwriter.py27
1 files changed, 4 insertions, 23 deletions
diff --git a/src/_pytest/_io/terminalwriter.py b/src/_pytest/_io/terminalwriter.py
index 6ff39111a..5533aa914 100644
--- a/src/_pytest/_io/terminalwriter.py
+++ b/src/_pytest/_io/terminalwriter.py
@@ -23,34 +23,15 @@ if sys.platform == "win32":
win32_and_ctypes = True
-def _getdimensions():
- size = shutil.get_terminal_size()
- return size.lines, size.columns
+def get_terminal_width() -> int:
+ width, _ = shutil.get_terminal_size(fallback=(80, 24))
-
-def get_terminal_width():
- width = 0
- try:
- _, width = _getdimensions()
- except (KeyboardInterrupt, SystemExit, MemoryError, GeneratorExit):
- raise
- except BaseException:
- # pass to fallback below
- pass
-
- if width == 0:
- # FALLBACK:
- # * some exception happened
- # * or this is emacs terminal which reports (0,0)
- width = int(os.environ.get("COLUMNS", 80))
-
- # XXX the windows getdimensions may be bogus, let's sanify a bit
+ # The Windows get_terminal_size may be bogus, let's sanify a bit.
if width < 40:
width = 80
- return width
+ return width
-terminal_width = get_terminal_width()
char_width = {
"A": 1, # "Ambiguous"