Ghostel.el: Terminal emulator powered by libghostty
306 points
• 5 days ago
• Article
Link
Ghostel 是一个由 libghostty-vt 驱动的 Emacs 终端模拟器,与 Ghostty 共享同一引擎。它采用双层架构:用 Zig 编写的本地动态模块负责终端状态、渲染和本地 PTY 的输入 / 输出,Emacs Lisp 则负责用户界面、键位映射和进程编排。这样的设计使 Ghostel 能在 Emacs 中实现现代终端功能,包括对 Kitty 的 keyboard 和 graphics 协议、 OSC 8 超链接、真彩色和同步输出的支持。
该模拟器既适用于本地也适用于远程场景。在本地 PTY 模式下,它会将终端解析卸载到后台线程,从而提供高性能的输出处理,即使在大量数据涌入时也能保持 Emacs 界面的流畅响应。通过 TRAMP 进行的远程会话则依赖 Emacs 自身的进程机制,便于跨主机无缝集成。与 vterm 和 eat 等替代方案相比,Ghostel 的特色包括更丰富的下划线样式、全面的鼠标透传以及可扩展的密码提示检测机制以保障输入安全。
用户可以在五种输入模式间切换以实现灵活的导航与编辑。默认的 semi-char 模式会将大多数按键转发给终端,同时为 Emacs 保留若干命令;专用的 Emacs 模式和 copy 模式则提供终端缓冲区的只读视图,便于搜索和选择文本;line mode 会在本地缓冲输入,允许以标准 Emacs 方式编辑后再一次性发送整行到 shell 。这些模式切换方便,且 Ghostel 支持为 bash 、 zsh 、 fish 等常用 shell 自动集成目录跟踪和提示符导航,无需手动配置文件。
通过 evil-ghostel 等扩展可获得类似 Vim 的键位绑定,针对 compilation-mode 和 Eshell 的集成层也能让 Ghostel 直接替代传统终端缓冲区。系统还提供远程终端管理工具(例如为 SSH 会话自动安装 terminfo)并开放钩子,方便用户根据终端输出触发通知或进度指示等自定义集成。 Ghostel 在兼顾性能与兼容性的同时,为 Emacs 提供了深度集成的现代终端体验。
Ghostel is an Emacs terminal emulator powered by the libghostty-vt engine, the same technology that drives the Ghostty terminal. It utilizes a two-layer architecture, where a native dynamic module written in Zig handles terminal state, rendering, and local PTY input/output, while Emacs Lisp manages the user interface, keymaps, and process orchestration. This design allows Ghostel to bring modern terminal capabilities to Emacs, including support for the Kitty keyboard and graphics protocols, OSC 8 hyperlinks, true color, and synchronized output.
The emulator is designed for both local and remote use, offering high performance by offloading terminal parsing to a background thread when using its native PTY mode. For local shells, this results in rapid output handling that keeps the Emacs interface responsive even during heavy data floods. Remote sessions via TRAMP utilize Emacs's own process machinery, allowing for seamless integration across different hosts. Ghostel distinguishes itself from alternatives like vterm and eat by providing a robust feature set that includes advanced underline styles, comprehensive mouse passthrough, and an extensible system for detecting password prompts to ensure secure input.
Users can interact with Ghostel through five distinct input modes, allowing for flexible navigation and editing. The default semi-char mode forwards most keystrokes to the terminal while reserving specific commands for Emacs, while dedicated Emacs and copy modes provide read-only views of the terminal buffer for searching and selecting text. A line mode is also available, which buffers input locally to allow for standard Emacs editing before sending a complete line to the shell. These modes can be toggled easily, and the emulator supports automatic shell integration for popular shells like bash, zsh, and fish, enabling features such as directory tracking and prompt navigation without requiring manual configuration files.
Extensions such as evil-ghostel for Vim-like keybindings, as well as specific integration layers for compilation-mode and Eshell, allow Ghostel to function as a drop-in replacement for traditional terminal buffers. The system also includes utilities for managing remote terminals, including automatic terminfo installation for SSH sessions, and provides hooks for user-defined integrations, such as triggering notifications or progress indicators based on terminal output. By prioritizing both performance and compatibility, Ghostel offers a modern terminal experience that integrates deeply into the Emacs environment.
67 comments • Comments Link
• Ghostel 是为 Emacs 设计的终端模拟器,基于 libghostty-vt,相较于现有的 Emacs 终端(如 vterm 和 eat)在性能和可靠性上有显著提升。
• 通过把终端输出直接集成到 Emacs 缓冲区,Ghostel 实现了 Emacs 的原生功能,例如在终端输出中用键盘高效选取文本、搜索和导航。
• 该项目将回溯(scrollback)视为不可变对象,并利用 libghostty-vt 提供的行级脏标志来最大限度减少更新 Emacs 缓冲区的开销,从而保持高性能。
• 项目提供一种 "line-mode",旨在提供类似于 M-x shell 的体验,允许用户像操作普通 Emacs 缓冲区那样与文本交互,但在处理交互式 TUI 应用时仍面临挑战。
• 用户反馈表明,尽管 Ghostel 在响应速度和应对重负载 TUI 工作方面有明显改善,但仍会偶发 UI 故障和稳定性问题,开发者正在积极修复这些问题。
• 由于 Emacs 包管理器(如 MELPA)的限制,原生模块需要提供预构建二进制,这意味着首次运行时需要下载或编译,这是高性能 Emacs 扩展的常见做法。
• 在 Emacs 内的终端模拟在概念上不同于外部终端:它把终端作为编辑、编码和系统交互的核心枢纽,而不是一个独立的隔离环境,从而带来独特的工作流优势。
• 包括 Ghostty 及其衍生实现等现代终端,对高分辨率显示和大量日志处理有实质性好处,GPU 加速渲染带来的性能提升对高级用户尤为有利。
• 与 TUI 应用的兼容性问题通常源于通过 SSH 使用较新模拟器时 TERM 变量不匹配,常见的解决办法是安装相应的 terminfo 条目或回退到 xterm-256color 。
总体来看,讨论反映出社区对将高性能终端直接引入 Emacs 的强烈热情,优先考虑深度编辑器集成而非将终端作为孤立应用。尽管用户认可这种方法带来的显著性能优势和改进的工作流潜力,也承认该项目尚在成熟过程中,当前主要在修复渲染边界情况和稳定性错误。社区普遍认为,对于许多高级用户来说,在原生编辑器内操作终端输出的优势,超过了早期开发阶段和安装原生依赖所带来的小幅不便。 • Ghostel is a terminal emulator for Emacs that leverages the libghostty-vt library, offering significant performance improvements and reliability over existing Emacs-based terminals like vterm and eat.
• By integrating terminal output directly into Emacs buffers, the tool enables native Emacs capabilities such as efficient keyboard-based text selection, searching, and navigation within terminal output.
• The project architecture maintains high performance by treating scrollback as immutable and utilizing row-level dirty flags from libghostty-vt to minimize the overhead of updating the Emacs buffer.
• A "line-mode" is available to provide an experience similar to `M-x shell`, allowing users to interact with text as a standard Emacs buffer, though this mode faces challenges with interactive TUI applications.
• Users report that while Ghostel is a significant upgrade in responsiveness and compatibility with heavy TUI workloads, it currently exhibits occasional UI glitches and stability issues that are being addressed by active development.
• The requirement for prebuilt binaries for native modules—due to limitations in Emacs package managers like MELPA—necessitates a first-run download or compilation process, which is standard practice for similar high-performance Emacs extensions.
• Terminal emulation within Emacs is conceptually distinct from external terminal emulators, offering a unique workflow where the terminal serves as a central hub for editing, coding, and system interaction rather than a separate isolated environment.
• Modern terminal implementations, including Ghostty and its derivatives, offer substantial benefits for high-resolution displays and heavy logging, making the performance gain from GPU-accelerated rendering a tangible benefit for power users.
• Compatibility issues with TUI applications, often attributed to `TERM` variable mismatches when using newer emulators over SSH, are typically mitigated by installing specific terminfo entries or falling back to `xterm-256color`.
The discussion reflects a strong enthusiasm for bringing high-performance terminal emulation directly into the Emacs environment, prioritizing deep editor integration over the isolation of standalone terminal applications. While users highlight the clear performance benefits and superior workflow possibilities of this approach, there is a clear acknowledgment that the project is in a maturing phase with ongoing efforts to resolve rendering edge cases and stability bugs. The community consensus suggests that for many power users, the ability to manipulate terminal output with native editor tools outweighs the minor friction points associated with early-stage development and installation of native dependencies.