Skip to content

Commit

Permalink
feat(ANSI): add name and order keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham committed Nov 1, 2024
1 parent d0ee97f commit 6dbb911
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ export type ColorFormat = Readonly<{
}>;

export type AnsiColorGroups = Readonly<{
/**
* Name of the ANSI color.
*/
name: string;

/**
* Order of the ANSI color in the palette spec
*/
order: number;

/**
* An object containing all the ANSI "normal" colors, which are the 8 standard colors from 0 to 7.
*/
Expand Down
64 changes: 64 additions & 0 deletions palette.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@
},
"ansiColors": {
"black": {
"name": "Black",
"order": 0,
"normal": {
"hex": "#5c5f77",
"code": 0
Expand All @@ -435,6 +437,8 @@
}
},
"red": {
"name": "Red",
"order": 1,
"normal": {
"hex": "#d20f39",
"code": 1
Expand All @@ -445,6 +449,8 @@
}
},
"green": {
"name": "Green",
"order": 2,
"normal": {
"hex": "#40a02b",
"code": 2
Expand All @@ -455,6 +461,8 @@
}
},
"yellow": {
"name": "Yellow",
"order": 3,
"normal": {
"hex": "#df8e1d",
"code": 3
Expand All @@ -465,6 +473,8 @@
}
},
"blue": {
"name": "Blue",
"order": 4,
"normal": {
"hex": "#1e66f5",
"code": 4
Expand All @@ -475,6 +485,8 @@
}
},
"magenta": {
"name": "Magenta",
"order": 5,
"normal": {
"hex": "#ea76cb",
"code": 5
Expand All @@ -485,6 +497,8 @@
}
},
"cyan": {
"name": "Cyan",
"order": 6,
"normal": {
"hex": "#179299",
"code": 6
Expand All @@ -495,6 +509,8 @@
}
},
"white": {
"name": "White",
"order": 7,
"normal": {
"hex": "#acb0be",
"code": 7
Expand Down Expand Up @@ -931,6 +947,8 @@
},
"ansiColors": {
"black": {
"name": "Black",
"order": 0,
"normal": {
"hex": "#51576d",
"code": 0
Expand All @@ -941,6 +959,8 @@
}
},
"red": {
"name": "Red",
"order": 1,
"normal": {
"hex": "#e78284",
"code": 1
Expand All @@ -951,6 +971,8 @@
}
},
"green": {
"name": "Green",
"order": 2,
"normal": {
"hex": "#a6d189",
"code": 2
Expand All @@ -961,6 +983,8 @@
}
},
"yellow": {
"name": "Yellow",
"order": 3,
"normal": {
"hex": "#e5c890",
"code": 3
Expand All @@ -971,6 +995,8 @@
}
},
"blue": {
"name": "Blue",
"order": 4,
"normal": {
"hex": "#8caaee",
"code": 4
Expand All @@ -981,6 +1007,8 @@
}
},
"magenta": {
"name": "Magenta",
"order": 5,
"normal": {
"hex": "#f4b8e4",
"code": 5
Expand All @@ -991,6 +1019,8 @@
}
},
"cyan": {
"name": "Cyan",
"order": 6,
"normal": {
"hex": "#81c8be",
"code": 6
Expand All @@ -1001,6 +1031,8 @@
}
},
"white": {
"name": "White",
"order": 7,
"normal": {
"hex": "#a5adce",
"code": 7
Expand Down Expand Up @@ -1437,6 +1469,8 @@
},
"ansiColors": {
"black": {
"name": "Black",
"order": 0,
"normal": {
"hex": "#494d64",
"code": 0
Expand All @@ -1447,6 +1481,8 @@
}
},
"red": {
"name": "Red",
"order": 1,
"normal": {
"hex": "#ed8796",
"code": 1
Expand All @@ -1457,6 +1493,8 @@
}
},
"green": {
"name": "Green",
"order": 2,
"normal": {
"hex": "#a6da95",
"code": 2
Expand All @@ -1467,6 +1505,8 @@
}
},
"yellow": {
"name": "Yellow",
"order": 3,
"normal": {
"hex": "#eed49f",
"code": 3
Expand All @@ -1477,6 +1517,8 @@
}
},
"blue": {
"name": "Blue",
"order": 4,
"normal": {
"hex": "#8aadf4",
"code": 4
Expand All @@ -1487,6 +1529,8 @@
}
},
"magenta": {
"name": "Magenta",
"order": 5,
"normal": {
"hex": "#f5bde6",
"code": 5
Expand All @@ -1497,6 +1541,8 @@
}
},
"cyan": {
"name": "Cyan",
"order": 6,
"normal": {
"hex": "#8bd5ca",
"code": 6
Expand All @@ -1507,6 +1553,8 @@
}
},
"white": {
"name": "White",
"order": 7,
"normal": {
"hex": "#a5adcb",
"code": 7
Expand Down Expand Up @@ -1943,6 +1991,8 @@
},
"ansiColors": {
"black": {
"name": "Black",
"order": 0,
"normal": {
"hex": "#45475a",
"code": 0
Expand All @@ -1953,6 +2003,8 @@
}
},
"red": {
"name": "Red",
"order": 1,
"normal": {
"hex": "#f38ba8",
"code": 1
Expand All @@ -1963,6 +2015,8 @@
}
},
"green": {
"name": "Green",
"order": 2,
"normal": {
"hex": "#a6e3a1",
"code": 2
Expand All @@ -1973,6 +2027,8 @@
}
},
"yellow": {
"name": "Yellow",
"order": 3,
"normal": {
"hex": "#f9e2af",
"code": 3
Expand All @@ -1983,6 +2039,8 @@
}
},
"blue": {
"name": "Blue",
"order": 4,
"normal": {
"hex": "#89b4fa",
"code": 4
Expand All @@ -1993,6 +2051,8 @@
}
},
"magenta": {
"name": "Magenta",
"order": 5,
"normal": {
"hex": "#f5c2e7",
"code": 5
Expand All @@ -2003,6 +2063,8 @@
}
},
"cyan": {
"name": "Cyan",
"order": 6,
"normal": {
"hex": "#94e2d5",
"code": 6
Expand All @@ -2013,6 +2075,8 @@
}
},
"white": {
"name": "White",
"order": 7,
"normal": {
"hex": "#a6adc8",
"code": 7
Expand Down
8 changes: 7 additions & 1 deletion scripts/gen_palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ const formatted = entriesFromObject(definitions).reduce(
(acc, [colorName, color], currentIndex) => {
const { r, g, b } = tinycolor(color).toRgb();
const { h, s, l } = tinycolor(color).toHsl();

acc[colorName] = {
name: prettyNames[currentIndex],
order: currentIndex,
Expand All @@ -296,11 +297,12 @@ const formatted = entriesFromObject(definitions).reduce(
hsl: { h, s, l },
accent: accents.includes(colorName),
};

return acc;
},
{} as Writeable<CatppuccinColors>,
),
ansiColors: entriesFromObject(ansiMappings).reduce((acc, [name, props]) => {
ansiColors: entriesFromObject(ansiMappings).reduce((acc, [name, props], currentIndex) => {
const mapping = props.normal.mapping as ColorName;
let normalColorHex = flavor.colors[mapping];
let brightColorHex: string;
Expand All @@ -318,7 +320,10 @@ const formatted = entriesFromObject(definitions).reduce(
brightColor.lch.h += 2;
brightColorHex = brightColor.toString({ format: "hex" });
}

acc[name] = {
name: name[0].toUpperCase() + name.substring(1).toLowerCase(),
order: currentIndex,
normal: {
hex: normalColorHex,
code: props.normal.code,
Expand All @@ -328,6 +333,7 @@ const formatted = entriesFromObject(definitions).reduce(
code: props.bright.code,
},
};

return acc;
}, {} as Writeable<CatppuccinAnsiColors>),
};
Expand Down

0 comments on commit 6dbb911

Please sign in to comment.