ghostty-web 0.3.0 → 0.4.0-next.1.g65aeac9

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/README.md CHANGED
@@ -1,141 +1,87 @@
1
1
  # ghostty-web
2
2
 
3
- ![ghostty](https://github.com/user-attachments/assets/aceee7eb-d57b-4d89-ac3d-ee1885d0187a)
4
-
5
- `ghostty-web` is a web terminal developed for [mux](https://github.com/coder/mux) that leverages
6
- [Ghostty's](https://github.com/ghostty-org/ghostty)
7
- terminal emulation core via WebAssembly. Because it leans on Ghostty to handle the complexity of terminal
8
- emulation, `ghostty-web` can deliver fast, robust terminal emulation in the browser. The intent is
9
- for this project to become a drop-in replacement for xterm.js. Under heavy development, no compatibility guarantees yet.
10
-
11
- ## Live Demo
12
-
13
- Try ghostty-web yourself with:
14
-
15
- ```bash
16
- npx @ghostty-web/demo@next
17
- ```
18
-
19
- This starts a local demo server with a real shell session. The demo server works best when run from Linux, but you can also try
20
- it on macOS. Windows is not supported (yet).
3
+ [![NPM Version](https://img.shields.io/npm/v/ghostty-web)](https://npmjs.com/package/ghostty-web) [![NPM Downloads](https://img.shields.io/npm/dw/ghostty-web)](https://npmjs.com/package/ghostty-web) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/ghostty-web)](https://npmjs.com/package/ghostty-web) [![license](https://img.shields.io/github/license/coder/ghostty-web)](./LICENSE)
21
4
 
22
- <details>
23
- <summary>Development setup (building from source)</summary>
5
+ [Ghostty](https://github.com/ghostty-org/ghostty) for the web with [xterm.js](https://github.com/xtermjs/xterm.js) API compatibility — giving you a proper VT100 implementation in the browser.
24
6
 
25
- > Requires Zig and Bun, see [Development](#development)
7
+ - Migrate from xterm by changing your import: `@xterm/xterm` → `ghostty-web`
8
+ - WASM-compiled parser from Ghostty—the same code that runs the native app
9
+ - Zero runtime dependencies, ~400KB WASM bundle
26
10
 
27
- ```bash
28
- git clone https://github.com/coder/ghostty-web
29
- cd ghostty-web
30
- bun install
31
- bun run build # Builds the WASM module and library
32
- bun run demo:dev # http://localhost:8000/demo/
33
- ```
34
-
35
- </details>
36
-
37
- ## Getting Started
11
+ Originally created for [Mux](https://github.com/coder/mux) (a desktop app for isolated, parallel agentic development), but designed to be used anywhere.
38
12
 
39
- Install the module via npm
40
-
41
- ```bash
42
- npm install ghostty-web
43
- ```
13
+ ## Try It
44
14
 
45
- After install, using `ghostty-web` is as simple as
46
-
47
- ```html
48
- <!doctype html>
49
- <html>
50
- <body>
51
- <div id="terminal"></div>
52
- <script type="module">
53
- import { init, Terminal } from 'ghostty-web';
54
-
55
- await init();
56
- const term = new Terminal();
57
- term.open(document.getElementById('terminal'));
58
- term.write('Hello from \x1B[1;3;31mghostty-web\x1B[0m $ ');
59
- </script>
60
- </body>
61
- </html>
62
- ```
15
+ - [Live Demo](https://ghostty.ondis.co) on an ephemeral VM (thank you to Greg from [disco.cloud](https://disco.cloud) for hosting).
63
16
 
64
- ## Features
17
+ - On your computer:
65
18
 
66
- `ghostty-web` compiles Ghostty's core terminal emulation engine (parser, state
67
- machine, and screen buffer) to WebAssembly, providing:
19
+ ```bash
20
+ npx @ghostty-web/demo@next
21
+ ```
68
22
 
69
- **Core Terminal:**
23
+ This starts a local HTTP server with a real shell on `http://localhost:8080`. Works best on Linux and macOS.
70
24
 
71
- - Full VT100/ANSI escape sequence support
72
- - True color (24-bit RGB) + 256 color + 16 ANSI colors
73
- - Text styles: bold, italic, underline, strikethrough, dim, reverse
74
- - Alternate screen buffer (for vim, htop, less, etc.)
75
- - Scrollback buffer with mouse wheel support
25
+ ![ghostty](https://github.com/user-attachments/assets/aceee7eb-d57b-4d89-ac3d-ee1885d0187a)
76
26
 
77
- **Input & Interaction:**
27
+ ## Comparison with xterm.js
78
28
 
79
- - Text selection and clipboard integration
80
- - Mouse tracking modes
81
- - Custom key/wheel event handlers
29
+ xterm.js is everywhere—VS Code, Hyper, countless web terminals. But it has fundamental issues:
82
30
 
83
- **API & Integration:**
31
+ | Issue | xterm.js | ghostty-web |
32
+ | ---------------------------------------- | ---------------------------------------------------------------- | -------------------------- |
33
+ | **Complex scripts** (Devanagari, Arabic) | Rendering issues | ✓ Proper grapheme handling |
34
+ | **XTPUSHSGR/XTPOPSGR** | [Not supported](https://github.com/xtermjs/xterm.js/issues/2570) | ✓ Full support |
84
35
 
85
- - xterm.js-compatible API (drop-in replacement for many use cases)
86
- - FitAddon for responsive terminal sizing
87
- - Event system (onData, onResize, onBell, onScroll, etc.)
36
+ xterm.js reimplements terminal emulation in JavaScript. Every escape sequence, every edge case, every Unicode quirk—all hand-coded. Ghostty's emulator is the same battle-tested code that runs the native Ghostty app.
88
37
 
89
- **Performance:**
38
+ ## Installation
90
39
 
91
- - Canvas-based rendering at 60 FPS
92
- - Zero runtime dependencies (just ghostty-web + bundled WASM)
93
- - Parser/state machine from Ghostty
40
+ ```bash
41
+ npm install ghostty-web
42
+ ```
94
43
 
95
- ## Usage Examples
44
+ ## Usage
96
45
 
97
- ### Basic Terminal
46
+ ghostty-web aims to be API-compatible with the xterm.js API.
98
47
 
99
- ```typescript
100
- import { init, Terminal, FitAddon } from 'ghostty-web';
48
+ ```javascript
49
+ import { init, Terminal } from 'ghostty-web';
101
50
 
102
- // Initialize WASM (call once at app startup)
103
51
  await init();
104
52
 
105
53
  const term = new Terminal({
106
- cursorBlink: true,
107
54
  fontSize: 14,
108
55
  theme: {
109
- background: '#1e1e1e',
110
- foreground: '#d4d4d4',
56
+ background: '#1a1b26',
57
+ foreground: '#a9b1d6',
111
58
  },
112
59
  });
113
60
 
114
- const fitAddon = new FitAddon();
115
- term.loadAddon(fitAddon);
116
-
117
61
  term.open(document.getElementById('terminal'));
118
- fitAddon.fit();
119
-
120
- // Handle user input
121
- term.onData((data) => {
122
- // Send to backend/PTY
123
- console.log('User typed:', data);
124
- });
62
+ term.onData((data) => websocket.send(data));
63
+ websocket.onmessage = (e) => term.write(e.data);
125
64
  ```
126
65
 
127
- ## Development
128
-
129
- ### Prerequisites
66
+ For a comprehensive client <-> server example, refer to the [demo](./demo/index.html#L141).
130
67
 
131
- - [bun](https://bun.com/docs/installation)
132
- - [zig](https://ziglang.org/download/)
68
+ ## Development
133
69
 
134
- ### Building WASM
70
+ ghostty-web builds from Ghostty's source with a [patch](./patches/ghostty-wasm-api.patch) to expose additional
71
+ functionality.
135
72
 
136
- `ghostty-web` builds a custom WASM binary from Ghostty's source with a patch to expose additional
137
- functionality
73
+ > Requires Zig and Bun.
138
74
 
139
75
  ```bash
140
76
  bun run build
141
77
  ```
78
+
79
+ Mitchell Hashimoto (author of Ghostty) has [been working](https://mitchellh.com/writing/libghostty-is-coming) on `libghostty` which makes this all possible. The patches are very minimal thanks to the work the Ghostty team has done, and we expect them to get smaller.
80
+
81
+ This library will eventually consume a native Ghostty WASM distribution once available, and will continue to provide an xterm.js compatible API.
82
+
83
+ At Coder we're big fans of Ghostty, so kudos to that team for all the amazing work.
84
+
85
+ ## License
86
+
87
+ [MIT](./LICENSE)
Binary file