diff --git a/include/main.h b/include/main.h index 7f51e92..34c1386 100644 --- a/include/main.h +++ b/include/main.h @@ -25,6 +25,6 @@ #define MDP_VER_MAJOR 1 #define MDP_VER_MINOR 0 -#define MDP_VER_REVISION 14 +#define MDP_VER_REVISION 15 #endif // !defined( MAIN_H ) diff --git a/include/viewer.h b/include/viewer.h index 1405e07..1b2b509 100644 --- a/include/viewer.h +++ b/include/viewer.h @@ -55,9 +55,9 @@ #define FADE_DELAY 15000 // micro seconds #define GOTO_SLIDE_DELAY 5 // tenths of seconds -int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum); -void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors); -void inline_display(WINDOW *window, const wchar_t *c, const int colors); +int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum, int nocodebg); +void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors, int nocodebg); +void inline_display(WINDOW *window, const wchar_t *c, const int colors, int nocodebg); void fade_out(WINDOW *window, int trans, int colors, int invert); void fade_in(WINDOW *window, int trans, int colors, int invert); int int_length (int val); diff --git a/src/main.c b/src/main.c index f9d554f..3279400 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ fprintf(stderr, "%s", " -s, --noslidenum do not show slide number at the bottom\n"); fprintf(stderr, "%s", " -v, --version display the version number and license\n"); fprintf(stderr, "%s", " -x, --noslidemax show slide number, but not total number of slides\n"); + fprintf(stderr, "%s", " -c, --nocodebg don't change the background color of code blocks\n"); fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n"); exit(EXIT_FAILURE); } @@ -61,6 +62,7 @@ int reload = 0; // reload page N (0 means no reload) int noreload = 1; // reload disabled until we know input is a file int slidenum = 2; // 0:don't show; 1:show #; 2:show #/# + int nocodebg = 0; // 0:show code bg as inverted; 1: don't invert code bg // define command-line options struct option longopts[] = { @@ -73,12 +75,13 @@ { "version", no_argument, 0, 'v' }, { "noslidenum", no_argument, 0, 's' }, { "noslidemax", no_argument, 0, 'x' }, + { "nocodebg", no_argument, 0, 'c' }, { 0, 0, 0, 0 } }; // parse command-line options int opt, debug = 0; - while ((opt = getopt_long(argc, argv, ":defhitvsx", longopts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, ":defhitvsxc", longopts, NULL)) != -1) { switch(opt) { case 'd': debug += 1; break; case 'e': noexpand = 0; break; @@ -89,6 +92,7 @@ case 'v': version(); break; case 's': slidenum = 0; break; case 'x': slidenum = 1; break; + case 'c': nocodebg = 1; break; case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break; case '?': default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break; @@ -163,7 +167,7 @@ markdown_debug(deck, debug); } - reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum); + reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum, nocodebg); free_deck(deck); diff --git a/src/viewer.c b/src/viewer.c index 2cf5911..1a3ac00 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -73,7 +73,7 @@ static const char *list_head2 = " +- "; static const char *list_head3 = " +- "; -int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum) { +int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum, int nocodebg) { int c = 0; // char int i = 0; // iterate @@ -339,7 +339,7 @@ // print lines while(line) { add_line(content, l + ((LINES - slide->lines_consumed - bar_top - bar_bottom) / 2), - (COLS - max_cols) / 2, line, max_cols, colors); + (COLS - max_cols) / 2, line, max_cols, colors, nocodebg); // raise stop counter if we pass a line having a stop bit if(CHECK_BIT(line->bits, IS_STOP)) @@ -565,7 +565,7 @@ } } -void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) { +void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors, int nocodebg) { int i; // increment int offset = 0; // text offset @@ -577,7 +577,7 @@ // fill rest off line with spaces if we are in a code block if(CHECK_BIT(line->bits, IS_CODE) && colors) { - if(colors) + if(colors && !nocodebg) wattron(window, COLOR_PAIR(CP_BLACK)); for(i = getcurx(window) - x; i < max_cols; i++) wprintw(window, "%s", " "); @@ -611,7 +611,7 @@ "%s", prompt); if(!CHECK_BIT(line->bits, IS_CODE)) - inline_display(window, &line->text->value[offset], colors); + inline_display(window, &line->text->value[offset], colors, nocodebg); // IS_UNORDERED_LIST_2 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) { @@ -634,7 +634,7 @@ "%s", prompt); if(!CHECK_BIT(line->bits, IS_CODE)) - inline_display(window, &line->text->value[offset], colors); + inline_display(window, &line->text->value[offset], colors, nocodebg); // IS_UNORDERED_LIST_1 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) { @@ -652,7 +652,7 @@ "%s", prompt); if(!CHECK_BIT(line->bits, IS_CODE)) - inline_display(window, &line->text->value[offset], colors); + inline_display(window, &line->text->value[offset], colors, nocodebg); } // IS_CODE @@ -665,7 +665,7 @@ } // reverse color for code blocks - if(colors) + if(colors && !nocodebg) wattron(window, COLOR_PAIR(CP_BLACK)); // print whole lines @@ -696,7 +696,7 @@ offset = next_word(line->text, offset); } - inline_display(window, &line->text->value[offset], colors); + inline_display(window, &line->text->value[offset], colors, nocodebg); } else { // IS_CENTER @@ -729,7 +729,7 @@ // no line-wide markdown } else { - inline_display(window, &line->text->value[offset], colors); + inline_display(window, &line->text->value[offset], colors, nocodebg); } } } @@ -747,7 +747,7 @@ wattroff(window, A_UNDERLINE); } -void inline_display(WINDOW *window, const wchar_t *c, const int colors) { +void inline_display(WINDOW *window, const wchar_t *c, const int colors, int nocodebg) { const static wchar_t *special = L"\\*_`!["; // list of interpreted chars const wchar_t *i = c; // iterator const wchar_t *start_link_name, *start_url; @@ -865,7 +865,7 @@ break; // enable inline code case L'`': - if(colors) + if(colors && !nocodebg) wattron(window, COLOR_PAIR(CP_BLACK)); break; // do nothing for backslashes