12
12
# from https://gist.github.com/jtriley/1108174
13
13
# Copyright © 2011 jtriley
14
14
#
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
+ #
15
22
# This program is free software; you can redistribute it and/or modify
16
23
# it under the terms of the GNU Lesser General Public License as published by
17
24
# the Free Software Foundation; either version 3 of the License, or
27
34
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28
35
# MA 02110-1301, USA.
29
36
#
30
- #
31
37
32
38
# stdlib
33
39
import os
34
- import sys
40
+ import platform
35
41
import shlex
36
42
import struct
37
- import platform
38
43
import subprocess
39
-
40
- # this package
41
- from domdf_python_tools import pyversion
44
+ import sys
42
45
43
46
44
47
def clear ():
45
48
"""
46
49
Clear the display
47
50
48
- works for Windows and UNIX, but does not clear Python Shell
51
+ works for Windows and UNIX, but does not clear Python Interpreter
49
52
50
53
:return:
51
54
"""
@@ -61,32 +64,14 @@ def br():
61
64
print ("" )
62
65
63
66
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
-
82
67
83
68
def interrupt ():
84
69
"""
85
70
Print what to do to abort the script; dynamic depending on OS
86
71
Useful when you have a long-running script that you might want t interrupt part way through
87
72
"""
88
73
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.)" )
90
75
91
76
92
77
def overtype (* objects , sep = ' ' , end = '' , file = sys .stdout , flush = False ):
@@ -97,11 +82,9 @@ def overtype(*objects, sep=' ', end='', file=sys.stdout, flush=False):
97
82
All non-keyword arguments are converted to strings like ``str()`` does and written to the stream,
98
83
separated by `sep` and followed by `end`.
99
84
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 ".
103
86
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
105
88
106
89
:param objects:
107
90
:param sep: String to separate the objects with, by default " "
@@ -155,12 +138,12 @@ def _get_terminal_size_windows():
155
138
csbi = create_string_buffer (22 )
156
139
res = windll .kernel32 .GetConsoleScreenBufferInfo (h , csbi )
157
140
if res :
158
- (bufx , bufy , curx , cury , wattr ,
141
+ (buf_x , buf_y , cur_x , cur_y , wattr ,
159
142
left , top , right , bottom ,
160
143
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
164
147
except :
165
148
pass
166
149
@@ -171,7 +154,7 @@ def _get_terminal_size_tput():
171
154
try :
172
155
cols = int (subprocess .check_call (shlex .split ('tput cols' )))
173
156
rows = int (subprocess .check_call (shlex .split ('tput lines' )))
174
- return ( cols , rows )
157
+ return cols , rows
175
158
except :
176
159
pass
177
160
@@ -181,8 +164,7 @@ def ioctl_GWINSZ(fd):
181
164
try :
182
165
import fcntl
183
166
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' ))
186
168
return cr
187
169
except :
188
170
pass
@@ -203,5 +185,5 @@ def ioctl_GWINSZ(fd):
203
185
204
186
205
187
if __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