Ghostty 编译为 WASM,兼容 xterm.js API
Ghostty compiled to WASM with xterm.js API compatibility

原始链接: https://github.com/coder/ghostty-web

## Ghostty-web:浏览器中的真正VT100终端 Ghostty-web 使用 xterm.js API 为 Web 应用程序带来真正的 VT100 终端体验,不同于 xterm.js 这种 JavaScript 的*近似实现*。它利用相同的、经过实战检验的模拟器,为原生 Ghostty 应用程序提供支持,通过约 400KB 的 WASM 包实现,且没有任何运行时依赖。 最初为 Mux 应用程序开发,Ghostty-web 在 xterm.js 难以处理的方面表现出色——特别是对从右到左的语言、Devanagari 和阿拉伯语等复杂脚本的支持,以及对 XTPUSHSGR/XTPOPSGR 等功能的全面支持。 迁移很简单:将 `@xterm/xterm` 替换为 `ghostty-web`。可通过 `npx @ghostty-web/demo@next` 访问演示服务器。 Ghostty-web 使用 Zig 和 Bun 构建,目前正在修补 Ghostty 的源代码,但未来旨在利用原生 Ghostty WASM 分发版,同时保持与 xterm.js API 的兼容性。

## Ghostty-web:一个基于浏览器的终端模拟器 Kyle Carbs 将 Ghostty 终端模拟器编译为 WebAssembly (WASM),并兼容 xterm.js API。这使得 Ghostty 能够直接在浏览器中运行,可能成为 xterm.js 的直接替代品。 该项目目前是一个概念验证,未来的目标是性能优化。初步反馈表明,利用 Ghostty 的新 RenderState API 进行增量更新,有可能实现显著的速度提升。 演示地址:[https://ghostty.ondis.co/](https://ghostty.ondis.co/),源代码在 GitHub 上:[https://github.com/coder/ghostty-web](https://github.com/coder/ghostty-web)。开发者正在探索与 VS Code 等项目的集成,以及用于远程 shell 访问的工具。虽然目标是完全兼容 VT100,但网络演示中一些复杂脚本(如天城文)的问题正在调查中。
相关文章

原文

NPM Version NPM Downloads npm bundle size license

Ghostty for the web with xterm.js API compatibility — giving you a proper VT100 implementation in the browser, not a JavaScript approximation of one.

  • Migrate from xterm by changing your import: @xterm/xtermghostty-web
  • WASM-compiled parser from Ghostty—the same code that runs the native app
  • Zero runtime dependencies, ~400KB WASM bundle

Originally created for Mux (a desktop app for isolated, parallel agentic development), but designed to be used anywhere.

npx @ghostty-web/demo@next

This starts a local HTTP server with a real shell on http://localhost:8080. Works best on Linux and macOS.

ghostty

xterm.js is everywhere—VS Code, Hyper, countless web terminals. But it has fundamental issues:

Issue xterm.js ghostty-web
RTL languages Broken since 2017 ✓ Works
Complex scripts (Devanagari, Arabic) Rendering issues ✓ Proper grapheme handling
XTPUSHSGR/XTPOPSGR Not supported ✓ Full support

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.

ghostty-web aims to be API-compatible with the xterm.js API.

import { init, Terminal } from 'ghostty-web';

await init();

const term = new Terminal({
  fontSize: 14,
  theme: {
    background: '#1a1b26',
    foreground: '#a9b1d6',
  },
});

term.open(document.getElementById('terminal'));
term.onData((data) => websocket.send(data));
websocket.onmessage = (e) => term.write(e.data);

For a comprehensive client <-> server example, refer to the demo.

ghostty-web builds from Ghostty's source with a patch to expose additional functionality.

Requires Zig and Bun.

Mitchell Hashimoto (author of Ghostty) has been working 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.

This library will eventually consume a native Ghostty WASM distribution once available, and will continue to provide an xterm.js compatible API.

At Coder we're big fans of Ghostty, so kudos to that team for all the amazing work.

MIT

联系我们 contact @ memedata.com