summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-31 14:25:30 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-31 14:25:30 -0500
commite26bc35d04c136a142da37a87f6ba47940399879 (patch)
tree8a537dcff79d0915c46249db336fa30e79a190d3
parente5ccfb4ee98da03ac5423c0570a4da33ef85b975 (diff)
started color customization
-rw-r--r--colors.c65
-rw-r--r--main.c3
-rw-r--r--ted-base.c4
3 files changed, 71 insertions, 1 deletions
diff --git a/colors.c b/colors.c
new file mode 100644
index 0000000..d3952c3
--- /dev/null
+++ b/colors.c
@@ -0,0 +1,65 @@
+ENUM_U16 {
+ COLOR_UNKNOWN,
+
+ COLOR_BG,
+ COLOR_CURSOR,
+ COLOR_CURSOR_LINE_BG,
+ COLOR_BORDER,
+ COLOR_TEXT,
+ COLOR_SELECTION_BG,
+ COLOR_SELECTION_TEXT,
+
+ COLOR_COUNT
+} ENUM_U16_END(ColorSetting);
+
+typedef struct {
+ ColorSetting setting;
+ char const *name;
+} ColorName;
+
+static ColorName const color_names[COLOR_COUNT] = {
+ {COLOR_UNKNOWN, "unknown"},
+ {COLOR_BG, "bg"},
+ {COLOR_CURSOR, "cursor"},
+ {COLOR_CURSOR_LINE_BG, "cursor-line-bg"},
+ {COLOR_BORDER, "border"},
+ {COLOR_TEXT, "text"},
+ {COLOR_SELECTION_BG, "selection-bg"},
+ {COLOR_SELECTION_TEXT, "selection-text"}
+};
+
+static ColorSetting color_setting_from_str(char const *str) {
+ // @OPTIM: sort color_names, binary search
+ for (int i = 0; i < COLOR_COUNT; ++i) {
+ ColorName const *n = &color_names[i];
+ if (streq(n->name, str))
+ return n->setting;
+ }
+ return COLOR_UNKNOWN;
+}
+
+static char const *color_setting_to_str(ColorSetting s) {
+ for (int i = 0; i < COLOR_COUNT; ++i) {
+ ColorName const *n = &color_names[i];
+ if (n->setting == s)
+ return n->name;
+ }
+ return "???";
+}
+
+// converts #rrggbb/#rrggbbaa to a color. returns false if it's not in the right format.
+static Status color_from_str(char const *str, u32 *color) {
+ uint r = 0, g = 0, b = 0, a = 0xff;
+ size_t len = strlen(str);
+ if (len == 7) {
+ sscanf(str, "#%02x%02x%02x", &r, &g, &b);
+ } else if (len == 9) {
+ sscanf(str, "#%02x%02x%02x%02x", &r, &g, &b, &a);
+ } else {
+ return false;
+ }
+ if (r > 0xff || g > 0xff || b > 0xff) return false;
+ if (color)
+ *color = (u32)r << 24 | (u32)g << 16 | (u32)b << 8 | (u32)a;
+ return true;
+}
diff --git a/main.c b/main.c
index c941ca9..de4f262 100644
--- a/main.c
+++ b/main.c
@@ -12,9 +12,10 @@ no_warn_end
#include <wctype.h>
#include "command.h"
+#include "util.c"
+#include "colors.c"
#include "time.c"
#include "unicode.h"
-#include "util.c"
#define MATH_GL
#include "math.c"
#include "text.h"
diff --git a/ted-base.c b/ted-base.c
index 1024404..8771f02 100644
--- a/ted-base.c
+++ b/ted-base.c
@@ -4,6 +4,10 @@ typedef struct {
i64 argument;
} KeyAction;
+typedef struct {
+ u32 colors[COLOR_COUNT];
+} Settings;
+
#define SCANCODE_COUNT 0x120 // SDL scancodes should be less than this value.
// a "key combo" is some subset of {control, shift, alt} + some key.
#define KEY_COMBO_COUNT (SCANCODE_COUNT << 3)