Skip to content

Commit

Permalink
screen: Add helpers to easy use color by name
Browse files Browse the repository at this point in the history
Added macros which allow easy specify color pair like:

    INIT_COLOR(YELLOW, BLACK);
    COLOR(YELLOW, BLACK);
    COLOR_ON(YELLOW, BLACK);

by calculating pair id via generic formula. Added shorter
color names via new enum.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
vkochan authored and tklauser committed Apr 18, 2016
1 parent e9bd3cd commit ecc2fd7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@

#include <curses.h>

enum colors {
BLACK = COLOR_BLACK,
RED = COLOR_RED,
GREEN = COLOR_GREEN,
YELLOW = COLOR_YELLOW,
BLUE = COLOR_BLUE,
MAGENTA = COLOR_MAGENTA,
CYAN = COLOR_CYAN,
WHITE = COLOR_WHITE,
};

#define COLOR_MASK(fg, bg) ((fg) + (bg) * (COLOR_WHITE + 1))
#define COLOR(fg, bg) COLOR_PAIR(COLOR_MASK((fg), (bg)))
#define INIT_COLOR(fg, bg) init_pair(COLOR_MASK((fg), (bg)), (fg), (bg))
#define COLOR_ON(fg, bg) attron(COLOR(fg, bg))
#define COLOR_OFF(fg, bg) attroff(COLOR(fg, bg))

extern WINDOW *screen_init(bool israw);
extern void screen_end(void);

Expand Down

0 comments on commit ecc2fd7

Please sign in to comment.