[英]Attribute BOLD doesn't seem to work in my curses
I use something like this: screen.addstr(text, color_pair(1) | A_BOLD), but it doesn't seem to work.. However, A_REVERSE and all others attribute does work! 我使用这样的东西:screen.addstr(text,color_pair(1)| A_BOLD),但它似乎不起作用..但是,A_REVERSE和所有其他属性确实有效!
In fact, I'm trying to print something in white, but the COLOR_WHITE prints it gray.. and after a while of searching, it seems that printing it gray + BOLD makes it! 事实上,我正在尝试用白色打印一些东西,但是COLOR_WHITE将它打印成灰色..经过一段时间的搜索,似乎将它打印成灰色+ BOLD就可以了!
Any helps would be greatly appreciated. 任何帮助将不胜感激。
Here's an example code (Python 2.6, Linux): 这是一个示例代码(Python 2.6,Linux):
#!/usr/bin/env python
from itertools import cycle
import curses, contextlib, time
@contextlib.contextmanager
def curses_screen():
"""Contextmanager's version of curses.wrapper()."""
try:
stdscr=curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
try: curses.start_color()
except: pass
yield stdscr
finally:
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
if __name__=="__main__":
with curses_screen() as stdscr:
c = curses.A_BOLD
if curses.has_colors():
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
c |= curses.color_pair(1)
curses.curs_set(0) # make cursor invisible
y, x = stdscr.getmaxyx()
for col in cycle((c, curses.A_BOLD)):
stdscr.erase()
stdscr.addstr(y//2, x//2, 'abc', col)
stdscr.refresh()
time.sleep(1)
All seems to be working. 一切似乎都在起作用。
I tried this: screen.addstr(text, curses.color_pair(1) | curses.A_BOLD)
and it worked! 我试过这个:
screen.addstr(text, curses.color_pair(1) | curses.A_BOLD)
并且它有效!
So just add curses.
所以只需添加
curses.
and it should do the trick. 它应该做的伎俩。 Of course at the beginning use:
import curses
当然在开始时使用:
import curses
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.