#include "theme.h" #include #include #include uint32_t base16[16]; bool theme_load(std::string filename) { FILE *fp = fopen(filename.c_str(), "r"); if(!fp) return false; for(int i = 0; i < 16; i++) base16[i] = 0xffffff; char entry[64], value[256]; int colors_found = 0; while(fscanf(fp, " %64[^:]: \"%64[^\"\n]\"", entry, value) == 2) { if(strlen(entry) == 6 && !strncmp(entry, "base0", 5)) { int index = entry[5] - '0' - 7 * (entry[5] >= 'A') - 32 * (entry[5] >= 'a'); colors_found++; sscanf(value, "%x", &base16[index]); } } fclose(fp); return true; } fmt::text_style theme(int color) { return fg(fmt::rgb(base16[color & 0xf])); } //--- // Built-in themes //--- static std::map> builtin_themes = { /* Tomorrow Night by Chris Kempson (http://chriskempson.com) */ {"tomorrow-night", { 0x1d1f21, 0x282a2e, 0x373b41, 0x969896, 0xb4b7b4, 0xc5c8c6, 0xe0e0e0, 0xffffff, 0xcc6666, 0xde935f, 0xf0c674, 0xb5bd68, 0x8abeb7, 0x81a2be, 0xb294bb, 0xa3685a, }}, }; bool theme_builtin(std::string name) { if(!builtin_themes.count(name)) return false; for(int i = 0; i < 16; i++) base16[i] = builtin_themes[name][i]; return true; }