6060#
6161
6262# stdlib
63+ import fcntl
6364import inspect
6465import os
6566import platform
6869import struct
6970import subprocess
7071import sys
72+ import termios
7173import textwrap
7274from typing import Optional , Tuple
7375
@@ -80,7 +82,7 @@ def clear() -> None:
8082 """
8183
8284 if os .name == "nt" :
83- os .system (' cls' )
85+ os .system (" cls" )
8486 else :
8587 print ("\033 c" , end = '' )
8688
@@ -90,7 +92,7 @@ def br() -> None:
9092 Prints a line break
9193 """
9294
93- print ("" )
95+ print ('' )
9496
9597
9698def interrupt () -> None :
@@ -148,13 +150,13 @@ def get_terminal_size() -> Tuple[int, int]:
148150 current_os = platform .system ()
149151 tuple_xy = None
150152
151- if current_os == ' Windows' :
153+ if current_os == " Windows" :
152154 tuple_xy = _get_terminal_size_windows ()
153155 if tuple_xy is None :
154156 tuple_xy = _get_terminal_size_tput ()
155157 # needed for window's python in cygwin's xterm!
156158
157- if current_os in [ ' Linux' , ' Darwin' ] or current_os .startswith (' CYGWIN' ):
159+ if current_os in { " Linux" , " Darwin" } or current_os .startswith (" CYGWIN" ):
158160 tuple_xy = _get_terminal_size_linux ()
159161
160162 if tuple_xy is None :
@@ -194,8 +196,8 @@ def _get_terminal_size_tput() -> Optional[Tuple[int, int]]:
194196 # get terminal width
195197 # src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window
196198 try :
197- cols = int (subprocess .check_call (shlex .split (' tput cols' )))
198- rows = int (subprocess .check_call (shlex .split (' tput lines' )))
199+ cols = int (subprocess .check_call (shlex .split (" tput cols" )))
200+ rows = int (subprocess .check_call (shlex .split (" tput lines" )))
199201 return cols , rows
200202 except :
201203 return None
@@ -205,11 +207,7 @@ def _get_terminal_size_linux() -> Optional[Tuple[int, int]]:
205207
206208 def ioctl_GWINSZ (fd ):
207209 try :
208-
209- # stdlib
210- import fcntl
211- import termios
212- cr = struct .unpack ('hh' , fcntl .ioctl (fd , termios .TIOCGWINSZ , '1234' ))
210+ cr = struct .unpack ("hh" , fcntl .ioctl (fd , termios .TIOCGWINSZ , "1234" ))
213211 return cr
214212 except :
215213 pass
@@ -218,15 +216,15 @@ def ioctl_GWINSZ(fd):
218216
219217 if not cr :
220218 try :
221- fd = os .open (os .ctermid (), os .O_RDONLY ) # type: ignore
219+ fd = os .open (os .ctermid (), os .O_RDONLY ) # type: ignore
222220 cr = ioctl_GWINSZ (fd )
223221 os .close (fd )
224222 except :
225223 pass
226224
227225 if not cr :
228226 try :
229- cr = (os .environ [' LINES' ], os .environ [' COLUMNS' ])
227+ cr = (os .environ [" LINES" ], os .environ [" COLUMNS" ])
230228 except :
231229 return None
232230
@@ -238,7 +236,7 @@ class Echo:
238236 Context manager for echoing variable assignments (in CPython)
239237 """
240238
241- def __init__ (self , msg : str , indent : str = ' ' ):
239+ def __init__ (self , msg : str , indent : str = " " ):
242240 self .msg = msg
243241 self .indent = indent
244242
@@ -259,4 +257,4 @@ def __exit__(self, exc_t, exc_v, tb):
259257
260258if __name__ == "__main__" :
261259 size_x , size_y = get_terminal_size ()
262- print (' width =' , size_x , ' height =' , size_y )
260+ print (" width =" , size_x , " height =" , size_y )
0 commit comments