X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=viewer.c;h=a97e44dc4bdb185d93aff60784571934d5deffd7;hb=d1a7b3c065e6f6d4839cc6107284f3e715d6f7ab;hp=c4e6b90f93849cb2284b5b29d45da6ca9ced5a6e;hpb=b0159e9e6cdf21c13cb94387146301aa000726c7;p=smdp.git diff --git a/viewer.c b/viewer.c index c4e6b90..a97e44d 100644 --- a/viewer.c +++ b/viewer.c @@ -81,16 +81,13 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) { // set locale to display UTF-8 correctly in ncurses setlocale(LC_CTYPE, ""); - // replace stdin with current tty if markdown input was piped - freopen("/dev/tty", "rw", stdin); - // init ncurses initscr(); if((max_cols > COLS) || (max_lines + bar_top + bar_bottom + 2 > LINES)) { - fprintf(stderr, "Error: Terminal size %ix%i to small. Need at least %ix%i.\n", + fprintf(stderr, "Error: Terminal size %ix%i too small. Need at least %ix%i.\n", COLS, LINES, max_cols, max_lines + bar_top + bar_bottom + 2); endwin(); return(1); @@ -191,7 +188,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 +308,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 +337,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 +391,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 +415,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 +442,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 +460,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); }