Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param message: The prompt message.
:param default: Default `None`. The default input value.
:param characters: Default `None`. Case-insensitive constraint for single-
character input.
"""
if isinstance(default, basestring):
message = "{0} [{1}]".format(message, default)
if characters:
puts("{0} ".format(message), newline=False)
else:
message = "{0}: ".format(message)
while True:
if characters:
ret_val = getch()
if default is not None and ret_val in (chr(CR), chr(LF)):
puts()
ret_val = default
break
if ret_val in characters.lower() or ret_val in characters.upper():
puts()
if ret_val not in characters:
ret_val = ret_val.swapcase()
break
elif isctrl(ret_val) and ctrl(ret_val) in (chr(ETX), chr(EOT)):
raise KeyboardInterrupt()
else:
ret_val = raw_input(message).strip() or default
def key_driver(servo):
"""Drive servos based on keyboard input.
Loops indefinitely until 'q' (quit) is typed.
"""
inc = 5
while True:
keypress = getch.getch()
if keypress == 'q':
go_home(servo)
servo.close()
break
if keypress == 'j':
RANGES[0] += inc
elif keypress == 'l':
RANGES[0] += -1*inc
elif keypress == 'i':
RANGES[1] += inc
elif keypress == 'k':
RANGES[1] += -1*inc
for index, target in enumerate(RANGES):
set_target(servo, index, target)
def pause(message='Press any key to continue . . . '):
"""
Prints the specified message if it's not None and waits for a keypress.
"""
if message is not None:
print(message, end='')
sys.stdout.flush()
getch()
print()
:param default: Default `None`. The default input value.
:param characters: Default `None`. Case-insensitive constraint for single-
character input.
:param echo: Default `True`. Determine if input is echoed.
"""
if default and isinstance(default, basestring):
message = "{0} [{1}]".format(message, default)
if characters:
puts("{0} ".format(message), newline=False)
else:
message = "{0}: ".format(message)
while True:
if characters:
ret_val = getch()
if default is not None and ret_val in (chr(CR), chr(LF)):
puts()
ret_val = default
break
if ret_val in characters.lower() or ret_val in characters.upper():
if echo:
puts(ret_val)
else:
puts()
if ret_val not in characters:
ret_val = ret_val.swapcase()
break
elif isctrl(ret_val) and ctrl(ret_val) in (chr(ETX), chr(EOT)):
def reader():
range0 = 90
range1 = 90
move(1, range0)
move(2, range1)
while True:
keypress = getch.getch()
if keypress == 'j':
range0 += 10
elif keypress == 'l':
range0 += -10
elif keypress == 'i':
range1 += -10
elif keypress == 'k':
range1 += 10
elif keypress == 'q':
break
if range0 > 180:
range0 = 180
elif range0 < 0:
range0 = 0