import round from 'lodash/round.js'; import type { Template } from './index.js'; import { colorSetToVariants } from '../color-set/index.js'; import { source } from 'common-tags'; import Color from 'color'; function formatColor(hex: string): string { return Color(hex) .rgb() .array() .concat(255) .map((component) => round(component / 255, 6)) .join(' '); } const template: Template = { name: 'Xcode', render: async function* (colorSet) { const variants = colorSetToVariants(colorSet); for (const variant of variants) { const shade0 = formatColor(variant.colors.shade0); const shade1 = formatColor(variant.colors.shade1); const shade2 = formatColor(variant.colors.shade2); const shade3 = formatColor(variant.colors.shade3); const shade4 = formatColor(variant.colors.shade4); const shade5 = formatColor(variant.colors.shade5); const shade6 = formatColor(variant.colors.shade6); const shade7 = formatColor(variant.colors.shade7); const accent0 = formatColor(variant.colors.accent0); const accent1 = formatColor(variant.colors.accent1); const accent2 = formatColor(variant.colors.accent2); const accent3 = formatColor(variant.colors.accent3); const accent4 = formatColor(variant.colors.accent4); const accent5 = formatColor(variant.colors.accent5); const accent6 = formatColor(variant.colors.accent6); const accent7 = formatColor(variant.colors.accent7); yield { path: `${variant.title.human}.dvtcolortheme`, content: source` DVTConsoleDebuggerInputTextColor ${shade7} DVTConsoleDebuggerOutputTextColor ${shade5} DVTConsoleDebuggerPromptTextColor ${accent1} DVTConsoleExectuableInputTextColor ${shade5} DVTConsoleExectuableOutputTextColor ${shade7} DVTConsoleTextBackgroundColor ${shade0} DVTConsoleTextInsertionPointColor ${accent6} DVTConsoleTextSelectionColor ${shade1} DVTDebuggerInstructionPointerColor ${accent3} DVTSourceTextBackground ${shade0} DVTSourceTextBlockDimBackgroundColor ${shade4} DVTSourceTextInsertionPointColor ${accent6} DVTSourceTextInvisiblesColor ${shade1} DVTSourceTextSelectionColor ${shade1} DVTSourceTextSyntaxColors xcode.syntax.attribute ${accent3} xcode.syntax.character ${accent4} xcode.syntax.comment ${shade2} xcode.syntax.comment.doc ${shade3} xcode.syntax.comment.doc.keyword ${shade4} xcode.syntax.identifier.class ${accent2} xcode.syntax.identifier.class.system ${accent2} xcode.syntax.identifier.constant ${accent3} xcode.syntax.identifier.constant.system ${accent3} xcode.syntax.identifier.function ${accent4} xcode.syntax.identifier.function.system ${accent4} xcode.syntax.identifier.macro ${accent7} xcode.syntax.identifier.macro.system ${accent7} xcode.syntax.identifier.type ${accent0} xcode.syntax.identifier.type.system ${accent1} xcode.syntax.identifier.variable ${shade7} xcode.syntax.identifier.variable.system ${shade7} xcode.syntax.keyword ${accent5} xcode.syntax.number ${accent3} xcode.syntax.plain ${shade6} xcode.syntax.preprocessor ${accent6} xcode.syntax.string ${accent3} xcode.syntax.url ${accent5} `, }; } }, renderInstructions: (paths) => source` Copy (or symlink) the generated theme ${ paths.length === 1 ? 'file' : 'files' } to Xcode's themes directory: \`\`\` mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes ${paths .map( (p) => `cp '${p}' ~/Library/Developer/Xcode/UserData/FontAndColorThemes/`, ) .join('\n')} \`\`\` Then restart Xcode. The ${ paths.length === 1 ? 'theme' : 'themes' } will be available in Preferences > Fonts and Colors. `, }; export default template;