MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / applyTerminalControls

Function applyTerminalControls

docs/components/Playground.jsx:20–36  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

18
19// Terminal control chars: `\r`/`\b`/`\t`/`\f` move the cursor and `\n` breaks the line.
20function 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
38const PlayIcon = () => (
39 <svg viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2.5" fill="none" height="11.5" aria-hidden="true" focusable="false">

Callers 1

PlaygroundFunction · 0.85

Calls 2

putFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected