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

Function parseExtendedColor

src/ink/termio/sgr.ts:79–125  ·  view source on GitHub ↗
(
  params: Param[],
  idx: number,
)

Source from the content-addressed store, hash-verified

77}
78
79function parseExtendedColor(
80 params: Param[],
81 idx: number,
82): { r: number; g: number; b: number } | { index: number } | null {
83 const p = params[idx]
84 if (!p) return null
85
86 if (p.colon && p.subparams.length >= 1) {
87 if (p.subparams[0] === 5 && p.subparams.length >= 2) {
88 return { index: p.subparams[1]! }
89 }
90 if (p.subparams[0] === 2 && p.subparams.length >= 4) {
91 const off = p.subparams.length >= 5 ? 1 : 0
92 return {
93 r: p.subparams[1 + off]!,
94 g: p.subparams[2 + off]!,
95 b: p.subparams[3 + off]!,
96 }
97 }
98 }
99
100 const next = params[idx + 1]
101 if (!next) return null
102 if (
103 next.value === 5 &&
104 params[idx + 2]?.value !== null &&
105 params[idx + 2]?.value !== undefined
106 ) {
107 return { index: params[idx + 2]!.value! }
108 }
109 if (next.value === 2) {
110 const r = params[idx + 2]?.value
111 const g = params[idx + 3]?.value
112 const b = params[idx + 4]?.value
113 if (
114 r !== null &&
115 r !== undefined &&
116 g !== null &&
117 g !== undefined &&
118 b !== null &&
119 b !== undefined
120 ) {
121 return { r, g, b }
122 }
123 }
124 return null
125}
126
127export function applySGR(paramStr: string, style: TextStyle): TextStyle {
128 const params = parseParams(paramStr)

Callers 1

applySGRFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected