Add option to not invert code background color.
[smdp.git] / src / viewer.c
index cbb1498..1a3ac00 100644 (file)
@@ -2,7 +2,7 @@
  * Functions necessary to display a deck of slides in different color modes
  * using ncurses. Only white, red, and blue are supported, as they can be
  * faded in 256 color mode.
- * Copyright (C) 2016 Michael Goehler
+ * Copyright (C) 2018 Michael Goehler
  *
  * This file is part of mdp.
  *
@@ -73,7 +73,7 @@ static const char *list_head1 = " +- ";
 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
@@ -158,6 +158,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa
             max_lines_slide = sc;
         }
 
+        slide->lines_consumed = lc;
         slide = slide->next;
         ++sc;
     }
@@ -261,7 +262,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa
     slide = deck->slide;
 
     // find slide to reload
-    sc = 0;
+    sc = 1;
     while(reload > 1 && reload <= deck->slides) {
         slide = slide->next;
         sc++;
@@ -337,7 +338,8 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa
 
         // print lines
         while(line) {
-            add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors);
+            add_line(content, l + ((LINES - slide->lines_consumed - bar_top - bar_bottom) / 2),
+                     (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))
@@ -563,7 +565,7 @@ void setup_list_strings(void)
     }
 }
 
-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
@@ -575,7 +577,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
 
         // 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", " ");
@@ -609,7 +611,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
                 "%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)) {
@@ -632,7 +634,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
                 "%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)) {
@@ -650,19 +652,20 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
                 "%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
     if(CHECK_BIT(line->bits, IS_CODE)) {
 
-        if (!CHECK_BIT(line->bits, IS_TILDE_CODE)) {
+        if (!CHECK_BIT(line->bits, IS_TILDE_CODE) &&
+            !CHECK_BIT(line->bits, IS_GFM_CODE)) {
             // set static offset for code
             offset = CODE_INDENT;
         }
 
         // reverse color for code blocks
-        if(colors)
+        if(colors && !nocodebg)
             wattron(window, COLOR_PAIR(CP_BLACK));
 
         // print whole lines
@@ -693,7 +696,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
                     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
@@ -726,7 +729,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
             // no line-wide markdown
             } else {
 
-                inline_display(window, &line->text->value[offset], colors);
+                inline_display(window, &line->text->value[offset], colors, nocodebg);
             }
         }
     }
@@ -744,7 +747,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo
     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;
@@ -862,7 +865,7 @@ void inline_display(WINDOW *window, const wchar_t *c, const int colors) {
                             break;
                         // enable inline code
                         case L'`':
-                            if(colors)
+                            if(colors && !nocodebg)
                                 wattron(window, COLOR_PAIR(CP_BLACK));
                             break;
                         // do nothing for backslashes
@@ -981,7 +984,7 @@ int int_length (int val) {
 
 int get_slide_number(char init) {
     int retval = init - '0';
-    char c;
+    int c;
     // block for tenths of a second when using getch, ERR if no input
     halfdelay(GOTO_SLIDE_DELAY);
     while((c = getch()) != ERR) {