Skip to content

Commit

Permalink
Add support for int colors in themes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
toastal authored and jubalh committed Nov 20, 2023
1 parent 0664491 commit bccfad3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/config/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bccfad3

Please sign in to comment.