import { ColorScheme } from './colorSchemes';
export function generateYAML(scheme: ColorScheme): string {
return `colors:
# Default colors
primary:
background: '${scheme.colors.primary.background}'
foreground: '${scheme.colors.primary.foreground}'
# Normal colors
normal:
black: '${scheme.colors.normal.black}'
red: '${scheme.colors.normal.red}'
green: '${scheme.colors.normal.green}'
yellow: '${scheme.colors.normal.yellow}'
blue: '${scheme.colors.normal.blue}'
magenta: '${scheme.colors.normal.magenta}'
cyan: '${scheme.colors.normal.cyan}'
white: '${scheme.colors.normal.white}'
# Bright colors
bright:
black: '${scheme.colors.bright.black}'
red: '${scheme.colors.bright.red}'
green: '${scheme.colors.bright.green}'
yellow: '${scheme.colors.bright.yellow}'
blue: '${scheme.colors.bright.blue}'
magenta: '${scheme.colors.bright.magenta}'
cyan: '${scheme.colors.bright.cyan}'
white: '${scheme.colors.bright.white}'
`;
}
export function generateJSON(scheme: ColorScheme): string {
return JSON.stringify(scheme.colors, null, 2);
}
export function generateXResources(scheme: ColorScheme): string {
return `*background: ${scheme.colors.primary.background}
*foreground: ${scheme.colors.primary.foreground}
*color0: ${scheme.colors.normal.black}
*color1: ${scheme.colors.normal.red}
*color2: ${scheme.colors.normal.green}
*color3: ${scheme.colors.normal.yellow}
*color4: ${scheme.colors.normal.blue}
*color5: ${scheme.colors.normal.magenta}
*color6: ${scheme.colors.normal.cyan}
*color7: ${scheme.colors.normal.white}
*color8: ${scheme.colors.bright.black}
*color9: ${scheme.colors.bright.red}
*color10: ${scheme.colors.bright.green}
*color11: ${scheme.colors.bright.yellow}
*color12: ${scheme.colors.bright.blue}
*color13: ${scheme.colors.bright.magenta}
*color14: ${scheme.colors.bright.cyan}
*color15: ${scheme.colors.bright.white}
`;
}
export function generateTOML(scheme: ColorScheme): string {
return `[colors.primary]
background = "${scheme.colors.primary.background}"
foreground = "${scheme.colors.primary.foreground}"
[colors.normal]
black = "${scheme.colors.normal.black}"
red = "${scheme.colors.normal.red}"
green = "${scheme.colors.normal.green}"
yellow = "${scheme.colors.normal.yellow}"
blue = "${scheme.colors.normal.blue}"
magenta = "${scheme.colors.normal.magenta}"
cyan = "${scheme.colors.normal.cyan}"
white = "${scheme.colors.normal.white}"
[colors.bright]
black = "${scheme.colors.bright.black}"
red = "${scheme.colors.bright.red}"
green = "${scheme.colors.bright.green}"
yellow = "${scheme.colors.bright.yellow}"
blue = "${scheme.colors.bright.blue}"
magenta = "${scheme.colors.bright.magenta}"
cyan = "${scheme.colors.bright.cyan}"
white = "${scheme.colors.bright.white}"
`;
}
export function generateITerm2(scheme: ColorScheme): string {
return `
Ansi 0 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.black.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.black.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.black.slice(1, 3), 16) / 255}
Ansi 1 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.red.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.red.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.red.slice(1, 3), 16) / 255}
Ansi 2 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.green.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.green.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.green.slice(1, 3), 16) / 255}
Ansi 3 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.yellow.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.yellow.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.yellow.slice(1, 3), 16) / 255}
Ansi 4 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.blue.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.blue.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.blue.slice(1, 3), 16) / 255}
Ansi 5 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.magenta.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.magenta.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.magenta.slice(1, 3), 16) / 255}
Ansi 6 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.cyan.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.cyan.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.cyan.slice(1, 3), 16) / 255}
Ansi 7 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.normal.white.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.normal.white.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.normal.white.slice(1, 3), 16) / 255}
Ansi 8 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.black.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.black.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.black.slice(1, 3), 16) / 255}
Ansi 9 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.red.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.red.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.red.slice(1, 3), 16) / 255}
Ansi 10 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.green.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.green.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.green.slice(1, 3), 16) / 255}
Ansi 11 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.yellow.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.yellow.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.yellow.slice(1, 3), 16) / 255}
Ansi 12 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.blue.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.blue.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.blue.slice(1, 3), 16) / 255}
Ansi 13 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.magenta.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.magenta.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.magenta.slice(1, 3), 16) / 255}
Ansi 14 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.cyan.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.cyan.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.cyan.slice(1, 3), 16) / 255}
Ansi 15 Color
Color Space
sRGB
Blue Component
${parseInt(scheme.colors.bright.white.slice(5, 7), 16) / 255}
Green Component
${parseInt(scheme.colors.bright.white.slice(3, 5), 16) / 255}
Red Component
${parseInt(scheme.colors.bright.white.slice(1, 3), 16) / 255}
`;
}
export function generateWindowsTerminal(scheme: ColorScheme): string {
return JSON.stringify({
"name": scheme.name,
"background": scheme.colors.primary.background,
"foreground": scheme.colors.primary.foreground,
"black": scheme.colors.normal.black,
"red": scheme.colors.normal.red,
"green": scheme.colors.normal.green,
"yellow": scheme.colors.normal.yellow,
"blue": scheme.colors.normal.blue,
"purple": scheme.colors.normal.magenta,
"cyan": scheme.colors.normal.cyan,
"white": scheme.colors.normal.white,
"brightBlack": scheme.colors.bright.black,
"brightRed": scheme.colors.bright.red,
"brightGreen": scheme.colors.bright.green,
"brightYellow": scheme.colors.bright.yellow,
"brightBlue": scheme.colors.bright.blue,
"brightPurple": scheme.colors.bright.magenta,
"brightCyan": scheme.colors.bright.cyan,
"brightWhite": scheme.colors.bright.white
}, null, 2);
}
export function generateTerminalApp(scheme: ColorScheme): string {
return `
ANSIBlackColor
${colorToBase64(scheme.colors.normal.black)}
ANSIRedColor
${colorToBase64(scheme.colors.normal.red)}
ANSIGreenColor
${colorToBase64(scheme.colors.normal.green)}
ANSIYellowColor
${colorToBase64(scheme.colors.normal.yellow)}
ANSIBlueColor
${colorToBase64(scheme.colors.normal.blue)}
ANSIMagentaColor
${colorToBase64(scheme.colors.normal.magenta)}
ANSICyanColor
${colorToBase64(scheme.colors.normal.cyan)}
ANSIWhiteColor
${colorToBase64(scheme.colors.normal.white)}
ANSIBrightBlackColor
${colorToBase64(scheme.colors.bright.black)}
ANSIBrightRedColor
${colorToBase64(scheme.colors.bright.red)}
ANSIBrightGreenColor
${colorToBase64(scheme.colors.bright.green)}
ANSIBrightYellowColor
${colorToBase64(scheme.colors.bright.yellow)}
ANSIBrightBlueColor
${colorToBase64(scheme.colors.bright.blue)}
ANSIBrightMagentaColor
${colorToBase64(scheme.colors.bright.magenta)}
ANSIBrightCyanColor
${colorToBase64(scheme.colors.bright.cyan)}
ANSIBrightWhiteColor
${colorToBase64(scheme.colors.bright.white)}
BackgroundColor
${colorToBase64(scheme.colors.primary.background)}
TextColor
${colorToBase64(scheme.colors.primary.foreground)}
CursorColor
${colorToBase64(scheme.colors.primary.foreground)}
`;
}
function colorToBase64(color: string): string {
const r = parseInt(color.slice(1, 3), 16) / 255;
const g = parseInt(color.slice(3, 5), 16) / 255;
const b = parseInt(color.slice(5, 7), 16) / 255;
const binaryData = new Float32Array([r, g, b, 1]);
return Buffer.from(binaryData.buffer).toString('base64');
}