Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

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!

Any helps would be greatly appreciated.

like image 554
Cathou Avatar asked Nov 29 '08 01:11

Cathou


People also ask

Does Python curses work on Windows?

The Windows version of Python doesn't include the curses module.

Does curses come with Python?

The curses package comes with the Python standard library. In Linux and Mac, the curses dependencies should already be installed so there is no extra steps needed. On Windows, you need to install one special Python package, windows-curses available on PyPI to add support.


2 Answers

Here's an example code (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.

like image 100
jfs Avatar answered Sep 22 '22 01:09

jfs


I tried this: screen.addstr(text, curses.color_pair(1) | curses.A_BOLD) and it worked!

So just add curses. and it should do the trick. Of course at the beginning use: import curses

like image 25
David Avatar answered Sep 25 '22 01:09

David