X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Fviewer.c;h=211557edc1114d92b133a3e4fe6e42b1126381e3;hb=aa1840c42fc305339cf02b45ea3039ca50f6d6e2;hp=2cf0f0e5bba99305a03e069f8ebf105d9162f4ec;hpb=8aa16fe57be3d85e46815509df69a61682be9bf0;p=smdp.git diff --git a/src/viewer.c b/src/viewer.c index 2cf0f0e..211557e 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -60,7 +60,7 @@ static short red_ramp_invert[24] = { 15, 231, 231, 224, 224, 225, 206, 207, 201, 200, 199, 199, 198, 198, 197, 197, 196, 196}; -int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { +int ncurses_display(deck_t *deck, int notrans, int nofade, int invert, int reload, int noreload) { int c = 0; // char int i = 0; // iterate @@ -93,7 +93,14 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { lc = 0; line = slide->line; - while(line) { + while(line && line->text) { + + if (line->text->text) + lc += url_count_inline(line->text->text); + + if (line->text->text) + line->length -= url_len_inline(line->text->text); + if(line->length > COLS) { i = line->length; offset = 0; @@ -113,7 +120,8 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { fprintf(stderr, "Error: Terminal width (%i columns) too small. Need at least %i columns.\n", COLS, i); fprintf(stderr, "You may need to shorten some lines by inserting line breaks.\n"); - return 1; + // no reload + return 0; } // set max_cols @@ -147,9 +155,10 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { // print error fprintf(stderr, "Error: Terminal height (%i lines) too small. Need at least %i lines.\n", LINES, max_lines + bar_top + bar_bottom); - fprintf(stderr, "You may need to add additional horizontal rules ('***') to split your file in shorter slides.\n"); + fprintf(stderr, "You may need to add additional horizontal rules (---) to split your file in shorter slides.\n"); - return 1; + // no reload + return 0; } // disable cursor @@ -233,7 +242,21 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { wbkgd(content, COLOR_PAIR(CP_WHITE)); slide = deck->slide; + + // find slide to reload + while(reload > 1 && reload <= deck->slides) { + slide = slide->next; + sc++; + reload--; + } + + // reset reload indicator + reload = 0; + while(slide) { + + url_init(); + // clear windows werase(content); werase(stdscr); @@ -266,6 +289,7 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { "%d / %d", sc, deck->slides); // make header + fooder visible + wrefresh(content); wrefresh(stdscr); line = slide->line; @@ -278,6 +302,13 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { line = line->next; } + 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] %s", i, url_get_target(i)); + } + // make content visible wrefresh(content); @@ -377,10 +408,24 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { } break; + // reload + case 'r': + if(noreload == 0) { + // reload slide N + reload = sc; + slide = NULL; + } else { + // disable fading if reload is not possible + fade = false; + } + break; + // quit case 'q': // do not fade out on exit fade = false; + // do not reload + reload = 0; slide = NULL; break; @@ -393,11 +438,20 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { // fade out if(fade) fade_out(content, trans, colors, invert); + + url_purge(); } + // disable ncurses endwin(); - return 0; + // free ncurses memory + delwin(content); + if(reload == 0) + delwin(stdscr); + + // return reload indicator (0 means no reload) + return reload; } void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) { @@ -559,8 +613,10 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo } void inline_display(WINDOW *window, const char *c, const int colors) { - const static char *special = "\\*_`"; // list of interpreted chars + const static char *special = "\\*_`!["; // list of interpreted chars const char *i = c; // iterator + const char *start_link_name, *start_url; + int length_link_name, url_num; cstack_t *stack = cstack_init(); @@ -611,12 +667,57 @@ void inline_display(WINDOW *window, const char *c, const int colors) { // emphasis or code span can start after new-line or space only // and of cause after another emphasis markup - if(*(i - 1) == ' ' || - ((*(i - 1) == '_' || *(i - 1) == '*') && (*(i - 2) == ' ' || (i - 1) == c)) || - *i == '\\' || - i == c) { + //TODO this condition looks ugly + if(i == c || + *(i - 1) == ' ' || + ((*(i - 1) == '_' || *(i - 1) == '*') && ((i - 1) == c || *(i - 2) == ' ')) || + *i == '\\') { + + // url in pandoc style + if ((*i == '[' && strchr(i, ']')) || + (*i == '!' && *(i + 1) == '[' && strchr(i, ']'))) { + + if (*i == '!') i++; + + if (strchr(i, ']')[1] == '(') { + i++; + + // turn higlighting and underlining on + if (colors) + wattron(window, COLOR_PAIR(CP_BLUE)); + wattron(window, A_UNDERLINE); + + start_link_name = i; + + // print the content of the label + // the label is printed as is + do { + wprintw(window, "%c", *i); + i++; + } while (*i != ']'); + + length_link_name = i - 1 - start_link_name; + + i++; + i++; + + start_url = i; + + while (*i != ')') i++; + + url_num = url_add(start_link_name, length_link_name, start_url, i - start_url, 0,0); + + wprintw(window, " [%d]", url_num); + + // turn highlighting and underlining off + wattroff(window, A_UNDERLINE); + wattron(window, COLOR_PAIR(CP_WHITE)); + + } else { + wprintw(window, "["); + } - switch(*i) { + } else switch(*i) { // enable highlight case '*': if(colors)