How to use the peru.display function in peru

To help you get started, we’ve selected a few peru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildinspace / peru / tests / test_display.py View on Github external
]
        # 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)
github buildinspace / peru / tests / test_display.py View on Github external
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)
github buildinspace / peru / tests / test_display.py View on Github external
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()
github buildinspace / peru / tests / test_display.py View on Github external
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):
github buildinspace / peru / tests / test_display.py View on Github external
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())
github buildinspace / peru / tests / test_display.py View on Github external
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()
github buildinspace / peru / peru / runtime.py View on Github external
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()
github buildinspace / peru / peru / runtime.py View on Github external
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()
github buildinspace / peru / peru / runtime.py View on Github external
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()