在现代开发者的工具箱中,终端模拟器占据着不可或缺的位置。虽然市面上已经存在许多优秀的终端模拟器,但它们通常在速度、功能和原生用户界面之间做出取舍。Ghostty 终端的出现,旨在打破这种平衡限制,提供一个同时具备快速响应、功能丰富和原生体验的终端工具。 Ghostty 旨在打破这种不可能三角的处境。在所有终端软件中,Ghostty 是可能不是最好的(即最快、功能最丰富或最原生)。但 Ghostty 在这三方面都做好了平衡,并且不需要你在这之间做出取舍。Ghostty 还打算推动终端模拟器的可能性,通过提供现代的、可选的功能,使 CLI 工具开发者能够构建更丰富、互动性更强的应用程序。
Ghostty 的开发是由 Mitchell Hashimoto 发起的个人项目。作为一款开源软件,它由一群充满热情的贡献者共同维护。Ghostty 的设计初衷并非追求市场垄断,而是希望为开发者提供一个功能完整且使用体验优越的终端工具。Ghostty 主要具有以下优势:
原生体验
Ghostty 的界面和交互完全符合 macOS 和 Linux 的桌面环境特性。它利用系统的本地 API 提供熟悉的快捷键、窗口管理和独特的系统功能支持(如 macOS 的 Quick Look 和安全输入 API)。
功能丰富
Ghostty 支持包括 Kitty 图形协议、超链接、深浅色主题切换在内的多种现代终端特性。同时,它还支持标签页、分屏和下拉终端等高阶应用功能。
快速响应
Ghostty 在启动时间、滚动速度、I/O 吞吐量等多个维度追求性能优化。虽然“快”是一个相对的概念,但 Ghostty 的用户普遍反映其速度提升显著,足以改善日常使用体验。
通过一套共享核心库 libghostty,Ghostty 将终端仿真、字体处理和渲染功能与图形用户界面分离。这种架构不仅确保了高效的开发和维护,也为其他项目基于同一核心创建多样化的终端工具提供了可能性。
接下来的内容将详细介绍如何安装和配置 Ghostty
可以通过官方下载链接进行下载, https://ghostty.org/download
这里我使用 Homebrew 进行安装
bashbrew install --cask ghostty
这里是我的基本配置, 主题色与原来的保持一致 ( Apple System Colors).
如果你想要更多自定义配置可以参考 官方文档 或者也可以使用 图形化的配置 后将配置导出, 然后粘贴到 $HOME/Library/Application\ Support/com.mitchellh.ghostty/config
文件中
ini# Config generated by Ghostty Config
# 默认的命令解释器,这里我使用的是 fish shell
command = /opt/homebrew/bin/fish
working-directory = home
clipboard-read = allow
clipboard-write = allow
copy-on-select = true
background-opacity = 0.75
background-blur-radius = 10
window-height = 24
window-width = 80
theme = Apple System Colors
background = #1e1e1e
selection-background = #3f638b
selection-foreground = #ffffff
cursor-color = #98989d
palette = 0=#1a1a1a
palette = 1=#cc372e
palette = 2=#26a439
palette = 3=#cdac08
palette = 4=#0869cb
palette = 5=#9647bf
palette = 6=#479ec2
palette = 7=#98989d
palette = 8=#464646
palette = 9=#ff453a
palette = 10=#32d74b
palette = 11=#ffd60a
palette = 12=#0a84ff
palette = 13=#bf5af2
palette = 14=#76d6ff
palette = 15=#ffffff
font-size = 18
font-thicken = true
macos-titlebar-style = native
font-family = Roboto Mono Regular
在使用 Ghostty SSH 连接服务器时,可能会出现以下问题:
txtwarning: Could not set up terminal. warning: TERM environment variable set to 'xterm-ghostty'. warning: Check that this terminal type is supported on this system. warning: Using fallback terminal type 'xterm-256color'.
或者在使用部分命令时提示
bashroot@kevin ~# clear
'xterm-ghostty': unknown terminal type.
要解决这个问题我们需要复制Ghostty的terminfo条目到远程机器。在目标服务器需要执行以下命令
bashinfocmp -x | ssh USER@YOUR-SERVER -- tic -x -
例如:
bashinfocmp -x | ssh root@debian.local -- tic -x -
并且终端会提示 The tic command on the server may give the warning "<stdin>", line 2, col 31, terminal 'xterm-ghostty': older tic versions may treat the description field as an alias which can be safely ignored.
下一次进入中终端后就可以解决以上问题. 问题原因可以参考: https://github.com/ghostty-org/ghostty/discussions/4268 , https://ghostty.org/docs/help/terminfo