in ebcli/display/screen.py [0:0]
def prompt_and_action(self, prompt_string, action):
id = ''
t = term.get_terminal()
io.echo(t.normal_cursor(), end='')
# Move cursor to specified empty row
with t.location(y=self.empty_row, x=2), t.cbreak():
io.echo(io.bold(prompt_string), end=' ')
sys.stdout.flush()
val = None
while not val or val.name not in {'KEY_ESCAPE', 'KEY_ENTER'}:
val = t.inkey(timeout=.5)
if val is None:
continue
elif val.is_sequence is False:
id += str(val)
sys.stdout.write(str(val))
sys.stdout.flush()
elif val.name == 'KEY_DELETE': # Backspace
if len(id) > 0:
id = id[:-1]
sys.stdout.write(str(t.move_left) + t.clear_eol)
sys.stdout.flush()
term.hide_cursor()
if val.name == 'KEY_ESCAPE' or not id:
return False
with t.location(y=self.empty_row, x=2):
sys.stdout.flush()
io.echo(t.clear_eol(), end='')
try:
should_exit_display = action(id)
if should_exit_display is None:
should_exit_display = True
return should_exit_display
except (ServiceError, ValidationError, NotFoundError) as e:
# Error messages that should be shown directly to user
io.log_error(e.message)
time.sleep(4) # Leave screen stable for a little
return False
except (IndexError, InvalidOperation, ValueError) as e:
if self.poller.all_app_versions: # Error thrown in versions table
max_input = len(self.poller.all_app_versions)
io.log_error("Enter a number between 1 and " + str(max_input) + ".")
else:
io.log_error(e)
time.sleep(4)
return False
except CaughtSignal as sig:
if sig.signum == 2:
LOG.debug("Caught SIGINT and exiting gracefully from action")
return True
except Exception as e: # Should never get thrown
LOG.debug(
"Exception thrown: {0},{1}. Something strange happened "
"and the request could not be completed.".format(
type(e),
str(e)
)
)
io.log_error("Something strange happened and the request could not be completed.")
time.sleep(4)
return False