MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / AnsiLine

Function AnsiLine

frontend/app/element/ansiline.tsx:119–153  ·  view source on GitHub ↗
({ line })

Source from the content-addressed store, hash-verified

117const ansiRegex = /\x1b\[([0-9;]+)m/g;
118
119const AnsiLine = ({ line }) => {
120 const segments: SegmentType[] = [];
121 let lastIndex = 0;
122 let currentState = makeInitialState();
123
124 let match: RegExpExecArray;
125 while ((match = ansiRegex.exec(line)) !== null) {
126 if (match.index > lastIndex) {
127 segments.push({
128 text: line.substring(lastIndex, match.index),
129 classes: stateToClasses(currentState),
130 });
131 }
132 const codes = match[1].split(";").map(Number);
133 updateStateWithCodes(currentState, codes);
134 lastIndex = ansiRegex.lastIndex;
135 }
136
137 if (lastIndex < line.length) {
138 segments.push({
139 text: line.substring(lastIndex),
140 classes: stateToClasses(currentState),
141 });
142 }
143
144 return (
145 <div>
146 {segments.map((seg, idx) => (
147 <span key={idx} className={seg.classes}>
148 {seg.text}
149 </span>
150 ))}
151 </div>
152 );
153};
154
155export default AnsiLine;

Callers

nothing calls this directly

Calls 4

makeInitialStateFunction · 0.85
stateToClassesFunction · 0.85
updateStateWithCodesFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected