From: Michael Göhler Date: Mon, 15 Sep 2014 21:56:16 +0000 (+0200) Subject: only use colors if supported X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=4cee0c886689978678fa39a275529fceb30106a8;p=smdp.git only use colors if supported --- diff --git a/include/viewer.h b/include/viewer.h index e368615..5175414 100644 --- a/include/viewer.h +++ b/include/viewer.h @@ -45,7 +45,7 @@ #define FADE_DELAY 15000 // micro seconds int ncurses_display(deck_t *deck, int notrans, int nofade); -void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols); +void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors); void fade_out(WINDOW *window, int trans, int colors); void fade_in(WINDOW *window, int trans, int colors); int int_length (int val); diff --git a/viewer.c b/viewer.c index c4e6b90..fd62cff 100644 --- a/viewer.c +++ b/viewer.c @@ -191,7 +191,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { // print lines while(line) { - add_line(content, l, (COLS - max_cols) / 2, line, max_cols); + add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors); line = line->next; l++; } @@ -311,7 +311,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { return(0); } -void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) { +void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) { int i = 0; // increment char *c; // char pointer for iteration char *special = "\\*_"; // list of interpreted chars @@ -340,7 +340,8 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) { if(CHECK_BIT(line->bits, IS_H1) || CHECK_BIT(line->bits, IS_H2)) { // set headline color - wattron(window, COLOR_PAIR(CP_BLUE)); + if(colors) + wattron(window, COLOR_PAIR(CP_BLUE)); // enable underline for H1 if(CHECK_BIT(line->bits, IS_H1)) @@ -393,7 +394,8 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) { break; // disable highlight case '*': - wattron(window, COLOR_PAIR(CP_WHITE)); + if(colors) + wattron(window, COLOR_PAIR(CP_WHITE)); break; // disable underline case '_': @@ -416,7 +418,8 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) { switch(*c) { // enable highlight case '*': - wattron(window, COLOR_PAIR(CP_RED)); + if(colors) + wattron(window, COLOR_PAIR(CP_RED)); break; // enable underline case '_': @@ -442,7 +445,8 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) { switch((stack->pop)(stack)) { // disable highlight case '*': - wattron(window, COLOR_PAIR(CP_WHITE)); + if(colors) + wattron(window, COLOR_PAIR(CP_WHITE)); break; // disable underline case '_': @@ -459,7 +463,8 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) { wprintw(window, "%s", " "); // reset to default color - wattron(window, COLOR_PAIR(CP_WHITE)); + if(colors) + wattron(window, COLOR_PAIR(CP_WHITE)); wattroff(window, A_UNDERLINE); wattroff(window, A_REVERSE); }