2 Documentation for this module. 6 import sys, tty, termios
13 Moves console cursor up by defined value 17 val -one integer greater than zero 21 0 for success and -1 for error 23 if isinstance(val, int)
and val > 0:
33 Moves console cursor down by defined value 37 val -one integer greater than zero 41 0 for success and -1 for error 43 if isinstance(val, int)
and val > 0:
53 Moves console cursor right by defined value 57 val -one integer greater than zero 61 0 for success and -1 for error 63 if isinstance(val, int)
and val > 0:
73 Moves console cursor left by defined value 77 val -one integer greater than zero 81 0 for success and -1 for error 83 if isinstance(val, int)
and val > 0:
93 Function designed for printing special @ref ANSI Escape Codes "https://en.wikipedia.org/wiki/ANSI_escape_code#Terminal_input_sequences". The value and letter are concatenated to the escape character before being printed to the console. 97 val - no verification and validation 98 letter - no verification and validation 104 unicode_prefix =
u"\u001b[" 105 print(f
'{unicode_prefix}{val}{letter}', end=
'')
112 Defines the console cursor color 116 val - one string from list (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, Reset) 120 0 for success and -1 for error 122 if isinstance(val, str):
124 colors = {
"BLACK":
"\u001b[30m",
126 "GREEN":
"\u001b[32m",
127 "YELLOW":
"\u001b[33m",
128 "BLUE":
"\u001b[34m",
129 "MAGENTA":
"\u001b[35m",
130 "CYAN":
"\u001b[36m",
131 "WHITE":
"\u001b[37m",
132 "RESET":
"\u001b[0m"}
133 if val
in colors.keys():
134 print(colors[val], end=
"")
143 Prints array passed with one element on each line before returning. 147 arr - array of strings to be printed 154 print(f
" {word}", end=
"\n\r")
161 Hide the console cursor. 171 print(
"\u001b[?25l", end=
'')
178 Resets the console cursor to on. 188 print(
"\u001b[?0l", end=
'')
196 @warning {This function is designed to be private, it may be used elswhere if useful hence the lack of attempt to hide} 198 This function sets the curson color as defined on input as well as moving the cursor up as long as the passed position is not currently greater than zero. 202 cursorColor - Colors defined in setColor 203 position - current cursor position 207 position - new position after movement 226 \warning {This function is designed to be private, it may be used elswhere if useful hence the lack of attempt to hide} 228 This function sets the curson color as defined on input as well as moving the cursor down as long as the passed position is not currently at the length of the passed array length. 232 arrL - Length of array printed 233 cursorColor - Colors defined in setColor 234 position - current cursor position 238 position - new position after movement 256 Gets single key input from the user 264 key buffer after press 266 return ord(sys.stdin.read(1))
269 def singleChoice(arr, cursorColor="Blue", textOrVal="Val"):
271 fd = sys.stdin.fileno()
272 old_settings = termios.tcgetattr(fd)
274 tty.setraw(sys.stdin)
286 enter_not_pressed = charIn != 13
287 while enter_not_pressed:
295 position =
onCharUp(cursorColor, position)
297 position =
onDownChar(len(arr)-1, cursorColor, position)
298 enter_not_pressed = charIn != 13
301 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
303 if textOrVal.upper() ==
"TEXT":
309 def multiChoice(arr, cursorColor="Blue", textOrVal="Val", tickOrCross="T", otherColor="Green"):
310 if (len(tickOrCross) > 1):
311 print(
"Error: character " + tickOrCross +
" Too long")
314 fd = sys.stdin.fileno()
315 old_settings = termios.tcgetattr(fd)
317 tty.setraw(sys.stdin)
321 print(
" Done", end=
"\n\r")
335 for i
in range(0, len(arr)):
336 if i
in positionList:
338 if tickOrCross ==
'X':
340 print(
"✗", end=
"\r\n")
341 elif tickOrCross ==
'T':
343 print(
"✓", end=
"\r\n")
346 print(tickOrCross, end=
"\r\n")
350 print(
" ", end=
"\r\n")
354 charIn = ord(sys.stdin.read(1))
357 if position == len(arr):
360 if position
not in positionList:
361 positionList.append(position)
363 positionList.remove(position)
366 charIn = ord(sys.stdin.read(1))
368 charIn = ord(sys.stdin.read(1))
370 position =
onCharUp(cursorColor, position)
372 position =
onDownChar(len(arr), cursorColor, position)
374 print(
"", end=
'\n\r')
376 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
377 if textOrVal.upper() ==
"TEXT":
379 for i
in positionList:
380 posListText.append(arr[i])
def onDownChar(arrL, cursorColor, position)
def print_cursor_value(val, letter)
def onCharUp(cursorColor, position)