""" ``astyle`` provides classes for adding style (foreground and background color; bold; blink; etc.) to terminal and curses output. """ import sys, os try: import curses except ImportError: curses = None COLOR_BLACK = 0 COLOR_RED = 1 COLOR_GREEN = 2 COLOR_YELLOW = 3 COLOR_BLUE = 4 COLOR_MAGENTA = 5 COLOR_CYAN = 6 COLOR_WHITE = 7 A_BLINK = 1<<0 # Blinking text A_BOLD = 1<<1 # Extra bright or bold text A_DIM = 1<<2 # Half bright text A_REVERSE = 1<<3 # Reverse-video text A_STANDOUT = 1<<4 # The best highlighting mode available A_UNDERLINE = 1<<5 # Underlined text class Style(object): """ Store foreground color, background color and attribute (bold, underlined etc.). """ __slots__ = ("fg", "bg", "attrs") COLORNAMES = { "black": COLOR_BLACK, "red": COLOR_RED, "green": COLOR_GREEN, "yellow": COLOR_YELLOW, "blue": COLOR_BLUE, "magenta": COLOR_MAGENTA, "cyan": COLOR_CYAN, "white": COLOR_WHITE, } ATTRNAMES = { "blink": A_BLINK, "bold": A_BOLD, "dim": A_DIM, "reverse": A_REVERSE, "standout": A_STANDOUT, "underline": A_UNDERLINE, } def __init__(self, fg, bg, attrs=0): """ Create a ``Style`` object with ``fg`` as the foreground color, ``bg`` as the background color and ``attrs`` as the attributes. Examples: >>> Style(COLOR_RED, COLOR_BLACK)