X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Fviewer.c;h=0e2da5893e7960c8485222a2573d49562a495d91;hb=e9663e348e5e5d36b36ec38a582df7df1fc9126b;hp=574c3a0eff5c5a016b41fddfbd17910d352655d2;hpb=0b0a025d81ad8f9caed6c945dbcb1a18ce38b300;p=smdp.git diff --git a/src/viewer.c b/src/viewer.c index 574c3a0..0e2da58 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -94,6 +94,13 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { line = slide->line; while(line) { + + if (line && line->text && line->text->text) + lc += url_count_inline(line->text->text); + + if (line && line->text && line->text->text) + line->length -= url_len_inline(line->text->text); + if(line->length > COLS) { i = line->length; offset = 0; @@ -234,6 +241,9 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { slide = deck->slide; while(slide) { + + url_init(); + // clear windows werase(content); werase(stdscr); @@ -279,6 +289,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); @@ -394,6 +411,8 @@ int ncurses_display(deck_t *deck, int notrans, int nofade, int invert) { // fade out if(fade) fade_out(content, trans, colors, invert); + + url_purge(); } endwin(); @@ -560,8 +579,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(); @@ -615,10 +636,54 @@ void inline_display(WINDOW *window, const char *c, const int colors) { //TODO this condition looks ugly if(i == c || *(i - 1) == ' ' || - ((i + 1 > c) && (*(i - 1) == '_' || *(i - 1) == '*') && (*(i - 2) == ' ' || (i - 1) == c)) || + ((*(i - 1) == '_' || *(i - 1) == '*') && ((i - 1) == c || *(i - 2) == ' ')) || *i == '\\') { - switch(*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, "["); + } + + } else switch(*i) { // enable highlight case '*': if(colors)