Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Created February 20, 2023 04:57
Show Gist options
  • Save crazymonkyyy/a4dd8683d097da84d4245a1c4f84469e to your computer and use it in GitHub Desktop.
Save crazymonkyyy/a4dd8683d097da84d4245a1c4f84469e to your computer and use it in GitHub Desktop.
import std;
enum filename="base-16.csv";
struct color{
int r;
int g;
int b;
}
auto rebase(T)(T a, T min, T max){
if(a>=min&&a<=max){
return a-min;
}
alias S=typeof(T.init-T.init);
return S.max-11;//hack
}
int hextoint(char c){
return min(
c.rebase('0','9'),
c.rebase('a','f')+10,
c.rebase('A','F')+10,
);
}
color tocolor(string s){
return color(
s[0].hextoint*16+s[1].hextoint,
s[2].hextoint*16+s[3].hextoint,
s[4].hextoint*16+s[5].hextoint,
);
}
enum color[16][string] __base16=(){
color[16][string] o;
foreach(s;import(filename).split('\n')){
auto a=s.splitter(',').array.to!(string[]);
o[a[0]]=a[1..$].filter!(a=>a.length==6).map!tocolor.staticArray!16;
}
return o;
}();
color[16][string] base16=__base16;// massively reduces compile time
enum colornames=["background","brightbackground","selection","hightlight",
"darktext","text","brighttext","brightwhite",
"red","good","yellow","green",
"cyan","blue","purple","evil"];
string theme="solarized-dark";
static foreach(i,s;colornames){
mixin("color "~s~"(){ return base16[theme]["~i.to!string~"];}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment