fprintf(stderr, "%s", " -s, --noslidenum do not show slide number at the bottom\n");
fprintf(stderr, "%s", " -v, --version display the version number and license\n");
fprintf(stderr, "%s", " -x, --noslidemax show slide number, but not total number of slides\n");
- fprintf(stderr, "%s", " -c, --nocodebg don't change the background color of code blocks\n");
fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n");
exit(EXIT_FAILURE);
}
int reload = 0; // reload page N (0 means no reload)
int noreload = 1; // reload disabled until we know input is a file
int slidenum = 2; // 0:don't show; 1:show #; 2:show #/#
- int nocodebg = 0; // 0:show code bg as inverted; 1: don't invert code bg
// define command-line options
struct option longopts[] = {
{ "version", no_argument, 0, 'v' },
{ "noslidenum", no_argument, 0, 's' },
{ "noslidemax", no_argument, 0, 'x' },
- { "nocodebg", no_argument, 0, 'c' },
{ 0, 0, 0, 0 }
};
case 'v': version(); break;
case 's': slidenum = 0; break;
case 'x': slidenum = 1; break;
- case 'c': nocodebg = 1; break;
case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
case '?':
default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
markdown_debug(deck, debug);
}
- reload = ncurses_display(deck, reload, noreload, slidenum, nocodebg);
+ reload = ncurses_display(deck, reload, noreload, slidenum);
free_deck(deck);
#include "viewer.h"
#include "config.h"
-int ncurses_display(deck_t *deck, int reload, int noreload, int slidenum, int nocodebg) {
+int ncurses_display(deck_t *deck, int reload, int noreload, int slidenum) {
int c = 0; // char
int i = 0; // iterate
use_default_colors();
init_pair(CP_FG, FG_COLOR, BG_COLOR);
- init_pair(CP_BG, BG_COLOR, FG_COLOR);
init_pair(CP_HEADER, HEADER_COLOR, BG_COLOR);
init_pair(CP_BOLD, BOLD_COLOR, BG_COLOR);
init_pair(CP_TITLE, TITLE_COLOR, BG_COLOR);
+ init_pair(CP_CODE, CODEFG_COLOR, CODEBG_COLOR);
colors = 1;
}
// print lines
while(line) {
add_line(content, l + ((LINES - slide->lines_consumed - bar_top - bar_bottom) / 2),
- (COLS - max_cols) / 2, line, max_cols, colors, nocodebg);
+ (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))
}
}
-void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors, int nocodebg) {
+void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors) {
int i; // increment
int offset = 0; // text offset
// fill rest off line with spaces if we are in a code block
if(CHECK_BIT(line->bits, IS_CODE) && colors) {
- if(colors && !nocodebg)
- wattron(window, COLOR_PAIR(CP_BG));
+ wattron(window, COLOR_PAIR(CP_CODE));
for(i = getcurx(window) - x; i < max_cols; i++)
wprintw(window, "%s", " ");
}
"%s", prompt);
if(!CHECK_BIT(line->bits, IS_CODE))
- inline_display(window, &line->text->value[offset], colors, nocodebg);
+ inline_display(window, &line->text->value[offset], colors);
// IS_UNORDERED_LIST_2
} else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) {
"%s", prompt);
if(!CHECK_BIT(line->bits, IS_CODE))
- inline_display(window, &line->text->value[offset], colors, nocodebg);
+ inline_display(window, &line->text->value[offset], colors);
// IS_UNORDERED_LIST_1
} else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) {
"%s", prompt);
if(!CHECK_BIT(line->bits, IS_CODE))
- inline_display(window, &line->text->value[offset], colors, nocodebg);
+ inline_display(window, &line->text->value[offset], colors);
}
// IS_CODE
offset = CODE_INDENT;
}
- // reverse color for code blocks
- if(colors && !nocodebg)
- wattron(window, COLOR_PAIR(CP_BG));
+ // color for code block
+ if (colors)
+ wattron(window, COLOR_PAIR(CP_CODE));
// print whole lines
waddwstr(window, &line->text->value[offset]);
// IS_QUOTE
if(CHECK_BIT(line->bits, IS_QUOTE)) {
while(line->text->value[offset] == '>') {
- // print a reverse color block
+ // print a code block
if(colors) {
- wattron(window, COLOR_PAIR(CP_BG));
+ wattron(window, COLOR_PAIR(CP_CODE));
wprintw(window, "%s", " ");
wattron(window, COLOR_PAIR(CP_FG));
wprintw(window, "%s", " ");
offset = next_word(line->text, offset);
}
- inline_display(window, &line->text->value[offset], colors, nocodebg);
+ inline_display(window, &line->text->value[offset], colors);
} else {
// IS_CENTER
// no line-wide markdown
} else {
- inline_display(window, &line->text->value[offset], colors, nocodebg);
+ inline_display(window, &line->text->value[offset], colors);
}
}
}
+ // fill rest off line with spaces
+ // we only need this if the color is inverted (e.g. code-blocks)
+ if(CHECK_BIT(line->bits, IS_CODE))
+ for(i = getcurx(window) - x; i < max_cols; i++)
+ wprintw(window, "%s", " ");
+
// reset to default color
if(colors)
wattron(window, COLOR_PAIR(CP_FG));
wattroff(window, A_UNDERLINE);
}
-void inline_display(WINDOW *window, const wchar_t *c, const int colors, int nocodebg) {
+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;
break;
// enable inline code
case L'`':
- if(colors && !nocodebg)
- wattron(window, COLOR_PAIR(CP_BG));
+ wattron(window, COLOR_PAIR(CP_CODE));
break;
// do nothing for backslashes
}