XEP-0392: color: implement color hashing

* add the HSL values of each of the 256 terminal colors
* add color_pair_cache_hash_str()
* move common code to _color_pair_cache_get() helper func

after hashing a string to a color, return the closest matching
terminal color using euclidian distance of the HSL diff vector (this
method was found empirically and seems to work well enough...)
This commit is contained in:
Aurelien Aptel
2019-12-03 20:51:51 +01:00
parent 15064d9739
commit 4a672bda22
2 changed files with 376 additions and 283 deletions

View File

@@ -38,10 +38,20 @@
/* to access color names */
#define COLOR_NAME_SIZE 256
extern const char *color_names[];
/* to add or clear cache */
#include <stdint.h>
struct color_def {
uint16_t h; uint8_t s, l;
const char *name;
};
extern const struct color_def color_names[];
/* hash string to color pair */
int color_pair_cache_hash_str(const char *str);
/* parse fg_bg string to color pair */
int color_pair_cache_get(const char *pair_name);
/* clear cache */
void color_pair_cache_reset(void);
#endif