fixed nested quotation
[smdp.git] / viewer.c
index f262ea2..15b5e6a 100644 (file)
--- a/viewer.c
+++ b/viewer.c
@@ -21,6 +21,7 @@
  *
  */
 
+#include <locale.h> // setlocale
 #include <ncurses.h>
 #include <stdlib.h>
 #include <string.h> // strchr
@@ -74,6 +75,9 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) {
         slide = slide->next;
     }
 
+    // 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);
 
@@ -147,6 +151,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade) {
     }
 
     // setup footer
+    //TODO display slide number in footer
     if(bar_bottom) {
         line = deck->header->next;
         offset = next_blank(line->text, 0) + 1;
@@ -274,18 +279,9 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) {
                       y, x,
                       "%s", &line->text->text[offset]);
 
-        // IS_QUOTE
-        } else if(CHECK_BIT(line->bits, IS_QUOTE)) {
-            //TODO replace greater sign with color block
-
-            //FIXME remove dummy print code
-            mvwprintw(window,
-                      y, x,
-                      "%s", &line->text->text[offset]);
-
         } else {
 
-            // IF_H1 || IF_H2
+            // IS_H1 || IS_H2
             if(CHECK_BIT(line->bits, IS_H1) || CHECK_BIT(line->bits, IS_H2)) {
 
                 // set headline color
@@ -310,8 +306,23 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) {
                 // move the cursor in position
                 wmove(window, y, x);
 
+                // IS_QUOTE
+                if(CHECK_BIT(line->bits, IS_QUOTE)) {
+                    while(line->text->text[offset] == '>') {
+                        // print a reverse color block
+                        wattron(window, A_REVERSE);
+                        wprintw(window, "%s", " ");
+                        wattroff(window, A_REVERSE);
+                        wprintw(window, "%s", " ");
+                        // find next quote or break
+                        offset++;
+                        if(line->text->text[offset] == ' ')
+                            offset = next_word(line->text, offset);
+                    }
+                }
+
                 // for each char in line
-                c = line->text->text;
+                c = &line->text->text[offset];
                 while(*c) {
 
                     // if char is in special char list
@@ -371,7 +382,22 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) {
                     c++;
                 }
 
-                //TODO pop stack until empty
+                // pop stack until empty to prevent formated trailing spaces
+                while(!(stack->empty)(stack)) {
+                    switch((stack->pop)(stack)) {
+                        case '\\':
+                            wprintw(window, "%c", '\\');
+                            break;
+                        // disable highlight
+                        case '*':
+                            wattron(window, COLOR_PAIR(CP_WHITE));
+                            break;
+                        // disable underline
+                        case '_':
+                            wattroff(window, A_UNDERLINE);
+                            break;
+                    }
+                }
             }
         }