From da1a4ad40b7bf0159584a9ed4ae76374475ad16c Mon Sep 17 00:00:00 2001 From: Pierce Corcoran Date: Tue, 8 Dec 2020 13:49:46 -0800 Subject: [PATCH 1/4] Refactor color styling and add test cases --- Makefile | 4 +- aha.c | 491 +++++++++++++++++++++++++++++++-------------------- test_print.c | 215 ++++++++++++++++++++++ 3 files changed, 520 insertions(+), 190 deletions(-) create mode 100644 test_print.c diff --git a/Makefile b/Makefile index 064c7e0..b4762c0 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,11 @@ all: aha aha: aha.c $(CC) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) aha.c -o $@ +test_print: test_print.c + $(CC) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) test_print.c -o $@ clean: - rm -f aha + rm -f aha aha_test install: aha ifeq ($(platform), Darwin) diff --git a/aha.c b/aha.c index cdffb11..a61fbbd 100644 --- a/aha.c +++ b/aha.c @@ -451,6 +451,8 @@ struct State { enum ColorMode fc_colormode; enum ColorMode bc_colormode; int highlighted; //for fc AND bc although not correct... + int fc_highlighted; + int bc_highlighted; }; void swapColors(struct State *const state) { @@ -481,6 +483,8 @@ const struct State default_state = { .fc_colormode = MODE_3BIT, .bc_colormode = MODE_3BIT, .highlighted = 0, + .fc_highlighted = 0, + .bc_highlighted = 0, }; int statesDiffer(const struct State *const old, const struct State *const new) { @@ -494,9 +498,106 @@ int statesDiffer(const struct State *const old, const struct State *const new) { (old->crossedout != new->crossedout) || (old->fc_colormode != new->fc_colormode) || (old->bc_colormode != new->bc_colormode) || - (old->highlighted != new->highlighted); + (old->highlighted != new->highlighted) || + (old->fc_highlighted != new->fc_highlighted) || + (old->bc_highlighted != new->bc_highlighted); } +struct ColorStyle { + char* fg_default; + char* bg_default; + char* colors[10]; + char* bright_colors[10]; +}; + +const struct ColorStyle styles[3] = { + { // SCHEME_WHITE + .fg_default = "black", + .bg_default = "white", + .colors = { + "dimgray", // Black + "red", // Red + "green", // Green + "olive", // Yellow + "blue", // Blue + "purple", // Magenta + "teal", // Cyan + "gray", // White + "white", // Default Background + "black" // Default Foreground + }, + .bright_colors = { + "dimgray", // Bright Black + "red", // Bright Red + "green", // Bright Green + "olive", // Bright Yellow + "blue", // Bright Blue + "purple", // Bright Magenta + "cyan", // Bright Cyan + "white", // Bright White + "white", // Default Background + "black" // Default Foreground + } + }, + + { // SCHEME_BLACK + .fg_default = "white", + .bg_default = "black", + .colors = { + "black", // Black + "red", // Red + "lime", // Green + "yellow", // Yellow + "#3333FF", // Blue + "fuchsia", // Magenta + "aqua", // Cyan + "white", // White + "black", // Default Background + "white" // Default Foreground + }, + .bright_colors = { + "black", // Bright Black + "red", // Bright Red + "lime", // Bright Green + "yellow", // Bright Yellow + "#3333FF", // Bright Blue + "fuchsia", // Bright Magenta + "aqua", // Bright Cyan + "white", // Bright White + "black", // Default Background + "white" // Default Foreground + } + }, + + { // SCHEME_PINK + .fg_default = "black", + .bg_default = "pink", + .colors = { + "dimgray", // Black + "red", // Red + "green", // Green + "olive", // Yellow + "blue", // Blue + "purple", // Magenta + "teal", // Cyan + "gray", // White + "pink", // Default Background + "black" // Default Foreground + }, + .bright_colors = { + "dimgray", // Bright Black + "red", // Bright Red + "green", // Bright Green + "olive", // Bright Yellow + "blue", // Bright Blue + "purple", // Bright Magenta + "cyan", // Bright Cyan + "white", // Bright White + "pink", // Default Background + "black" // Default Foreground + } + } +}; void printHeader(const struct Options *opts) { @@ -547,69 +648,38 @@ void printHeader(const struct Options *opts) printf("\">\n"); } + struct ColorStyle style = styles[opts->colorscheme]; + int style_tag = 0; if (opts->stylesheet) { printf("