MCPcopy Create free account
hub / github.com/codeaashu/claude-code / colorToEscape

Function colorToEscape

src/native-ts/color-diff/index.ts:129–145  ·  view source on GitHub ↗
(c: Color, fg: boolean, mode: ColorMode)

Source from the content-addressed store, hash-verified

127}
128
129function colorToEscape(c: Color, fg: boolean, mode: ColorMode): string {
130 // alpha=0: palette index encoded in .r (bat's ansi-theme convention)
131 if (c.a === 0) {
132 const idx = c.r
133 if (idx < 8) return `\x1b[${(fg ? 30 : 40) + idx}m`
134 if (idx < 16) return `\x1b[${(fg ? 90 : 100) + (idx - 8)}m`
135 return `\x1b[${fg ? 38 : 48};5;${idx}m`
136 }
137 // alpha=1: terminal default
138 if (c.a === 1) return fg ? '\x1b[39m' : '\x1b[49m'
139
140 const codeType = fg ? 38 : 48
141 if (mode === 'truecolor') {
142 return `\x1b[${codeType};2;${c.r};${c.g};${c.b}m`
143 }
144 return `\x1b[${codeType};5;${ansi256FromRgb(c.r, c.g, c.b)}m`
145}
146
147function asTerminalEscaped(
148 blocks: readonly Block[],

Callers 1

asTerminalEscapedFunction · 0.85

Calls 1

ansi256FromRgbFunction · 0.85

Tested by

no test coverage detected