(text)
| 18 | |
| 19 | // Terminal control chars: `\r`/`\b`/`\t`/`\f` move the cursor and `\n` breaks the line. |
| 20 | function applyTerminalControls(text) { |
| 21 | if (!/[\r\b\t\f]/.test(text)) return text |
| 22 | const lines = [] |
| 23 | let line = '' |
| 24 | let col = 0 |
| 25 | const put = (c) => { line = line.slice(0, col) + c + line.slice(col + 1); col += 1 } |
| 26 | for (const ch of text) { |
| 27 | if (ch === '\n') { lines.push(line); line = ''; col = 0 } |
| 28 | else if (ch === '\r') { col = 0 } |
| 29 | else if (ch === '\b') { if (col > 0) col -= 1 } |
| 30 | else if (ch === '\f') { lines.push(line); line = ''; col = 0 } |
| 31 | else if (ch === '\t') { do { put(' ') } while (col % 4) } // tab stop 4, matching the editor |
| 32 | else { put(ch) } |
| 33 | } |
| 34 | lines.push(line) |
| 35 | return lines.join('\n') |
| 36 | } |
| 37 | |
| 38 | const PlayIcon = () => ( |
| 39 | <svg viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2.5" fill="none" height="11.5" aria-hidden="true" focusable="false"> |
no test coverage detected