Codebase list mdp-src / upstream/latest
New upstream version 1.0.15 Lev Lamberov 5 years ago
4 changed file(s) with 22 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2424
2525 #define MDP_VER_MAJOR 1
2626 #define MDP_VER_MINOR 0
27 #define MDP_VER_REVISION 14
27 #define MDP_VER_REVISION 15
2828
2929 #endif // !defined( MAIN_H )
5454 #define FADE_DELAY 15000 // micro seconds
5555 #define GOTO_SLIDE_DELAY 5 // tenths of seconds
5656
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);
6060 void fade_out(WINDOW *window, int trans, int colors, int invert);
6161 void fade_in(WINDOW *window, int trans, int colors, int invert);
6262 int int_length (int val);
3838 fprintf(stderr, "%s", " -s, --noslidenum do not show slide number at the bottom\n");
3939 fprintf(stderr, "%s", " -v, --version display the version number and license\n");
4040 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");
4142 fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n");
4243 exit(EXIT_FAILURE);
4344 }
6061 int reload = 0; // reload page N (0 means no reload)
6162 int noreload = 1; // reload disabled until we know input is a file
6263 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
6365
6466 // define command-line options
6567 struct option longopts[] = {
7274 { "version", no_argument, 0, 'v' },
7375 { "noslidenum", no_argument, 0, 's' },
7476 { "noslidemax", no_argument, 0, 'x' },
77 { "nocodebg", no_argument, 0, 'c' },
7578 { 0, 0, 0, 0 }
7679 };
7780
7881 // parse command-line options
7982 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) {
8184 switch(opt) {
8285 case 'd': debug += 1; break;
8386 case 'e': noexpand = 0; break;
8891 case 'v': version(); break;
8992 case 's': slidenum = 0; break;
9093 case 'x': slidenum = 1; break;
94 case 'c': nocodebg = 1; break;
9195 case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
9296 case '?':
9397 default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
162166 markdown_debug(deck, debug);
163167 }
164168
165 reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum);
169 reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum, nocodebg);
166170
167171 free_deck(deck);
168172
7272 static const char *list_head2 = " +- ";
7373 static const char *list_head3 = " +- ";
7474
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) {
7676
7777 int c = 0; // char
7878 int i = 0; // iterate
338338 // print lines
339339 while(line) {
340340 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);
342342
343343 // raise stop counter if we pass a line having a stop bit
344344 if(CHECK_BIT(line->bits, IS_STOP))
564564 }
565565 }
566566
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) {
568568
569569 int i; // increment
570570 int offset = 0; // text offset
576576
577577 // fill rest off line with spaces if we are in a code block
578578 if(CHECK_BIT(line->bits, IS_CODE) && colors) {
579 if(colors)
579 if(colors && !nocodebg)
580580 wattron(window, COLOR_PAIR(CP_BLACK));
581581 for(i = getcurx(window) - x; i < max_cols; i++)
582582 wprintw(window, "%s", " ");
610610 "%s", prompt);
611611
612612 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);
614614
615615 // IS_UNORDERED_LIST_2
616616 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) {
633633 "%s", prompt);
634634
635635 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);
637637
638638 // IS_UNORDERED_LIST_1
639639 } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) {
651651 "%s", prompt);
652652
653653 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);
655655 }
656656
657657 // IS_CODE
664664 }
665665
666666 // reverse color for code blocks
667 if(colors)
667 if(colors && !nocodebg)
668668 wattron(window, COLOR_PAIR(CP_BLACK));
669669
670670 // print whole lines
695695 offset = next_word(line->text, offset);
696696 }
697697
698 inline_display(window, &line->text->value[offset], colors);
698 inline_display(window, &line->text->value[offset], colors, nocodebg);
699699 } else {
700700
701701 // IS_CENTER
728728 // no line-wide markdown
729729 } else {
730730
731 inline_display(window, &line->text->value[offset], colors);
731 inline_display(window, &line->text->value[offset], colors, nocodebg);
732732 }
733733 }
734734 }
746746 wattroff(window, A_UNDERLINE);
747747 }
748748
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) {
750750 const static wchar_t *special = L"\\*_`!["; // list of interpreted chars
751751 const wchar_t *i = c; // iterator
752752 const wchar_t *start_link_name, *start_url;
864864 break;
865865 // enable inline code
866866 case L'`':
867 if(colors)
867 if(colors && !nocodebg)
868868 wattron(window, COLOR_PAIR(CP_BLACK));
869869 break;
870870 // do nothing for backslashes