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

Function parseToSpans

src/ink/Ansi.tsx:118–153  ·  view source on GitHub ↗

* Parse an ANSI string into spans using the termio parser.

(input: string)

Source from the content-addressed store, hash-verified

116 * Parse an ANSI string into spans using the termio parser.
117 */
118function parseToSpans(input: string): Span[] {
119 const parser = new Parser();
120 const actions = parser.feed(input);
121 const spans: Span[] = [];
122 let currentHyperlink: string | undefined;
123 for (const action of actions) {
124 if (action.type === 'link') {
125 if (action.action.type === 'start') {
126 currentHyperlink = action.action.url;
127 } else {
128 currentHyperlink = undefined;
129 }
130 continue;
131 }
132 if (action.type === 'text') {
133 const text = action.graphemes.map(g => g.value).join('');
134 if (!text) continue;
135 const props = textStyleToSpanProps(action.style);
136 if (currentHyperlink) {
137 props.hyperlink = currentHyperlink;
138 }
139
140 // Try to merge with previous span if props match
141 const lastSpan = spans[spans.length - 1];
142 if (lastSpan && propsEqual(lastSpan.props, props)) {
143 lastSpan.text += text;
144 } else {
145 spans.push({
146 text,
147 props
148 });
149 }
150 }
151 }
152 return spans;
153}
154
155/**
156 * Convert termio's TextStyle to SpanProps.

Callers 1

Ansi.tsxFile · 0.85

Calls 4

feedMethod · 0.95
textStyleToSpanPropsFunction · 0.85
propsEqualFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected