Update upstream source from tag 'upstream/1.0.15'
Update to upstream version '1.0.15'
with Debian dir 683aa6029d9768f12f8afaafc31f8b858f681e17
Lev Lamberov
4 years ago
24 | 24 | |
25 | 25 | #define MDP_VER_MAJOR 1 |
26 | 26 | #define MDP_VER_MINOR 0 |
27 | #define MDP_VER_REVISION 14 | |
27 | #define MDP_VER_REVISION 15 | |
28 | 28 | |
29 | 29 | #endif // !defined( MAIN_H ) |
54 | 54 | #define FADE_DELAY 15000 // micro seconds |
55 | 55 | #define GOTO_SLIDE_DELAY 5 // tenths of seconds |
56 | 56 | |
57 | int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum); | |
58 | void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors); | |
59 | void inline_display(WINDOW *window, const wchar_t *c, const int colors); | |
57 | int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum, int nocodebg); | |
58 | void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors, int nocodebg); | |
59 | void inline_display(WINDOW *window, const wchar_t *c, const int colors, int nocodebg); | |
60 | 60 | void fade_out(WINDOW *window, int trans, int colors, int invert); |
61 | 61 | void fade_in(WINDOW *window, int trans, int colors, int invert); |
62 | 62 | int int_length (int val); |
38 | 38 | fprintf(stderr, "%s", " -s, --noslidenum do not show slide number at the bottom\n"); |
39 | 39 | fprintf(stderr, "%s", " -v, --version display the version number and license\n"); |
40 | 40 | fprintf(stderr, "%s", " -x, --noslidemax show slide number, but not total number of slides\n"); |
41 | fprintf(stderr, "%s", " -c, --nocodebg don't change the background color of code blocks\n"); | |
41 | 42 | fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n"); |
42 | 43 | exit(EXIT_FAILURE); |
43 | 44 | } |
60 | 61 | int reload = 0; // reload page N (0 means no reload) |
61 | 62 | int noreload = 1; // reload disabled until we know input is a file |
62 | 63 | int slidenum = 2; // 0:don't show; 1:show #; 2:show #/# |
64 | int nocodebg = 0; // 0:show code bg as inverted; 1: don't invert code bg | |
63 | 65 | |
64 | 66 | // define command-line options |
65 | 67 | struct option longopts[] = { |
72 | 74 | { "version", no_argument, 0, 'v' }, |
73 | 75 | { "noslidenum", no_argument, 0, 's' }, |
74 | 76 | { "noslidemax", no_argument, 0, 'x' }, |
77 | { "nocodebg", no_argument, 0, 'c' }, | |
75 | 78 | { 0, 0, 0, 0 } |
76 | 79 | }; |
77 | 80 | |
78 | 81 | // parse command-line options |
79 | 82 | int opt, debug = 0; |
80 | while ((opt = getopt_long(argc, argv, ":defhitvsx", longopts, NULL)) != -1) { | |
83 | while ((opt = getopt_long(argc, argv, ":defhitvsxc", longopts, NULL)) != -1) { | |
81 | 84 | switch(opt) { |
82 | 85 | case 'd': debug += 1; break; |
83 | 86 | case 'e': noexpand = 0; break; |
88 | 91 | case 'v': version(); break; |
89 | 92 | case 's': slidenum = 0; break; |
90 | 93 | case 'x': slidenum = 1; break; |
94 | case 'c': nocodebg = 1; break; | |
91 | 95 | case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break; |
92 | 96 | case '?': |
93 | 97 | default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break; |
162 | 166 | markdown_debug(deck, debug); |
163 | 167 | } |
164 | 168 | |
165 | reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum); | |
169 | reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum, nocodebg); | |
166 | 170 | |
167 | 171 | free_deck(deck); |
168 | 172 |
72 | 72 | static const char *list_head2 = " +- "; |
73 | 73 | static const char *list_head3 = " +- "; |
74 | 74 | |
75 | int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum) { | |
75 | int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload, int slidenum, int nocodebg) { | |
76 | 76 | |
77 | 77 | int c = 0; // char |
78 | 78 | int i = 0; // iterate |
338 | 338 | // print lines |
339 | 339 | while(line) { |
340 | 340 | add_line(content, l + ((LINES - slide->lines_consumed - bar_top - bar_bottom) / 2), |
341 | (COLS - max_cols) / 2, line, max_cols, colors); | |
341 | (COLS - max_cols) / 2, line, max_cols, colors, nocodebg); | |
342 | 342 | |
343 | 343 | // raise stop counter if we pass a line having a stop bit |
344 | 344 | if(CHECK_BIT(line->bits, IS_STOP)) |
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
567 | void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) { | |
567 | void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors, int nocodebg) { | |
568 | 568 | |
569 | 569 | int i; // increment |
570 | 570 | int offset = 0; // text offset |
576 | 576 | |
577 | 577 | // fill rest off line with spaces if we are in a code block |
578 | 578 | if(CHECK_BIT(line->bits, IS_CODE) && colors) { |
579 | if(colors) | |
579 | if(colors && !nocodebg) | |
580 | 580 | wattron(window, COLOR_PAIR(CP_BLACK)); |
581 | 581 | for(i = getcurx(window) - x; i < max_cols; i++) |
582 | 582 | wprintw(window, "%s", " "); |
610 | 610 | "%s", prompt); |
611 | 611 | |
612 | 612 | if(!CHECK_BIT(line->bits, IS_CODE)) |
613 | inline_display(window, &line->text->value[offset], colors); | |
613 | inline_display(window, &line->text->value[offset], colors, nocodebg); | |
614 | 614 | |
615 | 615 | // IS_UNORDERED_LIST_2 |
616 | 616 | } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) { |
633 | 633 | "%s", prompt); |
634 | 634 | |
635 | 635 | if(!CHECK_BIT(line->bits, IS_CODE)) |
636 | inline_display(window, &line->text->value[offset], colors); | |
636 | inline_display(window, &line->text->value[offset], colors, nocodebg); | |
637 | 637 | |
638 | 638 | // IS_UNORDERED_LIST_1 |
639 | 639 | } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) { |
651 | 651 | "%s", prompt); |
652 | 652 | |
653 | 653 | if(!CHECK_BIT(line->bits, IS_CODE)) |
654 | inline_display(window, &line->text->value[offset], colors); | |
654 | inline_display(window, &line->text->value[offset], colors, nocodebg); | |
655 | 655 | } |
656 | 656 | |
657 | 657 | // IS_CODE |
664 | 664 | } |
665 | 665 | |
666 | 666 | // reverse color for code blocks |
667 | if(colors) | |
667 | if(colors && !nocodebg) | |
668 | 668 | wattron(window, COLOR_PAIR(CP_BLACK)); |
669 | 669 | |
670 | 670 | // print whole lines |
695 | 695 | offset = next_word(line->text, offset); |
696 | 696 | } |
697 | 697 | |
698 | inline_display(window, &line->text->value[offset], colors); | |
698 | inline_display(window, &line->text->value[offset], colors, nocodebg); | |
699 | 699 | } else { |
700 | 700 | |
701 | 701 | // IS_CENTER |
728 | 728 | // no line-wide markdown |
729 | 729 | } else { |
730 | 730 | |
731 | inline_display(window, &line->text->value[offset], colors); | |
731 | inline_display(window, &line->text->value[offset], colors, nocodebg); | |
732 | 732 | } |
733 | 733 | } |
734 | 734 | } |
746 | 746 | wattroff(window, A_UNDERLINE); |
747 | 747 | } |
748 | 748 | |
749 | void inline_display(WINDOW *window, const wchar_t *c, const int colors) { | |
749 | void inline_display(WINDOW *window, const wchar_t *c, const int colors, int nocodebg) { | |
750 | 750 | const static wchar_t *special = L"\\*_`!["; // list of interpreted chars |
751 | 751 | const wchar_t *i = c; // iterator |
752 | 752 | const wchar_t *start_link_name, *start_url; |
864 | 864 | break; |
865 | 865 | // enable inline code |
866 | 866 | case L'`': |
867 | if(colors) | |
867 | if(colors && !nocodebg) | |
868 | 868 | wattron(window, COLOR_PAIR(CP_BLACK)); |
869 | 869 | break; |
870 | 870 | // do nothing for backslashes |