(self, s, do_echo=True)
Write a string to the screen at the current position.
Write a string to the screen at the current position.
Write a string to the screen at the current position .
def write(self, s, do_echo=True):
        """Write a string to the screen at the current position."""
        if not s:
            # don't disconnect line wrap if no output
            return
        if do_echo:
            # CR -> CRLF, CRLF -> CRLF LF
            self._io_streams.write(b''.join([(b'\r\n' if c == b'\r' else c) for c in iterchar(s)]))
        last = b''
        # if our line wrapped at the end before, it doesn't anymore
        self._text_screen.set_wrap(self.current_row, False)
        out_chars = []
        for c in iterchar(s):
            if c in b'\t\n\r\a\x0B\x0C\x1C\x1D\x1E\x1F':
                # non-printing or position-dependent chars, dump buffer first
                self._text_screen.write_chars(b''.join(out_chars), do_scroll_down=True)
                out_chars = []
                row, col = self.current_row, self.current_col
                if c == b'\t':
                    # TAB
                    num = (8 - (col - 1 - 8 * int((col-1) // 8)))
                    self._text_screen.write_chars(b' ' * num, do_scroll_down=False)
                elif c == b'\n':
                    # LF
                    # exclude CR/LF
                    if last != b'\r':
                        # LF connects lines like word wrap
                        self._text_screen.set_wrap(row, True)
                        self._text_screen.set_pos(row + 1, 1, scroll_ok=True)
                elif c == b'\r':
                    # CR
                    self._text_screen.set_wrap(row, False)
                    self._text_screen.set_pos(row + 1, 1, scroll_ok=True)
                elif c == b'\a':
                    # BEL
                    self._sound.beep()
                elif c == b'\x0B':
                    # HOME
                    self._text_screen.set_pos(1, 1, scroll_ok=True)
                elif c == b'\x0C':
                    # CLS
                    self._text_screen.clear_view()
                elif c == b'\x1C':
                    # RIGHT
                    self._text_screen.set_pos(row, col + 1, scroll_ok=True)
                elif c == b'\x1D':
                    # LEFT
                    self._text_screen.set_pos(row, col - 1, scroll_ok=True)
                elif c == b'\x1E':
                    # UP
                    self._text_screen.set_pos(row - 1, col, scroll_ok=True)
                elif c == b'\x1F':
                    # DOWN
                    self._text_screen.set_pos(row + 1, col, scroll_ok=True)
            else:
                # includes \b, \0, and non-control chars
                out_chars.append(c)
            last = c
        self._text_screen.write_chars(b''.join(out_chars), do_scroll_down=True)
def write ( self , s , do_echo = True ) : if not s : # don't disconnect line wrap if no output return if do_echo : # CR -> CRLF, CRLF -> CRLF LF self . _io_streams . write ( b'' . join ( [ ( b'\r\n' if c == b'\r' else c ) for c in iterchar ( s ) ] ) ) last = b'' # if our line wrapped at the end before, it doesn't anymore self . _text_screen . set_wrap ( self . current_row , False ) out_chars = [ ] for c in iterchar ( s ) : if c in b'\t\n\r\a\x0B\x0C\x1C\x1D\x1E\x1F' : # non-printing or position-dependent chars, dump buffer first self . _text_screen . write_chars ( b'' . join ( out_chars ) , do_scroll_down = True ) out_chars = [ ] row , col = self . current_row , self . current_col if c == b'\t' : # TAB num = ( 8 - ( col - 1 - 8 * int ( ( col - 1 ) // 8 ) ) ) self . _text_screen . write_chars ( b' ' * num , do_scroll_down = False ) elif c == b'\n' : # LF # exclude CR/LF if last != b'\r' : # LF connects lines like word wrap self . _text_screen . set_wrap ( row , True ) self . _text_screen . set_pos ( row + 1 , 1 , scroll_ok = True ) elif c == b'\r' : # CR self . _text_screen . set_wrap ( row , False ) self . _text_screen . set_pos ( row + 1 , 1 , scroll_ok = True ) elif c == b'\a' : # BEL self . _sound . beep ( ) elif c == b'\x0B' : # HOME self . _text_screen . set_pos ( 1 , 1 , scroll_ok = True ) elif c == b'\x0C' : # CLS self . _text_screen . clear_view ( ) elif c == b'\x1C' : # RIGHT self . _text_screen . set_pos ( row , col + 1 , scroll_ok = True ) elif c == b'\x1D' : # LEFT self . _text_screen . set_pos ( row , col - 1 , scroll_ok = True ) elif c == b'\x1E' : # UP self . _text_screen . set_pos ( row - 1 , col , scroll_ok = True ) elif c == b'\x1F' : # DOWN self . _text_screen . set_pos ( row + 1 , col , scroll_ok = True ) else : # includes \b, \0, and non-control chars out_chars . append ( c ) last = c self . _text_screen . write_chars ( b'' . join ( out_chars ) , do_scroll_down = True )