()
| 97 | // ── Terminal initialisation ────────────────────────────────────────────────── |
| 98 | |
| 99 | function initTerminal(): void { |
| 100 | term = new Terminal({ |
| 101 | cursorBlink: true, |
| 102 | cursorStyle: 'block', |
| 103 | fontFamily: |
| 104 | "'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'SF Mono', Menlo, Monaco, 'Courier New', monospace", |
| 105 | fontSize: 14, |
| 106 | lineHeight: 1.2, |
| 107 | theme: getTheme(), |
| 108 | allowProposedApi: true, |
| 109 | scrollback: 10_000, |
| 110 | convertEol: true, |
| 111 | }) |
| 112 | |
| 113 | fitAddon = new FitAddon() |
| 114 | term.loadAddon(fitAddon) |
| 115 | term.loadAddon(new WebLinksAddon()) |
| 116 | |
| 117 | searchAddon = new SearchAddon() |
| 118 | term.loadAddon(searchAddon) |
| 119 | |
| 120 | const unicode11 = new Unicode11Addon() |
| 121 | term.loadAddon(unicode11) |
| 122 | term.unicode.activeVersion = '11' |
| 123 | |
| 124 | term.open(terminalContainer) |
| 125 | |
| 126 | // WebGL renderer with canvas fallback |
| 127 | try { |
| 128 | const webgl = new WebglAddon() |
| 129 | webgl.onContextLoss(() => webgl.dispose()) |
| 130 | term.loadAddon(webgl) |
| 131 | } catch { |
| 132 | // Canvas renderer is already active — no action needed |
| 133 | } |
| 134 | |
| 135 | fitAddon.fit() |
| 136 | |
| 137 | // Keep terminal fitted to container |
| 138 | const resizeObserver = new ResizeObserver(() => fitAddon.fit()) |
| 139 | resizeObserver.observe(terminalContainer) |
| 140 | |
| 141 | // Propagate resize to server |
| 142 | term.onResize(({ cols, rows }) => sendJSON({ type: 'resize', cols, rows })) |
| 143 | |
| 144 | // Forward all terminal input to PTY |
| 145 | term.onData((data) => { |
| 146 | if (ws?.readyState === WebSocket.OPEN) ws.send(data) |
| 147 | }) |
| 148 | |
| 149 | // Keyboard intercepts (return false = swallow; return true = pass through) |
| 150 | term.attachCustomKeyEventHandler((ev) => { |
| 151 | // Ctrl+Shift+F → in-terminal search |
| 152 | if (ev.ctrlKey && ev.shiftKey && ev.key === 'F') { |
| 153 | if (ev.type === 'keydown') { |
| 154 | const query = window.prompt('Search terminal:') |
| 155 | if (query) searchAddon.findNext(query, { caseSensitive: false, regex: false }) |
| 156 | } |
no test coverage detected