ghostty-web 0.1.1 → 0.2.0-next.1.gc1b82ab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -234
- package/dist/ghostty-vt.wasm +0 -0
- package/dist/ghostty-web.js +1707 -557
- package/dist/ghostty-web.umd.cjs +4 -3
- package/dist/index.d.ts +715 -9
- package/ghostty-vt.wasm +0 -0
- package/package.json +6 -6
- package/INSTALL.md +0 -181
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Coder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,293 +1,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ghostty-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`ghostty-web` is a fully-featured web terminal built on [Ghostty's](https://github.com/ghostty-org/ghostty)
|
|
6
|
+
terminal emulation core compiled to WebAssembly. By leveraging Ghostty's production-tested VT100 parser
|
|
7
|
+
and state machine, `ghostty-web` delivers fast, robust terminal emulation in the browser. For many use
|
|
8
|
+
cases it is a drop-in replacement for xterm.js.
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
npm install @coder/ghostty-web
|
|
9
|
-
```
|
|
10
|
+
## Live Demo
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
You can try ghostty-web yourself:
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```
|
|
14
|
+
> [!NOTE]
|
|
15
|
+
> Requires Zig and Bun, see [Development](#development)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/coder/ghostty-web
|
|
19
|
+
cd ghostty-web
|
|
20
|
+
bun install
|
|
21
|
+
bun run build # Builds the WASM module and library
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
# Terminal 1: Start PTY Server
|
|
24
|
+
cd demo/server
|
|
25
|
+
bun install
|
|
26
|
+
bun run start
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
term.write('Hello, World!\r\n');
|
|
28
|
+
# Terminal 2: Start web server
|
|
29
|
+
bun run start # http://localhost:8000/demo/
|
|
25
30
|
```
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## Features
|
|
30
|
-
|
|
31
|
-
- ✅ Full xterm.js-compatible API
|
|
32
|
-
- ✅ Production-tested VT100 parser (via Ghostty)
|
|
33
|
-
- ✅ ANSI colors (16, 256, RGB true color)
|
|
34
|
-
- ✅ Canvas rendering at 60 FPS
|
|
35
|
-
- ✅ Scrollback buffer
|
|
36
|
-
- ✅ Text selection & clipboard
|
|
37
|
-
- ✅ FitAddon for responsive sizing
|
|
38
|
-
- ✅ TypeScript declarations included
|
|
32
|
+
## Getting Started
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Shell Terminal Demo
|
|
43
|
-
|
|
44
|
-
**Requires server**
|
|
34
|
+
Install the module via npm
|
|
45
35
|
|
|
46
36
|
```bash
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
bun install
|
|
50
|
-
bun run start
|
|
51
|
-
|
|
52
|
-
# Terminal 2: Start web server (from project root)
|
|
53
|
-
bun run dev
|
|
37
|
+
npm install ghostty-web
|
|
38
|
+
```
|
|
54
39
|
|
|
55
|
-
|
|
40
|
+
After install, using `ghostty-web` is as simple as
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<!doctype html>
|
|
44
|
+
<html>
|
|
45
|
+
<body>
|
|
46
|
+
<div id="terminal"></div>
|
|
47
|
+
<script type="module">
|
|
48
|
+
import { Terminal } from 'ghostty-web';
|
|
49
|
+
const term = new Terminal();
|
|
50
|
+
await term.open(document.getElementById('terminal'));
|
|
51
|
+
term.write('Hello from \x1B[1;3;31mghostty-web\x1B[0m $ ');
|
|
52
|
+
</script>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
56
55
|
```
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
## Features
|
|
59
58
|
|
|
60
|
-
-
|
|
61
|
-
|
|
62
|
-
- Use tab completion and command history (↑/↓)
|
|
63
|
-
- Use pipes, redirects, and background jobs
|
|
64
|
-
- Access all your shell aliases and environment
|
|
59
|
+
`ghostty-web` compiles Ghostty's core terminal emulation engine (parser, state
|
|
60
|
+
machine, and screen buffer) to WebAssembly, providing:
|
|
65
61
|
|
|
66
|
-
**
|
|
62
|
+
**Core Terminal:**
|
|
67
63
|
|
|
68
|
-
|
|
64
|
+
- Full VT100/ANSI escape sequence support
|
|
65
|
+
- True color (24-bit RGB) + 256 color + 16 ANSI colors
|
|
66
|
+
- Text styles: bold, italic, underline, strikethrough, dim, reverse
|
|
67
|
+
- Alternate screen buffer (for vim, htop, less, etc.)
|
|
68
|
+
- Scrollback buffer with mouse wheel support
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
cd demo/server
|
|
72
|
-
bun run file-browser
|
|
73
|
-
```
|
|
70
|
+
**Input & Interaction:**
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
- Text selection and clipboard integration
|
|
73
|
+
- Mouse tracking modes
|
|
74
|
+
- Kitty keyboard protocol support
|
|
75
|
+
- Custom key/wheel event handlers
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
- Port 3001 (WebSocket server)
|
|
77
|
+
**API & Integration:**
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
- xterm.js-compatible API (drop-in replacement for many use cases)
|
|
80
|
+
- FitAddon for responsive terminal sizing
|
|
81
|
+
- Event system (onData, onResize, onBell, onScroll, etc.)
|
|
81
82
|
|
|
82
|
-
**
|
|
83
|
+
**Performance:**
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
```
|
|
85
|
+
- Canvas-based rendering at 60 FPS
|
|
86
|
+
- Zero runtime dependencies (just ghostty-web + bundled WASM)
|
|
87
|
+
- Parser/state machine from Ghostty
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
## Why ghostty-web?
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
- **Don't reimplement VT100 parsing** – it's thousands of edge cases refined over years. Instead, leverage Ghostty's battle-tested terminal emulator that's proven by thousands of daily users.
|
|
92
|
+
- **Drop-in xterm.js replacement** – for many use cases, ghostty-web can replace xterm.js with minimal code changes
|
|
93
|
+
- **Modern & maintained** – Built on Ghostty, an actively developed modern terminal emulator, ensuring continued improvements and bug fixes.
|
|
94
|
+
|
|
95
|
+
## Usage Examples
|
|
92
96
|
|
|
93
97
|
### Basic Terminal
|
|
94
98
|
|
|
95
99
|
```typescript
|
|
96
|
-
import { Terminal } from '
|
|
97
|
-
import { FitAddon } from './lib/addons/fit.ts';
|
|
100
|
+
import { Terminal, FitAddon } from 'ghostty-web';
|
|
98
101
|
|
|
99
|
-
// Create terminal
|
|
100
102
|
const term = new Terminal({
|
|
101
|
-
cols: 80,
|
|
102
|
-
rows: 24,
|
|
103
103
|
cursorBlink: true,
|
|
104
|
+
fontSize: 14,
|
|
104
105
|
theme: {
|
|
105
106
|
background: '#1e1e1e',
|
|
106
107
|
foreground: '#d4d4d4',
|
|
107
108
|
},
|
|
108
109
|
});
|
|
109
110
|
|
|
110
|
-
// Add FitAddon for responsive sizing
|
|
111
111
|
const fitAddon = new FitAddon();
|
|
112
112
|
term.loadAddon(fitAddon);
|
|
113
113
|
|
|
114
|
-
// Open in container
|
|
115
114
|
await term.open(document.getElementById('terminal'));
|
|
116
115
|
fitAddon.fit();
|
|
117
116
|
|
|
118
|
-
// Write output (supports ANSI colors)
|
|
119
|
-
term.write('Hello, World!\r\n');
|
|
120
|
-
term.write('\x1b[1;32mGreen bold text\x1b[0m\r\n');
|
|
121
|
-
|
|
122
117
|
// Handle user input
|
|
123
118
|
term.onData((data) => {
|
|
119
|
+
// Send to backend/PTY
|
|
124
120
|
console.log('User typed:', data);
|
|
125
|
-
// Send to backend, echo, etc.
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### WebSocket Integration
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
const ws = new WebSocket('ws://localhost:3001/ws');
|
|
133
|
-
|
|
134
|
-
// Send user input to backend
|
|
135
|
-
term.onData((data) => {
|
|
136
|
-
ws.send(JSON.stringify({ type: 'input', data }));
|
|
137
121
|
});
|
|
138
|
-
|
|
139
|
-
// Display backend output
|
|
140
|
-
ws.onmessage = (event) => {
|
|
141
|
-
const msg = JSON.parse(event.data);
|
|
142
|
-
term.write(msg.data);
|
|
143
|
-
};
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
See [AGENTS.md](AGENTS.md) for development guide and code patterns.
|
|
147
|
-
|
|
148
|
-
## Why This Approach?
|
|
149
|
-
|
|
150
|
-
**DON'T** re-implement VT100 parsing from scratch (years of work, thousands of edge cases).
|
|
151
|
-
|
|
152
|
-
**DO** use Ghostty's proven parser:
|
|
153
|
-
|
|
154
|
-
- ✅ Battle-tested by thousands of users
|
|
155
|
-
- ✅ Handles all VT100/ANSI quirks correctly
|
|
156
|
-
- ✅ Modern features (RGB colors, Kitty keyboard protocol)
|
|
157
|
-
- ✅ Get bug fixes and updates for free
|
|
158
|
-
|
|
159
|
-
**You build**: Screen buffer, rendering, UI (the "easy" parts in TypeScript)
|
|
160
|
-
**Ghostty handles**: VT100 parsing (the hard part via WASM)
|
|
161
|
-
|
|
162
|
-
## Architecture
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
┌─────────────────────────────────────────┐
|
|
166
|
-
│ Terminal (lib/terminal.ts) │
|
|
167
|
-
│ - Public xterm.js-compatible API │
|
|
168
|
-
│ - Event handling (onData, onResize) │
|
|
169
|
-
└───────────┬─────────────────────────────┘
|
|
170
|
-
│
|
|
171
|
-
├─► ScreenBuffer (lib/buffer.ts)
|
|
172
|
-
│ - 2D grid, cursor, scrollback
|
|
173
|
-
│
|
|
174
|
-
├─► VTParser (lib/vt-parser.ts)
|
|
175
|
-
│ - ANSI escape sequence parsing
|
|
176
|
-
│ └─► Ghostty WASM (SGR parser)
|
|
177
|
-
│
|
|
178
|
-
├─► CanvasRenderer (lib/renderer.ts)
|
|
179
|
-
│ - Canvas-based rendering
|
|
180
|
-
│ - 60 FPS, supports all colors
|
|
181
|
-
│
|
|
182
|
-
└─► InputHandler (lib/input-handler.ts)
|
|
183
|
-
- Keyboard events → escape codes
|
|
184
|
-
└─► Ghostty WASM (Key encoder)
|
|
185
|
-
|
|
186
|
-
WebSocket Server (server/file-browser-server.ts)
|
|
187
|
-
└─► Executes shell commands (ls, cd, cat, etc.)
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## Project Structure
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
├── lib/
|
|
194
|
-
│ ├── terminal.ts - Main Terminal class (xterm.js-compatible)
|
|
195
|
-
│ ├── buffer.ts - Screen buffer with scrollback
|
|
196
|
-
│ ├── vt-parser.ts - VT100/ANSI escape sequence parser
|
|
197
|
-
│ ├── renderer.ts - Canvas-based renderer
|
|
198
|
-
│ ├── input-handler.ts - Keyboard input handling
|
|
199
|
-
│ ├── ghostty.ts - Ghostty WASM wrapper
|
|
200
|
-
│ ├── types.ts - TypeScript type definitions
|
|
201
|
-
│ ├── interfaces.ts - xterm.js-compatible interfaces
|
|
202
|
-
│ └── addons/
|
|
203
|
-
│ └── fit.ts - FitAddon for responsive sizing
|
|
204
|
-
│
|
|
205
|
-
├── demo/
|
|
206
|
-
│ ├── index.html - File browser terminal
|
|
207
|
-
│ ├── colors-demo.html - ANSI colors showcase
|
|
208
|
-
│ └── server/
|
|
209
|
-
│ ├── file-browser-server.ts - WebSocket server
|
|
210
|
-
│ ├── package.json
|
|
211
|
-
│ └── start.sh - Startup script (auto-kills port conflicts)
|
|
212
|
-
│
|
|
213
|
-
├── docs/
|
|
214
|
-
│ └── API.md - Complete API documentation
|
|
215
|
-
│
|
|
216
|
-
└── ghostty-vt.wasm - Ghostty VT100 parser (122 KB)
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## Building WASM
|
|
220
|
-
|
|
221
|
-
The WASM binary is built from source, not committed to the repo.
|
|
222
|
-
|
|
223
|
-
**Requirements:**
|
|
224
|
-
|
|
225
|
-
- Zig 0.15.2+
|
|
226
|
-
- Git submodules initialized
|
|
227
|
-
|
|
228
|
-
**Build:**
|
|
229
|
-
|
|
230
|
-
```bash
|
|
231
|
-
# Initialize submodule (first time only)
|
|
232
|
-
git submodule update --init --recursive
|
|
233
|
-
|
|
234
|
-
# Build WASM
|
|
235
|
-
./scripts/build-wasm.sh
|
|
236
|
-
# or
|
|
237
|
-
bun run build:wasm
|
|
238
122
|
```
|
|
239
123
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
1. Initializes `ghostty/` submodule (ghostty-org/ghostty)
|
|
243
|
-
2. Applies patches from `patches/ghostty-wasm-api.patch`
|
|
244
|
-
3. Builds WASM with Zig (takes ~20 seconds)
|
|
245
|
-
4. Outputs `ghostty-vt.wasm` (404 KB)
|
|
246
|
-
5. Reverts patch to keep submodule clean
|
|
124
|
+
## Development
|
|
247
125
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
```bash
|
|
251
|
-
cd ghostty
|
|
252
|
-
git fetch origin
|
|
253
|
-
git checkout <commit-or-tag>
|
|
254
|
-
cd ..
|
|
255
|
-
./scripts/build-wasm.sh
|
|
256
|
-
# Test, then commit the updated submodule pointer
|
|
257
|
-
```
|
|
126
|
+
### Prerequisites
|
|
258
127
|
|
|
259
|
-
|
|
128
|
+
- [bun](https://bun.com/docs/installation)
|
|
129
|
+
- [zig](https://ziglang.org/download/)
|
|
260
130
|
|
|
261
|
-
|
|
131
|
+
### Building WASM
|
|
262
132
|
|
|
263
|
-
|
|
133
|
+
`ghostty-web` builds a custom WASM binary from Ghostty's source with patches to expose additional
|
|
134
|
+
browser-specific functionality
|
|
264
135
|
|
|
265
136
|
```bash
|
|
266
|
-
bun
|
|
267
|
-
bun test --watch # Watch mode
|
|
268
|
-
bun run typecheck # Type checking
|
|
269
|
-
bun run build # Build distribution
|
|
137
|
+
bun run build
|
|
270
138
|
```
|
|
271
|
-
|
|
272
|
-
**Test Coverage:**
|
|
273
|
-
|
|
274
|
-
- ✅ ScreenBuffer (63 tests, 163 assertions)
|
|
275
|
-
- ✅ VTParser (45 tests)
|
|
276
|
-
- ✅ CanvasRenderer (11 tests)
|
|
277
|
-
- ✅ InputHandler (35 tests)
|
|
278
|
-
- ✅ Terminal integration (25 tests)
|
|
279
|
-
- ✅ FitAddon (12 tests)
|
|
280
|
-
|
|
281
|
-
## Documentation
|
|
282
|
-
|
|
283
|
-
- **[AGENTS.md](AGENTS.md)** - Development guide for AI agents and developers
|
|
284
|
-
|
|
285
|
-
## Links
|
|
286
|
-
|
|
287
|
-
- [Ghostty Terminal](https://github.com/ghostty-org/ghostty)
|
|
288
|
-
- [libghostty-vt API](https://github.com/ghostty-org/ghostty/tree/main/include/ghostty/vt)
|
|
289
|
-
- [VT100 Reference](https://vt100.net/docs/vt100-ug/)
|
|
290
|
-
|
|
291
|
-
## License
|
|
292
|
-
|
|
293
|
-
See cmux LICENSE (AGPL-3.0)
|
package/dist/ghostty-vt.wasm
CHANGED
|
Binary file
|