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.
  • Loading branch information
toastal authored and jubalh committed Oct 29, 2023
1 parent 0664491 commit ffa9073
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 ul = 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') && ul <= UINT8_MAX) {
return (int)ul;
}

/*
* 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 ffa9073

Please sign in to comment.