term.py 文件源码

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

项目:xyppy 作者: theinternetftw 项目源码 文件源码
def set_color(fg_col, bg_col):
    global last_fg_col
    global last_bg_col
    if fg_col == last_fg_col and bg_col == last_bg_col:
        return
    last_fg_col = fg_col
    last_bg_col = bg_col
    if is_windows:
        # convert from (rgb+2) to bgr
        fg_col = rgb3_to_bgr3(fg_col-2)
        bg_col = rgb3_to_bgr3(bg_col-2)
        col_attr = fg_col | (bg_col << 4)
        stdout_handle = ctypes.windll.kernel32.GetStdHandle(ctypes.c_ulong(-11))
        ctypes.windll.kernel32.SetConsoleTextAttribute(stdout_handle, col_attr)
    else:
        color = str(fg_col + 28)
        sys.stdout.write('\x1b['+color+'m')
        color = str(bg_col + 38)
        sys.stdout.write('\x1b['+color+'m')

# TODO: any other encodings to check for?
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号