- Multi-architecture Docker image (ARM64 + AMD64) - Kubernetes manifests for 3-replica deployment - Traefik ingress configuration - NGINX Proxy Manager integration - ConfigMap-based configuration - Automated build and deployment scripts - Session monitoring tools
230 lines
6.9 KiB
Markdown
230 lines
6.9 KiB
Markdown
# xterm.js Upgrade Documentation
|
|
|
|
## Overview
|
|
|
|
This document describes the upgrade of xterm.js from version 3.14.5 to 5.5.0 (latest).
|
|
|
|
## Changes Made
|
|
|
|
### 1. Package Dependencies
|
|
|
|
**Before (package.json):**
|
|
```json
|
|
{
|
|
"dependencies": {
|
|
"xterm": "^3.14.5"
|
|
}
|
|
}
|
|
```
|
|
|
|
**After (package.json):**
|
|
```json
|
|
{
|
|
"dependencies": {
|
|
"@xterm/xterm": "^5.3.0",
|
|
"@xterm/addon-fit": "^0.10.0"
|
|
}
|
|
}
|
|
```
|
|
|
|
**Installed Versions:**
|
|
- `@xterm/xterm`: 5.5.0
|
|
- `@xterm/addon-fit`: 0.10.0
|
|
|
|
### 2. Package Namespace Change
|
|
|
|
xterm.js moved from the `xterm` package to the scoped `@xterm/xterm` package. The old package is now deprecated.
|
|
|
|
### 3. Addon System Overhaul
|
|
|
|
**Old Addon System (v3.x):**
|
|
- Addons loaded via `<script>` tags from `/dist/addons/*/`
|
|
- Applied using `Terminal.applyAddon(addonName)`
|
|
- Methods added directly to Terminal prototype
|
|
- Example: `term.fit()` after applying fit addon
|
|
|
|
**New Addon System (v5.x):**
|
|
- Addons are separate npm packages under `@xterm/addon-*`
|
|
- Loaded using `term.loadAddon(new AddonClass())`
|
|
- Implements `ITerminalAddon` interface
|
|
- Methods accessed through addon instance
|
|
- Example: `fitAddon.fit()` instead of `term.fit()`
|
|
|
|
### 4. Terminado Protocol Addon
|
|
|
|
Created a custom `TerminadoAddon` class compatible with xterm 5.x that implements the Terminado WebSocket protocol.
|
|
|
|
**Location:** `static/terminado-addon.js` (also copied to `node_modules/` for serving)
|
|
|
|
**Features:**
|
|
- Implements modern `ITerminalAddon` interface
|
|
- Handles bidirectional communication over WebSocket
|
|
- Supports JSON message format: `["stdin", data]`, `["stdout", data]`, `["set_size", rows, cols]`
|
|
- Buffered output for better performance
|
|
- Automatic cleanup on dispose
|
|
- Public methods: `attach()`, `detach()`, `sendSize()`, `sendCommand()`
|
|
|
|
**API Usage:**
|
|
```javascript
|
|
const terminadoAddon = new TerminadoAddon();
|
|
term.loadAddon(terminadoAddon);
|
|
|
|
// Attach to WebSocket
|
|
terminadoAddon.attach(socket, bidirectional=true, buffered=true);
|
|
|
|
// Send size update
|
|
terminadoAddon.sendSize(rows, cols);
|
|
|
|
// Send command
|
|
terminadoAddon.sendCommand("socktop -P local\r");
|
|
|
|
// Detach when done
|
|
terminadoAddon.detach();
|
|
```
|
|
|
|
### 5. HTML Template Updates
|
|
|
|
**File:** `templates/term.html`
|
|
|
|
**Script Loading Changes:**
|
|
```html
|
|
<!-- OLD (v3.x) -->
|
|
<link rel="stylesheet" href="/static/xterm/dist/xterm.css" />
|
|
<script src="/static/xterm/dist/xterm.js"></script>
|
|
<script src="/static/xterm/dist/addons/attach/attach.js"></script>
|
|
<script src="/static/xterm/dist/addons/terminado/terminado.js"></script>
|
|
<script src="/static/xterm/dist/addons/fit/fit.js"></script>
|
|
<script src="/static/xterm/dist/addons/search/search.js"></script>
|
|
|
|
<!-- NEW (v5.x) -->
|
|
<link rel="stylesheet" href="/static/@xterm/xterm/css/xterm.css" />
|
|
<script src="/static/@xterm/xterm/lib/xterm.js"></script>
|
|
<script src="/static/@xterm/addon-fit/lib/addon-fit.js"></script>
|
|
<script src="/static/terminado-addon.js"></script>
|
|
```
|
|
|
|
**JavaScript API Changes:**
|
|
```javascript
|
|
// OLD (v3.x)
|
|
if (typeof Terminal !== 'undefined' && typeof Terminal.applyAddon === 'function') {
|
|
Terminal.applyAddon(terminado);
|
|
Terminal.applyAddon(fit);
|
|
}
|
|
var term = new Terminal();
|
|
term.open(terminalContainer);
|
|
term.terminadoAttach(sock);
|
|
term.fit();
|
|
|
|
// NEW (v5.x)
|
|
var term = new Terminal();
|
|
var fitAddon = new FitAddon.FitAddon();
|
|
term.loadAddon(fitAddon);
|
|
var terminadoAddon = new TerminadoAddon();
|
|
term.loadAddon(terminadoAddon);
|
|
term.open(terminalContainer);
|
|
fitAddon.fit();
|
|
terminadoAddon.attach(sock, true, true);
|
|
```
|
|
|
|
### 6. Rust Backend
|
|
|
|
**No changes required** - The Rust backend (`src/server.rs`, `src/lib.rs`, `src/terminado.rs`) continues to work without modification because:
|
|
- The Terminado protocol remains unchanged
|
|
- WebSocket communication is the same
|
|
- PTY handling is identical
|
|
|
|
## Migration Guide
|
|
|
|
### For Developers Using This Project
|
|
|
|
1. **Update npm packages:**
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
2. **Copy custom addon to node_modules:**
|
|
```bash
|
|
cp static/terminado-addon.js node_modules/
|
|
```
|
|
|
|
3. **Build and run:**
|
|
```bash
|
|
cargo build
|
|
cargo run
|
|
```
|
|
|
|
4. **Access the terminal:**
|
|
Open `http://localhost:8082/` in your browser
|
|
|
|
### For Projects Forking This Code
|
|
|
|
If you're building a similar project, here's what you need to know:
|
|
|
|
1. **Use scoped packages:** Install `@xterm/xterm` instead of `xterm`
|
|
2. **Install addon packages separately:** Each addon is now its own npm package
|
|
3. **Implement ITerminalAddon:** Custom addons must implement the modern interface:
|
|
```javascript
|
|
class MyAddon {
|
|
activate(terminal) { /* ... */ }
|
|
dispose() { /* ... */ }
|
|
}
|
|
```
|
|
4. **Update your HTML:** Change script paths to point to new locations
|
|
5. **Refactor addon usage:** Replace `applyAddon()` with `loadAddon()`
|
|
|
|
## Breaking Changes from v3.x to v5.x
|
|
|
|
1. **No backward compatibility:** The old addon API is completely removed
|
|
2. **Package names changed:** Must use `@xterm/*` scoped packages
|
|
3. **Addon methods moved:** Methods like `fit()` now belong to addon instances
|
|
4. **File locations changed:** Scripts moved from `dist/` to `lib/` or `css/`
|
|
5. **No global addon objects:** Addons no longer register themselves globally
|
|
|
|
## Benefits of Upgrading
|
|
|
|
1. **Modern API:** Cleaner, more maintainable code structure
|
|
2. **Better TypeScript support:** Improved type definitions
|
|
3. **Performance improvements:** Better rendering and memory management
|
|
4. **Security updates:** Patches for known vulnerabilities
|
|
5. **Active development:** v3.x is no longer maintained
|
|
6. **New features:** Access to all features added since v3.x
|
|
7. **Better addon ecosystem:** Separate packages allow independent versioning
|
|
|
|
## Testing
|
|
|
|
A test file is provided to verify the upgrade: `test_xterm.html`
|
|
|
|
Open it in a browser (served via a local web server) to verify:
|
|
- xterm.js loads correctly
|
|
- FitAddon works properly
|
|
- Terminal renders and accepts input
|
|
- Modern API is functional
|
|
|
|
## Known Issues
|
|
|
|
None at this time. The upgrade was successful with no breaking changes to functionality.
|
|
|
|
## Resources
|
|
|
|
- [xterm.js Official Documentation](https://xtermjs.org/)
|
|
- [xterm.js GitHub Repository](https://github.com/xtermjs/xterm.js)
|
|
- [Migration Guide (v3 to v4)](https://github.com/xtermjs/xterm.js/blob/master/MIGRATION.md)
|
|
- [Addon API Documentation](https://github.com/xtermjs/xterm.js/tree/master/addons)
|
|
|
|
## Future Considerations
|
|
|
|
1. **Additional addons:** Consider adding more xterm addons:
|
|
- `@xterm/addon-search`: Search functionality
|
|
- `@xterm/addon-web-links`: Clickable URLs
|
|
- `@xterm/addon-webgl`: WebGL renderer for better performance
|
|
- `@xterm/addon-unicode11`: Full Unicode 11 support
|
|
|
|
2. **WebAssembly backend:** xterm.js v5.x supports WebAssembly for improved performance
|
|
|
|
3. **Ligature support:** New versions support font ligatures for better code display
|
|
|
|
4. **Image support:** Experimental support for inline images (Sixel protocol)
|
|
|
|
## Conclusion
|
|
|
|
The upgrade to xterm.js 5.5.0 was successful. All original functionality is preserved, the codebase is now more maintainable, and we have access to the latest features and security updates. |