From: Michael Göhler Date: Sun, 8 Feb 2015 16:46:42 +0000 (+0100) Subject: added support for interupting slides line by line, #45, #75 X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=680d0478fc66d6d25b1f258be0114d6c915ec0a0;p=smdp.git added support for interupting slides line by line, #45, #75 --- diff --git a/include/markdown.h b/include/markdown.h index f38a646..da8805e 100644 --- a/include/markdown.h +++ b/include/markdown.h @@ -53,6 +53,7 @@ enum line_bitmask { IS_UNORDERED_LIST_3, IS_UNORDERED_LIST_EXT, IS_CENTER, + IS_STOP, IS_EMPTY }; @@ -70,6 +71,7 @@ typedef struct _slide_t { struct _slide_t *prev; struct _slide_t *next; int lines; + int stop; } slide_t; typedef struct _deck_t { diff --git a/src/markdown.c b/src/markdown.c index 05c77be..dd1ea48 100644 --- a/src/markdown.c +++ b/src/markdown.c @@ -43,7 +43,7 @@ slide_t *new_slide() { slide_t *x = malloc(sizeof(slide_t)); x->line = NULL; x->prev = x->next = NULL; - x->lines = 0; + x->lines = x->stop = 0; return x; } diff --git a/src/parser.c b/src/parser.c index 59b6b52..5ca7ea2 100644 --- a/src/parser.c +++ b/src/parser.c @@ -68,6 +68,14 @@ deck_t *markdown_load(FILE *input) { // clear text (text->reset)(text); + } else if(line && CHECK_BIT(bits, IS_STOP)) { + + // set stop bit on last line + SET_BIT(line->bits, IS_STOP); + + // clear text + (text->reset)(text); + // if text is markdown hr } else if(CHECK_BIT(bits, IS_HR) && CHECK_BIT(line->bits, IS_EMPTY)) { @@ -308,6 +316,15 @@ int markdown_analyse(cstring_t *text, int prev) { // count leading spaces offset = next_nonblank(text, 0); + // IS_STOP + if((offset < CODE_INDENT || !CHECK_BIT(prev, IS_CODE)) && + (!wcsncmp(&text->value[offset], L"
", 4) || + !wcsncmp(&text->value[offset], L"
", 4) || + !wcsncmp(&text->value[offset], L"^", 1))) { + SET_BIT(bits, IS_STOP); + return bits; + } + // strip trailing spaces for(eol = text->size; eol > offset && iswspace(text->value[eol - 1]); eol--); @@ -381,7 +398,8 @@ int markdown_analyse(cstring_t *text, int prev) { // IS_CODE if(offset >= CODE_INDENT && (CHECK_BIT(prev, IS_EMPTY) || - CHECK_BIT(prev, IS_CODE))) { + CHECK_BIT(prev, IS_CODE) || + CHECK_BIT(prev, IS_STOP))) { SET_BIT(bits, IS_CODE); } else { diff --git a/src/viewer.c b/src/viewer.c index bf8af68..5ca04a5 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -73,6 +73,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa int max_lines = 0; // max lines per slide int max_cols = 0; // max columns per line int offset; // text offset + int stop = 0; // passed stop bits per slide // header line 1 is displayed at the top int bar_top = (deck->headers > 0) ? 1 : 0; @@ -291,21 +292,34 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa wrefresh(stdscr); line = slide->line; - l = 0; + l = stop = 0; // print lines while(line) { add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors); + + // raise stop counter if we pass a line having a stop bit + if(CHECK_BIT(line->bits, IS_STOP)) + stop++; + l += (line->length / COLS) + 1; line = line->next; + + // only stop here if we didn't stop here recently + if(stop > slide->stop) + break; } - int i, ymax; - getmaxyx( content, ymax, i ); - for (i = 0; i < url_get_amount(); i++) { - mvwprintw(content, ymax - url_get_amount() - 1 + i, 3, - "[%d] ", i); - waddwstr(content, url_get_target(i)); + // print pandoc URL references + // only if we already printed all lines of the current slide + if(!line) { + int i, ymax; + getmaxyx( content, ymax, i ); + for (i = 0; i < url_get_amount(); i++) { + mvwprintw(content, ymax - url_get_amount() - 1 + i, 3, + "[%d] ", i); + waddwstr(content, url_get_target(i)); + } } // make content visible @@ -326,7 +340,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa i = 0; switch(c) { - // show previous slide + // show previous slide or stop bit case KEY_UP: case KEY_LEFT: case KEY_PPAGE: @@ -335,15 +349,23 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa case 263: // BACKSPACE (getty) case 'h': case 'k': - if(slide->prev) { - slide = slide->prev; - sc--; + if(stop > 1 || (stop == 1 && !line)) { + // show current slide again + // but stop one stop bit earlier + slide->stop--; } else { - fade = false; + if(slide->prev) { + // show previous slide + slide = slide->prev; + sc--; + } else { + // do nothing + fade = false; + } } break; - // show next slide + // show next slide or stop bit case KEY_DOWN: case KEY_RIGHT: case KEY_NPAGE: @@ -351,11 +373,19 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reloa case ' ': // SPACE case 'j': case 'l': - if(slide->next) { - slide = slide->next; - sc++; + if(stop && line) { + // show current slide again + // but stop one stop bit later (or at end of slide) + slide->stop++; } else { - fade = false; + if(slide->next) { + // show next slide + slide = slide->next; + sc++; + } else { + // do nothing + fade = false; + } } break;