From bccfad3de2fdc7d06e6ff975dd5f928654f089f0 Mon Sep 17 00:00:00 2001 From: toastal Date: Thu, 26 Oct 2023 17:24:00 +0700 Subject: [PATCH] Add support for int colors in themes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow theme colors to be specified as integers. Works with both decimal & hex. Given the XXX warning, it seems reasonable to allow users to specify their theme’s colors as the base integers since the names are pretty arbitrary. We changed the variable name `ul` to `col_value` per @H3rnand3zzz suggestion. --- src/config/color.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/config/color.c b/src/config/color.c index ecadc36b..3265e1e1 100644 --- a/src/config/color.c +++ b/src/config/color.c @@ -361,8 +361,19 @@ find_closest_col(int h, int s, int l) static int find_col(const char* col_name, int n) { + char* endptr; + unsigned long col_value = strtoul(col_name, &endptr, 0); char name[32] = { 0 }; + /* + * When the col_name is a uint8, then we don’t need to look up by + * color name (which is problematic given the duplicate names) + */ + + if ((*endptr == '\0' || *endptr == '\n') && col_value <= UINT8_MAX) { + return (int)col_value; + } + /* * make a null terminated version of col_name. we don't want to * use strNcasecmp because we could end up matching blue3 with