From: Daniel Liu Date: Thu, 17 Jun 2021 16:20:13 +0000 (-0400) Subject: color config for code blocks X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;ds=inline;p=smdp.git color config for code blocks --- diff --git a/README.md b/README.md index 6e3e9f4..cbedfd8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [NEW GIF COMING SOON] ### BACKGROUND -**smdp** is a fork of **[mdp](https://github.com/visit1985/mdp)**, the wonderful markdown presentation program. **smdp** is a set of modifications to my liking, namely, to make the project more suckless. Here's some notable differences: +**smdp** is a fork of **mdp** (find it [here](https://github.com/visit1985/mdp), the wonderful markdown presentation program. **smdp** is a set of modifications to my liking, namely, to make the project more suckless. Here's some notable differences: - configuration variables were abstracted out into a config.h variable (you can now change colors and keybindings to your liking!) - color fading and transparency was removed - patches are encouraged (i will be providing a couple myself) diff --git a/include/config.h b/include/config.h index 28a4351..cb73e86 100644 --- a/include/config.h +++ b/include/config.h @@ -36,7 +36,6 @@ static const char *list_head1 = " +- "; static const char *list_head2 = " +- "; static const char *list_head3 = " +- "; -#define FADE_DELAY 15000 // micro seconds #define GOTO_SLIDE_DELAY 5 // tenths of seconds // colors - you can only set in 8-bit color mode @@ -56,6 +55,8 @@ static const char *list_head3 = " +- "; #define TITLE_COLOR COLOR_YELLOW #define HEADER_COLOR COLOR_BLUE #define BOLD_COLOR COLOR_RED +#define CODEFG_COLOR COLOR_BLACK +#define CODEBG_COLOR COLOR_WHITE // keybindings static const int prev_slide_binding[] = { diff --git a/include/viewer.h b/include/viewer.h index 4f9a9f1..8850c7f 100644 --- a/include/viewer.h +++ b/include/viewer.h @@ -50,11 +50,11 @@ #define CP_HEADER 2 #define CP_BOLD 3 #define CP_TITLE 4 -#define CP_BG 5 // CP_FG with foreground and background swapped +#define CP_CODE 5 -int ncurses_display(deck_t *deck, int reload, int noreload, int slidenum, int nocodebg); -void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors, int nocodebg); -void inline_display(WINDOW *window, const wchar_t *c, const int colors, int nocodebg); +int ncurses_display(deck_t *deck, int reload, int noreload, int slidenum); +void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colors); +void inline_display(WINDOW *window, const wchar_t *c, const int colors); int int_length (int val); int get_slide_number(char init); void setup_list_strings(void); diff --git a/smdp.1 b/smdp.1 index 6abf7ac..2949e3f 100644 --- a/smdp.1 +++ b/smdp.1 @@ -37,9 +37,6 @@ or if the file name is the presentation is read from standard input. .SS "Output Control" .TP -.BR \-c ", " \-\^\-nocodebg -Don't change the background color of code blocks. -.TP .BR \-e ", " \-\^\-expand Enable character entity expansion (e.g. '>' becomes '>'). .TP diff --git a/src/main.c b/src/main.c index 07ceed1..49c0eeb 100644 --- a/src/main.c +++ b/src/main.c @@ -36,7 +36,6 @@ void usage() { 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); } @@ -56,7 +55,6 @@ int main(int argc, char *argv[]) { 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[] = { @@ -66,7 +64,6 @@ int main(int argc, char *argv[]) { { "version", no_argument, 0, 'v' }, { "noslidenum", no_argument, 0, 's' }, { "noslidemax", no_argument, 0, 'x' }, - { "nocodebg", no_argument, 0, 'c' }, { 0, 0, 0, 0 } }; @@ -80,7 +77,6 @@ int main(int argc, char *argv[]) { 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; @@ -155,7 +151,7 @@ int main(int argc, char *argv[]) { markdown_debug(deck, debug); } - reload = ncurses_display(deck, reload, noreload, slidenum, nocodebg); + reload = ncurses_display(deck, reload, noreload, slidenum); free_deck(deck); diff --git a/src/viewer.c b/src/viewer.c index bfc753d..20e4fb9 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -29,7 +29,7 @@ #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 @@ -149,10 +149,10 @@ int ncurses_display(deck_t *deck, int reload, int noreload, int slidenum, int no 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; } @@ -248,7 +248,7 @@ int ncurses_display(deck_t *deck, int reload, int noreload, int slidenum, int no // 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)) @@ -404,7 +404,7 @@ void setup_list_strings(void) } } -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 @@ -416,8 +416,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo // 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", " "); } @@ -450,7 +449,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo "%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)) { @@ -473,7 +472,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo "%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)) { @@ -491,7 +490,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo "%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 @@ -503,9 +502,9 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo 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]); @@ -519,9 +518,9 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo // 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", " "); @@ -535,7 +534,7 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo 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 @@ -568,18 +567,24 @@ void add_line(WINDOW *window, int y, int x, line_t *line, int max_cols, int colo // 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; @@ -697,8 +702,7 @@ void inline_display(WINDOW *window, const wchar_t *c, const int colors, int noco 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 }