({ line })
| 117 | const ansiRegex = /\x1b\[([0-9;]+)m/g; |
| 118 | |
| 119 | const 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 | |
| 155 | export default AnsiLine; |
nothing calls this directly
no test coverage detected