// 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);
-
// init ncurses
initscr();
if((max_cols > COLS) ||
(max_lines + bar_top + bar_bottom + 2 > LINES)) {
- fprintf(stderr, "Error: Terminal size %ix%i to small. Need at least %ix%i.\n",
+ fprintf(stderr, "Error: Terminal size %ix%i too small. Need at least %ix%i.\n",
COLS, LINES, max_cols, max_lines + bar_top + bar_bottom + 2);
endwin();
return(1);
// print lines
while(line) {
- add_line(content, l, (COLS - max_cols) / 2, line, max_cols);
+ add_line(content, l, (COLS - max_cols) / 2, line, max_cols, colors);
line = line->next;
l++;
}
return(0);
}
-void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols) {
+void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) {
int i = 0; // increment
char *c; // char pointer for iteration
char *special = "\\*_"; // list of interpreted chars
if(CHECK_BIT(line->bits, IS_H1) || CHECK_BIT(line->bits, IS_H2)) {
// set headline color
- wattron(window, COLOR_PAIR(CP_BLUE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_BLUE));
// enable underline for H1
if(CHECK_BIT(line->bits, IS_H1))
break;
// disable highlight
case '*':
- wattron(window, COLOR_PAIR(CP_WHITE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_WHITE));
break;
// disable underline
case '_':
switch(*c) {
// enable highlight
case '*':
- wattron(window, COLOR_PAIR(CP_RED));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_RED));
break;
// enable underline
case '_':
switch((stack->pop)(stack)) {
// disable highlight
case '*':
- wattron(window, COLOR_PAIR(CP_WHITE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_WHITE));
break;
// disable underline
case '_':
wprintw(window, "%s", " ");
// reset to default color
- wattron(window, COLOR_PAIR(CP_WHITE));
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_WHITE));
wattroff(window, A_UNDERLINE);
wattroff(window, A_REVERSE);
}