返回 CodeWhale
terminal-palette.mjs
根目录 / web / scripts / terminal-palette.mjs
1 const ANSI16 = [
2 "#000000", "#cd0000", "#00cd00", "#cdcd00", "#0000ee", "#cd00cd", "#00cdcd", "#e5e5e5",
3 "#7f7f7f", "#ff0000", "#00ff00", "#ffff00", "#5c5cff", "#ff00ff", "#00ffff", "#ffffff",
4 ];
5
6 export function hex(r, g, b) {
7 return `#${[r, g, b].map((v) => v.toString(16).padStart(2, "0")).join("")}`;
8 }
9
10 export function paletteColor(index) {
11 if (index < 16) return ANSI16[index];
12 if (index < 232) {
13 const i = index - 16;
14 const level = (v) => (v === 0 ? 0 : 55 + v * 40);
15 return hex(level(Math.floor(i / 36)), level(Math.floor(i / 6) % 6), level(i % 6));
16 }
17 const v = 8 + (index - 232) * 10;
18 return hex(v, v, v);
19 }
20
20 lines Plain Text