Exemplo n.º 1
0
    def println(self, text=""):
        """
        Prints the supplied text to the device, scrolling where necessary.
        The text is always followed by a newline.

        :param text: The text to print.
        :type text: str
        """
        if self.word_wrap:
            # find directives in complete text
            directives = ansi_color.find_directives(text, self)

            # strip ansi from text
            clean_text = ansi_color.strip_ansi_codes(text)

            # wrap clean text
            clean_lines = self.tw.wrap(clean_text)

            # print wrapped text
            index = 0
            for line in clean_lines:
                line_length = len(line)
                y = 0
                while y < line_length:
                    method, args = directives[index]
                    if method == self.putch:
                        y += 1
                    method(*args)
                    index += 1
                self.newline()
        else:
            self.puts(text)
            self.newline()
Exemplo n.º 2
0
def test_strip_ansi_codes():
    gen = ansi_color.strip_ansi_codes("hello \033[27mworld")
    assert gen == "hello world"