summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/scheme.c51
1 files changed, 18 insertions, 33 deletions
diff --git a/bin/scheme.c b/bin/scheme.c
index 92a41fd7..fd1d8286 100644
--- a/bin/scheme.c
+++ b/bin/scheme.c
@@ -25,13 +25,8 @@
 #include <unistd.h>
 #include <zlib.h>
 
-struct Hsv {
-    double h, s, v;
-};
-
-struct Rgb {
-    uint8_t r, g, b;
-};
+struct Hsv { double h, s, v; };
+struct Rgb { uint8_t r, g, b; };
 
 static struct Rgb toRgb(struct Hsv hsv) {
     double c = hsv.v * hsv.s;
@@ -65,7 +60,7 @@ static void pngChunk(const char *type, uint32_t size) {
 }
 enum { NONE, SUB, UP, AVERAGE, PAETH };
 
-static void png(const struct Hsv *scheme, uint32_t len) {
+static void outPng(const struct Hsv *scheme, uint32_t len) {
     uint32_t swatchWidth = 64;
     uint32_t swatchHeight = 64;
     uint32_t columns = 8;
@@ -112,20 +107,20 @@ static void png(const struct Hsv *scheme, uint32_t len) {
     pngInt(crc);
 }
 
-static void hsv(const struct Hsv *scheme, uint32_t len) {
+static void outHsv(const struct Hsv *scheme, uint32_t len) {
     for (uint32_t i = 0; i < len; ++i) {
         printf("%g,%g,%g\n", scheme[i].h, scheme[i].s, scheme[i].v);
     }
 }
 
-static void hex(const struct Hsv *scheme, uint32_t len) {
+static void outHex(const struct Hsv *scheme, uint32_t len) {
     for (uint32_t i = 0; i < len; ++i) {
         struct Rgb rgb = toRgb(scheme[i]);
         printf("%02x%02x%02x\n", rgb.r, rgb.g, rgb.b);
     }
 }
 
-static void linux(const struct Hsv *scheme, uint32_t len) {
+static void outLinux(const struct Hsv *scheme, uint32_t len) {
     if (len > 16) len = 16;
     for (uint32_t i = 0; i < len; ++i) {
         struct Rgb rgb = toRgb(scheme[i]);
@@ -149,11 +144,13 @@ struct Ansi {
     struct Hsv dark[8];
     struct Hsv light[8];
 };
+
 struct Terminal {
     struct Ansi ansi;
     struct Hsv background, text, bold, selection, cursor;
 };
 
+#define HSV_LEN(x) (sizeof(x) / sizeof(struct Hsv))
 struct Scheme {
     uint32_t len;
     union {
@@ -162,7 +159,6 @@ struct Scheme {
         struct Terminal terminal;
     };
 };
-#define HSV_LEN(x) (sizeof(x) / sizeof(struct Hsv))
 
 static struct Scheme genAnsi(void) {
     struct Ansi ansi = {
@@ -176,7 +172,6 @@ static struct Scheme genAnsi(void) {
             [CYAN]    = p(C, -60.0, 0.3, 0.6),
             [WHITE]   = p(R, +45.0, 0.3, 0.8),
         },
-        .dark[BLACK] = ansi.light[BLACK],
     };
     ansi.dark[BLACK] = p(ansi.light[BLACK], 0.0, 1.0, 0.3);
     ansi.dark[WHITE] = p(ansi.light[WHITE], 0.0, 1.0, 0.6);
@@ -203,34 +198,24 @@ static struct Scheme genTerminal(void) {
 }
 
 int main(int argc, char *argv[]) {
-    enum { ANSI, TERMINAL } generate = ANSI;
-    enum { HSV, HEX, LINUX, PNG } output = HEX;
+    struct Scheme (*gen)(void) = genAnsi;
+    void (*out)(const struct Hsv *, uint32_t len) = outHex;
 
     int opt;
     while (0 < (opt = getopt(argc, argv, "aghltx"))) {
         switch (opt) {
-            case 'a': generate = ANSI; break;
-            case 'g': output = PNG; break;
-            case 'h': output = HSV; break;
-            case 'l': output = LINUX; break;
-            case 't': generate = TERMINAL; break;
-            case 'x': output = HEX; break;
+            case 'a': gen = genAnsi; break;
+            case 'g': out = outPng; break;
+            case 'h': out = outHsv; break;
+            case 'l': out = outLinux; break;
+            case 't': gen = genTerminal; break;
+            case 'x': out = outHex; break;
             default: return EX_USAGE;
         }
     }
 
-    struct Scheme scheme;
-    switch (generate) {
-        case ANSI: scheme = genAnsi(); break;
-        case TERMINAL: scheme = genTerminal(); break;
-    }
-
-    switch (output) {
-        case HSV: hsv(&scheme.hsv, scheme.len); break;
-        case HEX: hex(&scheme.hsv, scheme.len); break;
-        case LINUX: linux(&scheme.hsv, scheme.len); break;
-        case PNG: png(&scheme.hsv, scheme.len); break;
-    }
+    struct Scheme scheme = gen();
+    out(&scheme.hsv, scheme.len);
 
     return EX_OK;
 }
ghlight'> 2018-08-06Rewrite line editing again, add formattingJune McEnroe 2018-08-06Fix allocation size in vaswprintfJune McEnroe This is so embarrassing. It only started crashing once it had strings that were long enough, and then it took me so long to notice this mistake. I was worried I was still doing va_list wrong somehow. 2018-08-06Implement word wrappingJune McEnroe 2018-08-06Use wchar_t strings for all of UIJune McEnroe vaswprintf is a nightmare. 2018-08-06Rename line editing functionsJune McEnroe 2018-08-05Initialize all possible color pairsJune McEnroe This is actually possible with use_default_colors! 2018-08-05Refactor color initializationJune McEnroe 2018-08-05Add ^L redrawJune McEnroe 2018-08-05Use 16 colors if availableJune McEnroe Fall back to using bold if there are only 8 colors. This also allowed bright background colors in 16-color terminals. I must port this system to torus. I'll be able to remove the awful termcap patch hack. 2018-08-05Limit parsed colors to number of mIRC colorsJune McEnroe Oh boy that's embarrassing. 2018-08-04Show source link on exitJune McEnroe 2018-08-04Implement line editing, scrollingJune McEnroe Don't really have a way to implement the M-* keys, and currently missing C-w. 2018-08-04Handle /topicJune McEnroe