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()
def puts(self, text): """ Prints the supplied text, handling special character codes for carriage return (\\r), newline (\\n), backspace (\\b) and tab (\\t). ANSI color codes are also supported. If the ``animate`` flag was set to True (default), then each character is flushed to the device, giving the effect of 1970's teletype device. :type text: str """ for method, args in ansi_color.find_directives(text, self): method(*args)