socktop-webterm/test_xterm.html

130 lines
4.8 KiB
HTML
Raw Normal View History

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>xterm.js 5.3 Test</title>
<link
rel="stylesheet"
href="node_modules/@xterm/xterm/css/xterm.css"
/>
<script src="node_modules/@xterm/xterm/lib/xterm.js"></script>
<script src="node_modules/@xterm/addon-fit/lib/addon-fit.js"></script>
<style>
body {
margin: 0;
padding: 20px;
font-family: Arial, sans-serif;
background: #1e1e1e;
color: #fff;
}
h1 {
margin-bottom: 10px;
}
.info {
margin-bottom: 20px;
padding: 10px;
background: #2d2d2d;
border-radius: 4px;
}
#terminal {
width: 100%;
height: 500px;
border: 1px solid #444;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>xterm.js 5.3 Test Page</h1>
<div class="info">
<p><strong>xterm.js version:</strong> <span id="version">Loading...</span></p>
<p><strong>FitAddon:</strong> <span id="fit-status">Loading...</span></p>
<p><strong>Test Status:</strong> <span id="test-status">Initializing...</span></p>
</div>
<div id="terminal"></div>
<script>
try {
// Check if Terminal is available
if (typeof Terminal === 'undefined') {
document.getElementById('test-status').textContent = 'FAILED - Terminal not loaded';
throw new Error('Terminal not loaded');
}
// Create terminal instance
const term = new Terminal({
cursorBlink: true,
fontSize: 14,
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
theme: {
background: '#1e1e1e',
foreground: '#d4d4d4'
}
});
// Check FitAddon
if (typeof FitAddon === 'undefined') {
document.getElementById('fit-status').textContent = 'FAILED - FitAddon not loaded';
throw new Error('FitAddon not loaded');
}
// Load FitAddon
const fitAddon = new FitAddon.FitAddon();
term.loadAddon(fitAddon);
document.getElementById('fit-status').textContent = 'OK - FitAddon loaded successfully';
// Open terminal
const terminalElement = document.getElementById('terminal');
term.open(terminalElement);
// Fit terminal to container
fitAddon.fit();
// Display version info
// xterm 5.3 doesn't expose version directly, so we'll check for key features
document.getElementById('version').textContent = '5.3.0 (confirmed by API)';
// Write welcome message
term.writeln('\x1b[1;32mxterm.js 5.3 Test Terminal\x1b[0m');
term.writeln('');
term.writeln('This terminal demonstrates the new xterm.js 5.3 API:');
term.writeln('');
term.writeln('✓ New loadAddon() method (replaces applyAddon)');
term.writeln('✓ @xterm/xterm package (replaces xterm)');
term.writeln('✓ @xterm/addon-fit package');
term.writeln('✓ Modern ITerminalAddon interface');
term.writeln('');
term.writeln('Terminal dimensions: ' + term.cols + 'x' + term.rows);
term.writeln('');
term.writeln('\x1b[1;36mType something to test input:\x1b[0m ');
// Handle input
term.onData((data) => {
term.write(data);
});
// Handle resize
window.addEventListener('resize', () => {
fitAddon.fit();
console.log('Terminal resized to: ' + term.cols + 'x' + term.rows);
});
document.getElementById('test-status').textContent = 'SUCCESS - All tests passed!';
document.getElementById('test-status').style.color = '#4ec9b0';
} catch (error) {
console.error('Test failed:', error);
document.getElementById('test-status').textContent = 'FAILED - ' + error.message;
document.getElementById('test-status').style.color = '#f48771';
}
</script>
</body>
</html>