使用python->;curses模块,我体验到一个非常慢的 画/刷新如果我改变字符串颜色属性很多。 我用C++编写了同样的程序,没有问题。 代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses
import locale
# Inint global console config
locale.setlocale(locale.LC_ALL, '')
def main(stdscr):
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_YELLOW, 0)
curses.init_pair(2, curses.COLOR_RED, 0)
max_rows, max_cols = stdscr.getmaxyx()
max_cont = max_rows * max_cols
try:
for i in range(1, max_cont):
stdscr.addstr('█', curses.color_pair(i % 2 + 1))
except curses.ERR:
pass
stdscr.refresh()
stdscr.getch()
curses.wrapper(main)
它很慢,因为程序发送一个转义序列来改变屏幕上每个单元格的颜色。在
也就是说,它不只是发送} ),如下所示:
'█'
(一个3字节的UTF-8字符串),而是另外发送颜色信息。以可读形式(使用^{因为curses会同时为每个单元格写入前景和背景颜色(因为少数终端无法独立完成)。转义序列是10个字节,数据是3个字节,速度慢了大约4倍。在
相关问题 更多 >
编程相关推荐