(cls, handle, unistr)
Write character to console, avoid scroll on bottom line.
Write character to console, avoid scroll on bottom line.
Write character to console avoid scroll on bottom line .
def write(cls, handle, unistr):
        """Write character to console, avoid scroll on bottom line."""
        csbi = CONSOLE_SCREEN_BUFFER_INFO()
        _GetConsoleScreenBufferInfo(handle, byref(csbi))
        col, row = csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y
        width, height = csbi.dwSize.X, csbi.dwSize.Y
        for ch in unistr:
            if (col >= width - 1 and ch not in (u'\n', u'\b', u'\r') and not cls._overflow):
                ci = CHAR_INFO(ch, csbi.wAttributes)
                # do not advance cursor if we're on the last position of the
                # screen buffer, to avoid unwanted scrolling.
                _WriteConsoleOutputW(
                    handle, byref(ci), wintypes._COORD(1, 1), wintypes._COORD(0, 0),
                    wintypes.SMALL_RECT(col, row, col, row)
                )
            else:
                if cls._overflow and ch not in (u'\n', u'\r', u'\b'):
                    _WriteConsoleW(
                        handle, u'\r\n', 1,
                        byref(wintypes.DWORD()), byref(wintypes.DWORD())
                    )
                    col = 0
                    cls._overflow = False
                _WriteConsoleW(
                    handle, ch, 1,
                    byref(wintypes.DWORD()), byref(wintypes.DWORD())
                )
            # if we don't include \n here we get glitches on regular console writes
            # is it necessary to treat CR and LF separately *in raw mode*?
            # i.e. in raw mode,  shouldn't LF just move a line down without changing the column?
            if ch in (u'\r', u'\n'):
                col = 0
                cls._overflow = False
            elif ch == u'\b':
                col = max(col-1, 0)
                cls._overflow = False
            else:
                col = min(col+1, width-1)
def write ( cls , handle , unistr ) : csbi = CONSOLE_SCREEN_BUFFER_INFO ( ) _GetConsoleScreenBufferInfo ( handle , byref ( csbi ) ) col , row = csbi . dwCursorPosition . X , csbi . dwCursorPosition . Y width , height = csbi . dwSize . X , csbi . dwSize . Y for ch in unistr : if ( col >= width - 1 and ch not in ( u'\n' , u'\b' , u'\r' ) and not cls . _overflow ) : ci = CHAR_INFO ( ch , csbi . wAttributes ) # do not advance cursor if we're on the last position of the # screen buffer, to avoid unwanted scrolling. _WriteConsoleOutputW ( handle , byref ( ci ) , wintypes . _COORD ( 1 , 1 ) , wintypes . _COORD ( 0 , 0 ) , wintypes . SMALL_RECT ( col , row , col , row ) ) else : if cls . _overflow and ch not in ( u'\n' , u'\r' , u'\b' ) : _WriteConsoleW ( handle , u'\r\n' , 1 , byref ( wintypes . DWORD ( ) ) , byref ( wintypes . DWORD ( ) ) ) col = 0 cls . _overflow = False _WriteConsoleW ( handle , ch , 1 , byref ( wintypes . DWORD ( ) ) , byref ( wintypes . DWORD ( ) ) ) # if we don't include \n here we get glitches on regular console writes # is it necessary to treat CR and LF separately *in raw mode*? # i.e. in raw mode,  shouldn't LF just move a line down without changing the column? if ch in ( u'\r' , u'\n' ) : col = 0 cls . _overflow = False elif ch == u'\b' : col = max ( col - 1 , 0 ) cls . _overflow = False else : col = min ( col + 1 , width - 1 )