1212# from https://gist.github.com/jtriley/1108174
1313# Copyright © 2011 jtriley
1414#
15+ # Parts of the docstrings based on the Python 3.8.2 Documentation
16+ # Licensed under the Python Software Foundation License Version 2.
17+ # Copyright © 2001-2020 Python Software Foundation. All rights reserved.
18+ # Copyright © 2000 BeOpen.com . All rights reserved.
19+ # Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
20+ # Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
21+ #
1522# This program is free software; you can redistribute it and/or modify
1623# it under the terms of the GNU Lesser General Public License as published by
1724# the Free Software Foundation; either version 3 of the License, or
2734# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
2835# MA 02110-1301, USA.
2936#
30- #
3137
3238# stdlib
3339import os
34- import sys
40+ import platform
3541import shlex
3642import struct
37- import platform
3843import subprocess
39-
40- # this package
41- from domdf_python_tools import pyversion
44+ import sys
4245
4346
4447def clear ():
4548 """
4649 Clear the display
4750
48- works for Windows and UNIX, but does not clear Python Shell
51+ works for Windows and UNIX, but does not clear Python Interpreter
4952
5053 :return:
5154 """
@@ -61,32 +64,14 @@ def br():
6164 print ("" )
6265
6366
64- def entry (text_to_print ):
65- """
66- Version-agnostic input function
67-
68- # TODO: Deprecation warning
69-
70- :param text_to_print: Text to print before the input field
71- :type text_to_print: str
72-
73- :return: Text entered
74- :rtype: str
75- """
76-
77- if pyversion == 3 :
78- return input (text_to_print )
79- elif pyversion == 2 :
80- return raw_input (text_to_print )
81-
8267
8368def interrupt ():
8469 """
8570 Print what to do to abort the script; dynamic depending on OS
8671 Useful when you have a long-running script that you might want t interrupt part way through
8772 """
8873
89- print (' (Press Ctrl-%s to quit at any time.)' % ' C' if os .name == 'nt' else 'D' )
74+ print (f" (Press Ctrl-{ ' C' if os .name == 'nt' else 'D' } to quit at any time.)" )
9075
9176
9277def overtype (* objects , sep = ' ' , end = '' , file = sys .stdout , flush = False ):
@@ -97,11 +82,9 @@ def overtype(*objects, sep=' ', end='', file=sys.stdout, flush=False):
9782 All non-keyword arguments are converted to strings like ``str()`` does and written to the stream,
9883 separated by `sep` and followed by `end`.
9984
100- If no objects are given, ``overwrite()` will just write "\r ".
101-
102- Based on the Python print() docs: https://docs.python.org/3/library/functions.html#print
85+ If no objects are given, ``overtype()`` will just write "\r ".
10386
104- # This does not currently work in the PyCharm console, at least on Windows
87+ TODO: This does not currently work in the PyCharm console, at least on Windows
10588
10689 :param objects:
10790 :param sep: String to separate the objects with, by default " "
@@ -155,12 +138,12 @@ def _get_terminal_size_windows():
155138 csbi = create_string_buffer (22 )
156139 res = windll .kernel32 .GetConsoleScreenBufferInfo (h , csbi )
157140 if res :
158- (bufx , bufy , curx , cury , wattr ,
141+ (buf_x , buf_y , cur_x , cur_y , wattr ,
159142 left , top , right , bottom ,
160143 maxx , maxy ) = struct .unpack ("hhhhHhhhhhh" , csbi .raw )
161- sizex = right - left + 1
162- sizey = bottom - top + 1
163- return sizex , sizey
144+ size_x = right - left + 1
145+ size_y = bottom - top + 1
146+ return size_x , size_y
164147 except :
165148 pass
166149
@@ -171,7 +154,7 @@ def _get_terminal_size_tput():
171154 try :
172155 cols = int (subprocess .check_call (shlex .split ('tput cols' )))
173156 rows = int (subprocess .check_call (shlex .split ('tput lines' )))
174- return ( cols , rows )
157+ return cols , rows
175158 except :
176159 pass
177160
@@ -181,8 +164,7 @@ def ioctl_GWINSZ(fd):
181164 try :
182165 import fcntl
183166 import termios
184- cr = struct .unpack ('hh' ,
185- fcntl .ioctl (fd , termios .TIOCGWINSZ , '1234' ))
167+ cr = struct .unpack ('hh' , fcntl .ioctl (fd , termios .TIOCGWINSZ , '1234' ))
186168 return cr
187169 except :
188170 pass
@@ -203,5 +185,5 @@ def ioctl_GWINSZ(fd):
203185
204186
205187if __name__ == "__main__" :
206- sizex , sizey = get_terminal_size ()
207- print ('width =' , sizex , 'height =' , sizey )
188+ size_x , size_y = get_terminal_size ()
189+ print ('width =' , size_x , 'height =' , size_y )
0 commit comments