Hacker News 中文摘要

RSS订阅

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

文章摘要

该项目是Ghostty的网页版,兼容xterm.js API,可在浏览器中运行终端模拟器。

文章总结

GitHub 项目:ghostty-web

项目名称:ghostty-web
项目地址:https://github.com/coder/ghostty-web
项目简介
ghostty-web 是一个基于 Ghostty 的 Web 终端模拟器,兼容 xterm.js 的 API。它通过 WASM 编译的 Ghostty 解析器,在浏览器中实现了真正的 VT100 终端功能,而非 JavaScript 的近似实现。

主要特点:

  1. 兼容性

    • 可直接替换 xterm.js,只需将导入从 @xterm/xterm 改为 ghostty-web
    • 使用与原生 Ghostty 应用相同的代码,确保终端行为的准确性。
  2. 性能与体积

    • 零运行时依赖,WASM 包大小约 400KB。
  3. 功能优势

    • 支持 RTL 语言(如阿拉伯语)、复杂脚本(如梵文、阿拉伯文)和 XTPUSHSGR/XTPOPSGR 等 xterm.js 未完全支持的功能。

快速体验:

shell npx @ghostty-web/demo@next 运行后会在本地启动一个 HTTP 服务器,提供真实的终端环境(支持 Linux 和 macOS)。

安装与使用:

shell npm install ghostty-web 示例代码: ```javascript 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); ```

开发与构建:

项目基于 Ghostty 源码,并通过补丁扩展功能。构建需 Zig 和 Bun: shell bun run build

背景:

ghostty-web 最初为 Mux(一个并行开发工具)设计,但可广泛应用于任何需要终端模拟的场景。未来计划直接使用 Ghostty 官方的 WASM 分发版。

许可证:

MIT

项目状态:

  • 星标数:252
  • Fork 数:10
  • 主要语言:TypeScript(99.4%)

贡献者:

包括 Jon AyersKyle Carberry 等。

评论总结

总结评论内容:

  1. 赞赏与肯定
  • 多位用户对Kyle的工作表示惊叹和赞赏,认为这是令人印象深刻的项目 "Holy shit Kyle... This is amazing" (mitchellh) "omg! Seriously, wow. That was quick!" (pmarreck)
  1. 性能优化建议
  • 有评论指出当前实现可能存在性能问题,建议使用RenderState API来提升渲染效率 "the way you're grabbing the viewport seems expensive... The RenderState API is stateful and produces the state necessary to create a high-performance" (mitchellh) "You're doing per row line grabbing currently which is probably pretty slow" (mitchellh)
  1. 功能扩展建议
  • 用户建议添加更多功能,如浏览器内完整shell支持、GPU着色器等 "you could add... a fully featured in browser shell with support for installing packages" (someguy101010) "Does this version support custom GPU shaders?" (oersted)
  1. 集成可能性探讨
  • 多个评论讨论与其他工具集成的可能性,如VS Code、Zed、ttyd等 "could someone now make a Visual Studio Code... that has ghostty-web as the Terminal?" (VikingCoder) "might try hacking this into https://tsl0922.github.io/ttyd/" (jordemort)
  1. 演示需求
  • 部分用户表示希望看到托管演示版本 "No hosted demo?" (ivanjermakov) "can you do a hosted demo with jslinux (or similar) as backend?" (asadm)
  1. 新手疑问
  • 有用户表示对项目理解有限,希望获得简单解释 "I have no understanding of any of this... Can someone do a ELI5 for the uninitiated?" (warunsl)