Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]
# The parens make this a capturing expression, so the tokens will be
# included in re.split()'s return list.
token_expr = '(' + '|'.join(re.escape(token) for token in tokens) + ')'
pieces = re.split(token_expr, string)
for piece in pieces:
if piece in (display.ANSI_DISABLE_LINE_WRAP,
display.ANSI_ENABLE_LINE_WRAP):
# Ignore the line wrap codes. TODO: Test for these?
continue
elif piece == display.ANSI_CLEAR_LINE:
buffer = self.lines[self.cursor_line]
buffer.seek(0)
buffer.truncate()
elif piece == display.ANSI_CURSOR_UP_ONE_LINE:
col = self.lines[self.cursor_line].tell()
self.cursor_line -= 1
assert self.cursor_line >= 0
new_buffer = self.lines[self.cursor_line]
new_buffer.seek(col)
elif piece == '\n':
self.cursor_line += 1
if self.cursor_line == len(self.lines):
self.lines.append(io.StringIO())
self.lines[self.cursor_line].seek(0)
else:
self.lines[self.cursor_line].write(piece)
def write(self, string):
tokens = [
display.ANSI_DISABLE_LINE_WRAP, display.ANSI_ENABLE_LINE_WRAP,
display.ANSI_CLEAR_LINE, display.ANSI_CURSOR_UP_ONE_LINE, '\n'
]
# The parens make this a capturing expression, so the tokens will be
# included in re.split()'s return list.
token_expr = '(' + '|'.join(re.escape(token) for token in tokens) + ')'
pieces = re.split(token_expr, string)
for piece in pieces:
if piece in (display.ANSI_DISABLE_LINE_WRAP,
display.ANSI_ENABLE_LINE_WRAP):
# Ignore the line wrap codes. TODO: Test for these?
continue
elif piece == display.ANSI_CLEAR_LINE:
buffer = self.lines[self.cursor_line]
buffer.seek(0)
buffer.truncate()
elif piece == display.ANSI_CURSOR_UP_ONE_LINE:
col = self.lines[self.cursor_line].tell()
self.cursor_line -= 1
assert self.cursor_line >= 0
new_buffer = self.lines[self.cursor_line]
new_buffer.seek(col)
elif piece == '\n':
self.cursor_line += 1
if self.cursor_line == len(self.lines):
self.lines.append(io.StringIO())
self.lines[self.cursor_line].seek(0)
else:
self.lines[self.cursor_line].write(piece)
def write(self, string):
tokens = [
display.ANSI_DISABLE_LINE_WRAP, display.ANSI_ENABLE_LINE_WRAP,
display.ANSI_CLEAR_LINE, display.ANSI_CURSOR_UP_ONE_LINE, '\n'
]
# The parens make this a capturing expression, so the tokens will be
# included in re.split()'s return list.
token_expr = '(' + '|'.join(re.escape(token) for token in tokens) + ')'
pieces = re.split(token_expr, string)
for piece in pieces:
if piece in (display.ANSI_DISABLE_LINE_WRAP,
display.ANSI_ENABLE_LINE_WRAP):
# Ignore the line wrap codes. TODO: Test for these?
continue
elif piece == display.ANSI_CLEAR_LINE:
buffer = self.lines[self.cursor_line]
buffer.seek(0)
buffer.truncate()
def write(self, string):
tokens = [
display.ANSI_DISABLE_LINE_WRAP, display.ANSI_ENABLE_LINE_WRAP,
display.ANSI_CLEAR_LINE, display.ANSI_CURSOR_UP_ONE_LINE, '\n'
]
# The parens make this a capturing expression, so the tokens will be
# included in re.split()'s return list.
token_expr = '(' + '|'.join(re.escape(token) for token in tokens) + ')'
pieces = re.split(token_expr, string)
for piece in pieces:
if piece in (display.ANSI_DISABLE_LINE_WRAP,
display.ANSI_ENABLE_LINE_WRAP):
# Ignore the line wrap codes. TODO: Test for these?
continue
elif piece == display.ANSI_CLEAR_LINE:
buffer = self.lines[self.cursor_line]
buffer.seek(0)
buffer.truncate()
elif piece == display.ANSI_CURSOR_UP_ONE_LINE:
col = self.lines[self.cursor_line].tell()
self.cursor_line -= 1
assert self.cursor_line >= 0
new_buffer = self.lines[self.cursor_line]
new_buffer.seek(col)
elif piece == '\n':
self.cursor_line += 1
if self.cursor_line == len(self.lines):
def test_quiet_display(self):
output = io.StringIO()
disp = display.QuietDisplay(output)
with disp.get_handle('title') as handle:
handle.write('some stuff!')
disp.print('other stuff?')
self.assertEqual('other stuff?\n', output.getvalue())
def test_fancy_display(self):
output = FakeTerminal()
disp = display.FancyDisplay(output)
handle1 = disp.get_handle('title1')
handle1.__enter__()
handle1.write('something1')
disp._draw()
# We need to test trailing spaces, and the '# noqa: W291' tag stops the
# linter from complaining about these.
expected1 = textwrap.dedent('''\
╶ title1: something1
''') # noqa: W291
self.assertEqual(expected1, output.getlines())
handle2 = disp.get_handle('title2')
handle2.__enter__()
handle2.write('something2')
disp._draw()
def get_display(args):
if args['--quiet']:
return display.QuietDisplay()
elif args['--verbose']:
return display.VerboseDisplay()
elif compat.is_fancy_terminal():
return display.FancyDisplay()
else:
return display.QuietDisplay()
def get_display(args):
if args['--quiet']:
return display.QuietDisplay()
elif args['--verbose']:
return display.VerboseDisplay()
elif compat.is_fancy_terminal():
return display.FancyDisplay()
else:
return display.QuietDisplay()
def get_display(args):
if args['--quiet']:
return display.QuietDisplay()
elif args['--verbose']:
return display.VerboseDisplay()
elif compat.is_fancy_terminal():
return display.FancyDisplay()
else:
return display.QuietDisplay()