Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_output_content(self, output):
output.get_stream().seek(0)
value = output.get_stream().getvalue()
return decode(value).replace(os.linesep, "\n")
def get_output_content(self, output):
output.get_stream().seek(0)
value = output.get_stream().getvalue()
return decode(value)
def _write_error(self, output, error):
"""
Outputs an error message.
:param output: An Output instance
:type output: Output
:param error: A Exception instance
:type error: Exception
"""
if self.helper_set is not None and self.helper_set.has('formatter'):
message = self.helper_set.get('formatter').format_block(decode(str(error)), 'error')
else:
message = '%s' % decode(str(error))
output.writeln(message)
if value.startswith(ret) and i != len(value):
num_matches += 1
matches[num_matches - 1] = value
# Erase characters from cursor to end of line
output.write('\033[K')
if num_matches > 0 and ofs != -1:
# Save cursor position
output.write('\0337')
# Write highlighted text
output.write('' + matches[ofs][i:] + '')
# Restore cursor position
output.write('\0338')
subprocess.call(['stty', '%s' % decode(stty_mode)])
return ret
def _write_error(self, output, error):
"""
Outputs an error message.
:param output: An Output instance
:type output: Output
:param error: A Exception instance
:type error: Exception
"""
if self.helper_set is not None and self.helper_set.has('formatter'):
message = self.helper_set.get('formatter').format_block(decode(str(error)), 'error')
else:
message = '%s' % decode(str(error))
output.writeln(message)
:param question: The question to ask
:type question: Question
:rtype: str
"""
autocomplete = question.autocompleter_values
ret = ''
i = 0
ofs = -1
matches = [x for x in autocomplete]
num_matches = len(matches)
stty_mode = decode(subprocess.check_output(['stty', '-g'])).rstrip('\n')
# Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
subprocess.check_output(['stty', '-icanon', '-echo'])
# Add highlighted text style
output.get_formatter().add_style('hl', 'black', 'white')
# Read a keypress
while True:
c = input_stream.read(1)
# Backspace character
if c == '\177':
if num_matches == 0 and i != 0:
i -= 1
# Move cursor backwards
"""
Read user input.
:param stream: The input stream
:return:
"""
if stream == sys.stdin:
ret = stream.readline()
else:
ret = stream.readline(4096)
if not ret:
raise RuntimeError('Aborted')
return decode(ret.strip())