term.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:xyppy 作者: theinternetftw 项目源码 文件源码
def fill_to_eol_with_bg_color():
    if is_windows:
        cbuf = CONSOLE_SCREEN_BUFFER_INFO()
        stdout_handle = ctypes.windll.kernel32.GetStdHandle(ctypes.c_ulong(-11))
        ctypes.windll.kernel32.GetConsoleScreenBufferInfo(stdout_handle, ctypes.byref(cbuf))

        cursor = cbuf.dwCursorPosition
        distance = cbuf.srWindow.Right - cursor.X
        # distance > 0 skips x == right to avoid default windows scroll-on-last-col-write behavior
        if distance > 0:
            cbuf = CONSOLE_SCREEN_BUFFER_INFO()
            stdout_handle = ctypes.windll.kernel32.GetStdHandle(ctypes.c_ulong(-11))
            ctypes.windll.kernel32.GetConsoleScreenBufferInfo(stdout_handle, ctypes.byref(cbuf))

            cursor = cbuf.dwCursorPosition
            temp_cursor = COORD()

            written = ctypes.c_uint(0)
            char_attr = ctypes.c_uint16(cbuf.wAttributes)
            space = ctypes.c_char_p(' ')
            for i in range(distance):
                temp_cursor.X = cursor.X + i
                temp_cursor.Y = cursor.Y
                ctypes.windll.kernel32.WriteConsoleOutputAttribute(stdout_handle,
                                                                   ctypes.byref(char_attr),
                                                                   1,
                                                                   temp_cursor,
                                                                   ctypes.byref(written))
                ctypes.windll.kernel32.WriteConsoleOutputCharacterA(stdout_handle,
                                                                    space,
                                                                    1,
                                                                    temp_cursor,
                                                                    ctypes.byref(written))
    else:
        sys.stdout.write('\x1b[K') # insure bg_col covers rest of line
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号