MCPcopy Index your code
hub / github.com/codeaashu/claude-code / colorize

Function colorize

src/ink/colorize.ts:69–169  ·  view source on GitHub ↗
(
  str: string,
  color: string | undefined,
  type: ColorType,
)

Source from the content-addressed store, hash-verified

67const ANSI_REGEX = /^ansi256\(\s?(\d+)\s?\)$/
68
69export const colorize = (
70 str: string,
71 color: string | undefined,
72 type: ColorType,
73): string => {
74 if (!color) {
75 return str
76 }
77
78 if (color.startsWith('ansi:')) {
79 const value = color.substring('ansi:'.length)
80 switch (value) {
81 case 'black':
82 return type === 'foreground' ? chalk.black(str) : chalk.bgBlack(str)
83 case 'red':
84 return type === 'foreground' ? chalk.red(str) : chalk.bgRed(str)
85 case 'green':
86 return type === 'foreground' ? chalk.green(str) : chalk.bgGreen(str)
87 case 'yellow':
88 return type === 'foreground' ? chalk.yellow(str) : chalk.bgYellow(str)
89 case 'blue':
90 return type === 'foreground' ? chalk.blue(str) : chalk.bgBlue(str)
91 case 'magenta':
92 return type === 'foreground' ? chalk.magenta(str) : chalk.bgMagenta(str)
93 case 'cyan':
94 return type === 'foreground' ? chalk.cyan(str) : chalk.bgCyan(str)
95 case 'white':
96 return type === 'foreground' ? chalk.white(str) : chalk.bgWhite(str)
97 case 'blackBright':
98 return type === 'foreground'
99 ? chalk.blackBright(str)
100 : chalk.bgBlackBright(str)
101 case 'redBright':
102 return type === 'foreground'
103 ? chalk.redBright(str)
104 : chalk.bgRedBright(str)
105 case 'greenBright':
106 return type === 'foreground'
107 ? chalk.greenBright(str)
108 : chalk.bgGreenBright(str)
109 case 'yellowBright':
110 return type === 'foreground'
111 ? chalk.yellowBright(str)
112 : chalk.bgYellowBright(str)
113 case 'blueBright':
114 return type === 'foreground'
115 ? chalk.blueBright(str)
116 : chalk.bgBlueBright(str)
117 case 'magentaBright':
118 return type === 'foreground'
119 ? chalk.magentaBright(str)
120 : chalk.bgMagentaBright(str)
121 case 'cyanBright':
122 return type === 'foreground'
123 ? chalk.cyanBright(str)
124 : chalk.bgCyanBright(str)
125 case 'whiteBright':
126 return type === 'foreground'

Callers 4

applyTextStylesFunction · 0.70
applyColorFunction · 0.70
setSelectionBgColorMethod · 0.70
colorFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected