File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 22
33import os
44import re
5- import shutil
65import sys
7- from typing import Dict , Pattern
6+ from typing import Dict
87
98try :
109 # check if colorama is installed to support color on Windows
1312 colorama = None
1413
1514
16- _ansi_re : Pattern = re .compile ('\x1b \\ [(\\ d\\ d;){0,2}\\ d\\ dm' )
15+ _ansi_re : 're. Pattern[str]' = re .compile ('\x1b \\ [(\\ d\\ d;){0,2}\\ d\\ dm' )
1716codes : Dict [str , str ] = {}
1817
1918
@@ -24,7 +23,17 @@ def terminal_safe(s: str) -> str:
2423
2524def get_terminal_width () -> int :
2625 """Return the width of the terminal in columns."""
27- return shutil .get_terminal_size ().columns - 1
26+ try :
27+ columns = int (os .environ .get ('COLUMNS' , 0 ))
28+ except ValueError :
29+ columns = 0
30+ if columns > 1 :
31+ return columns - 1
32+ try :
33+ return os .get_terminal_size (sys .__stdout__ .fileno ()).columns - 1
34+ except (AttributeError , ValueError , OSError ):
35+ # fallback
36+ return 80 - 1
2837
2938
3039_tw : int = get_terminal_width ()
You can’t perform that action at this time.
0 commit comments