(element: HTMLElement)
| 228 | }; |
| 229 | |
| 230 | const initTerminalWindow = (element: HTMLElement) => { |
| 231 | if (terminal.value) { |
| 232 | throw new Error("Terminal already initialized, Please refresh the page!"); |
| 233 | } |
| 234 | |
| 235 | // init touch handler |
| 236 | element.addEventListener("touchstart", touchHandler, true); |
| 237 | element.addEventListener("touchmove", touchHandler, true); |
| 238 | element.addEventListener("touchend", touchHandler, true); |
| 239 | element.addEventListener("touchcancel", touchHandler, true); |
| 240 | |
| 241 | const background = hasBgImage.value ? "#00000000" : "#1e1e1e"; |
| 242 | const term = new Terminal({ |
| 243 | convertEol: true, |
| 244 | disableStdin: false, |
| 245 | cursorStyle: "underline", |
| 246 | cursorBlink: true, |
| 247 | fontSize: 14, |
| 248 | theme: { |
| 249 | background |
| 250 | }, |
| 251 | allowProposedApi: true, |
| 252 | allowTransparency: true |
| 253 | }); |
| 254 | const fitAddon = new FitAddon(); |
| 255 | term.loadAddon(fitAddon); |
| 256 | |
| 257 | const unicode11Addon = new Unicode11Addon(); |
| 258 | term.loadAddon(unicode11Addon); |
| 259 | term.unicode.activeVersion = "11"; |
| 260 | |
| 261 | terminal.value = term; |
| 262 | |
| 263 | const gl = document.createElement("canvas").getContext("webgl2"); |
| 264 | if (gl) { |
| 265 | // If WebGL2 is supported, use the WebGlAddon |
| 266 | const webglAddon = new WebglAddon(); |
| 267 | webglAddon.onContextLoss((_) => { |
| 268 | webglAddon.dispose(); |
| 269 | }); |
| 270 | term.loadAddon(webglAddon); |
| 271 | } else { |
| 272 | // If WebGL2 is not supported, use the CanvasAddon |
| 273 | const canvasAddon = new CanvasAddon(); |
| 274 | term.loadAddon(canvasAddon); |
| 275 | } |
| 276 | |
| 277 | term.open(element); |
| 278 | |
| 279 | // If text is selected, copy it. Otherwise, fallback to default behavior. |
| 280 | term.attachCustomKeyEventHandler((arg) => { |
| 281 | if (arg.type === "keydown" && arg.ctrlKey && arg.code === "KeyC") { |
| 282 | const selection = term.getSelection(); |
| 283 | if (selection) { |
| 284 | arg.preventDefault(); |
| 285 | toCopy(selection); |
| 286 | term.clearSelection(); |
| 287 | return false; |
nothing calls this directly
no test coverage detected