| <!-- | |
| Copyright (C) 2026 The Android Open Source Project | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| See the License for the specific language governing permissions and | |
| limitations under the License. | |
| --> | |
| <!doctype html> | |
| <html> | |
| <head> | |
| <script> | |
| window.pendingConsoleData = []; | |
| window.onConsoleData = function(data) { | |
| window.pendingConsoleData.push(data); | |
| }; | |
| </script> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.css" /> | |
| <script src="https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.js"></script> | |
| <style> | |
| body { margin: 0; background: black; } | |
| #terminal { height: 100vh; } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="terminal"></div> | |
| <script> | |
| const term = new Terminal({ | |
| theme: { background: '#000000' }, | |
| convertEol: true, | |
| cursorBlink: true, | |
| fontFamily: 'monospace' | |
| }); | |
| const fitAddon = new FitAddon.FitAddon(); | |
| window.term = term; | |
| term.loadAddon(fitAddon); | |
| term.open(document.getElementById('terminal')); | |
| term.focus(); | |
| fitAddon.fit(); | |
| if (term.parser) { | |
| const titleHandler = (data) => { | |
| const cleanTitle = data.replace(/[\x00-\x1f\x7f]/g, ''); | |
| document.title = cleanTitle; | |
| return true; | |
| }; | |
| [0, 1, 2].forEach(id => term.parser.registerOscHandler(id, titleHandler)); | |
| } | |
| function sanitizeOscTitleString(str) { | |
| if (!str.includes('\x1b]')) { | |
| return str; | |
| } | |
| return str.replace(/\x1b\]([0-9]+);([\s\S]*?)(\x07|\x1b\\)/g, function(match, cmd, payload, term) { | |
| const cleanPayload = payload.replace(/[\x00-\x1f\x7f]/g, ''); | |
| return '\x1b]' + cmd + ';' + cleanPayload + term; | |
| }); | |
| } | |
| const processData = function(base64Data) { | |
| const binaryString = atob(base64Data); | |
| const cleanString = sanitizeOscTitleString(binaryString); | |
| const bytes = new Uint8Array(cleanString.length); | |
| for (let i = 0; i < cleanString.length; i++) { | |
| bytes[i] = cleanString.charCodeAt(i); | |
| } | |
| term.write(bytes); | |
| }; | |
| if (window.pendingConsoleData) { | |
| window.pendingConsoleData.forEach(data => processData(data)); | |
| window.pendingConsoleData = null; | |
| } | |
| window.onConsoleData = processData; | |
| term.onData(data => { | |
| if (window.ConsoleApp) { | |
| window.ConsoleApp.sendInput(data); | |
| window.ConsoleApp.onKeyProcessed(); | |
| } | |
| }); | |
| window.addEventListener('resize', () => { | |
| fitAddon.fit(); | |
| }); | |
| if (window.ConsoleApp) { | |
| window.ConsoleApp.onTerminalReady(); | |
| } | |
| </script> | |
| <script src="js/autofocus_fix.js"></script> | |
| </body> | |
| </html> |