*/
#include <ctype.h> // isalnum
-#include <locale.h> // setlocale
-#include <string.h> // strchr
+#include <wchar.h> // wcschr
+#include <wctype.h> // iswalnum
+#include <string.h> // strcpy
#include <unistd.h> // usleep
-
#include "viewer.h"
// color ramp for fading from black to color
slide_t *slide = deck->slide;
line_t *line;
- // set locale to display UTF-8 correctly in ncurses
- setlocale(LC_CTYPE, "");
-
// init ncurses
initscr();
endwin();
// print error
- 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");
+ fwprintf(stderr, L"Error: Terminal width (%i columns) too small. Need at least %i columns.\n", COLS, i);
+ fwprintf(stderr, L"You may need to shorten some lines by inserting line breaks.\n");
// no reload
return 0;
endwin();
// 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");
+ fwprintf(stderr, L"Error: Terminal height (%i lines) too small. Need at least %i lines.\n", LINES, max_lines + bar_top + bar_bottom);
+ fwprintf(stderr, L"You may need to add additional horizontal rules (---) to split your file in shorter slides.\n");
// no reload
return 0;
line = deck->header;
offset = next_blank(line->text, 0) + 1;
// add text to header
- mvwprintw(stdscr,
- 0, (COLS - line->length + offset) / 2,
- "%s", &line->text->text[offset]);
+ mvwaddwstr(stdscr,
+ 0, (COLS - line->length + offset) / 2,
+ &line->text->text[offset]);
}
// setup footer
line = deck->header->next;
offset = next_blank(line->text, 0) + 1;
// add text to left footer
- mvwprintw(stdscr,
- LINES - 1, 3,
- "%s", &line->text->text[offset]);
+ mvwaddwstr(stdscr,
+ LINES - 1, 3,
+ &line->text->text[offset]);
}
+
// add slide number to right footer
mvwprintw(stdscr,
LINES - 1, COLS - int_length(deck->slides) - int_length(sc) - 6,
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));
+ "[%d] ", i);
+ waddwstr(content, url_get_target(i));
}
// make content visible
break;
// show slide n
- case '9': i++;
- case '8': i++;
- case '7': i++;
- case '6': i++;
- case '5': i++;
- case '4': i++;
- case '3': i++;
- case '2': i++;
- case '1': i++;
- if(i <= deck->slides) {
+ case '9':
+ case '8':
+ case '7':
+ case '6':
+ case '5':
+ case '4':
+ case '3':
+ case '2':
+ case '1':
+ i = get_slide_number(c);
+ if(i > 0 && i <= deck->slides) {
while(sc != i) {
// search forward
if(sc < i) {
break;
// show first slide
+ case 'g':
case KEY_HOME:
slide = deck->slide;
sc = 1;
break;
// show last slide
+ case 'G':
case KEY_END:
for(i = sc; i <= deck->slides; i++) {
if(slide->next) {
wattron(window, COLOR_PAIR(CP_BLACK));
// print whole lines
- wprintw(window,
- "%s", &line->text->text[offset]);
+ waddwstr(window, &line->text->text[offset]);
}
if(!CHECK_BIT(line->bits, IS_UNORDERED_LIST_1) &&
offset = next_word(line->text, offset);
// print whole lines
- wprintw(window,
- "%s", &line->text->text[offset]);
+ waddwstr(window, &line->text->text[offset]);
wattroff(window, A_UNDERLINE);
wattroff(window, A_UNDERLINE);
}
-void inline_display(WINDOW *window, const char *c, const int colors) {
- const static char *special = "\\*_`!["; // list of interpreted chars
- const char *i = c; // iterator
- const char *start_link_name, *start_url;
+void inline_display(WINDOW *window, const wchar_t *c, const int colors) {
+ const static wchar_t *special = L"\\*_`!["; // list of interpreted chars
+ const wchar_t *i = c; // iterator
+ const wchar_t *start_link_name, *start_url;
int length_link_name, url_num;
cstack_t *stack = cstack_init();
for(; *i; i++) {
// if char is in special char list
- if(strchr(special, *i)) {
+ if(wcschr(special, *i)) {
// closing special char (or second backslash)
// only if not followed by :alnum:
if((stack->top)(stack, *i) &&
- (!isalnum((int)i[1]) || *(i + 1) == '\0' || *i == '\\')) {
+ (!iswalnum(i[1]) || *(i + 1) == L'\0' || *i == L'\\')) {
switch(*i) {
// print escaped backslash
- case '\\':
- wprintw(window, "%c", *i);
+ case L'\\':
+ waddnwstr(window, i, 1);
break;
// disable highlight
- case '*':
+ case L'*':
if(colors)
wattron(window, COLOR_PAIR(CP_WHITE));
break;
// disable underline
- case '_':
+ case L'_':
wattroff(window, A_UNDERLINE);
break;
// disable inline code
- case '`':
+ case L'`':
if(colors)
wattron(window, COLOR_PAIR(CP_WHITE));
break;
(stack->pop)(stack);
// treat special as regular char
- } else if((stack->top)(stack, '\\')) {
- wprintw(window, "%c", *i);
+ } else if((stack->top)(stack, L'\\')) {
+ waddnwstr(window, i, 1);
// remove backslash from stack
(stack->pop)(stack);
// and of cause after another emphasis markup
//TODO this condition looks ugly
if(i == c ||
- *(i - 1) == ' ' ||
- ((*(i - 1) == '_' || *(i - 1) == '*') && ((i - 1) == c || *(i - 2) == ' ')) ||
- *i == '\\') {
+ iswspace(*(i - 1)) ||
+ ((iswspace(*(i - 1)) || *(i - 1) == L'*' || *(i - 1) == L'_') &&
+ ((i - 1) == c || iswspace(*(i - 2)))) ||
+ *i == L'\\') {
// url in pandoc style
- if ((*i == '[' && strchr(i, ']')) ||
- (*i == '!' && *(i + 1) == '[' && strchr(i, ']'))) {
+ if ((*i == L'[' && wcschr(i, L']')) ||
+ (*i == L'!' && *(i + 1) == L'[' && wcschr(i, L']'))) {
- if (*i == '!') i++;
+ if (*i == L'!') i++;
- if (strchr(i, ']')[1] == '(') {
+ if (wcschr(i, L']')[1] == L'(') {
i++;
// turn higlighting and underlining on
// print the content of the label
// the label is printed as is
do {
- wprintw(window, "%c", *i);
+ waddnwstr(window, i, 1);
i++;
- } while (*i != ']');
+ } while (*i != L']');
length_link_name = i - 1 - start_link_name;
start_url = i;
- while (*i != ')') i++;
+ while (*i != L')') i++;
- url_num = url_add(start_link_name, length_link_name, start_url, i - start_url, 0,0);
+ url_num = url_add(start_link_name, length_link_name, start_url, i - start_url, 0, 0);
wprintw(window, " [%d]", url_num);
} else switch(*i) {
// enable highlight
- case '*':
+ case L'*':
if(colors)
wattron(window, COLOR_PAIR(CP_RED));
break;
// enable underline
- case '_':
+ case L'_':
wattron(window, A_UNDERLINE);
break;
// enable inline code
- case '`':
+ case L'`':
if(colors)
wattron(window, COLOR_PAIR(CP_BLACK));
break;
(stack->push)(stack, *i);
} else {
- wprintw(window, "%c", *i);
+ waddnwstr(window, i, 1);
}
}
} else {
// remove backslash from stack
- if((stack->top)(stack, '\\'))
+ if((stack->top)(stack, L'\\'))
(stack->pop)(stack);
// print regular char
- wprintw(window, "%c", *i);
+ waddnwstr(window, i, 1);
}
}
while(!(stack->empty)(stack)) {
switch((stack->pop)(stack)) {
// disable highlight
- case '*':
+ case L'*':
if(colors)
wattron(window, COLOR_PAIR(CP_WHITE));
break;
// disable underline
- case '_':
+ case L'_':
wattroff(window, A_UNDERLINE);
break;
// disable inline code
- case '`':
+ case L'`':
if(colors)
wattron(window, COLOR_PAIR(CP_WHITE));
break;
}
return l;
}
+
+int get_slide_number(char init) {
+ int retval = init - '0';
+ char c;
+ // block for tenths of a second when using getch, ERR if no input
+ halfdelay(GOTO_SLIDE_DELAY);
+ while((c = getch()) != ERR) {
+ if (c < '0' || c > '9') {
+ retval = -1;
+ break;
+ }
+ retval = (retval * 10) + (c - '0');
+ }
+ nocbreak(); // cancel half delay mode
+ cbreak(); // go back to cbreak
+ return retval;
+}