Terminfo

Terminfo 用于向软件告知终端的能力。 Ghostty 自带自己的 terminfo 条目来宣传其功能。

Terminfo 是一种古老的数据格式,很多终端 应用仍在使用它来判定终端 的能力。Ghostty 自带自己的 terminfo 条目来对外宣传 其功能。

Ghostty 使用 TERM 值 xterm-ghostty。

Note

为什么要带 xterm 前缀? 不幸的是,许多终端应用会 在 TERM 值中搜索字符串 "xterm" 来推断功能。在私有测试期间,我们 试过纯 ghostty 值,但发现太多应用挂掉,修复整个生态也不现实。 我们最终选择 xterm-ghostty 以保持兼容。

Ghostty 的包内置了 terminfo 条目,并会设置相应的文件系统 布局或环境变量,使其可供系统使用。当你运行 Ghostty 时,只要检测到 terminfo 条目 可用,它就会自动把 TERM 环境变量设为 xterm-ghostty。

Important

Ghostty 的 terminfo 条目已包含在 ncurses 6.5-20241228 及更高版本中。 随着发行版更新 ncurses 包,Ghostty 的 terminfo 条目将默认在系统范围内 可用。这一点还需要时间来传播。

Sudo

如果你使用 sudo,sudo 可能会重置你的环境变量,导致 某些程序运行时看到 missing or unsuitable terminal: xterm-ghostty 或 'xterm-ghostty': unknown terminal type. 的错误。

要解决此问题,你必须配置 sudo 保留 TERMINFO 环境变量,或者你可以使用 shell integration 并指定 sudo 功能,Ghostty 会把 sudo 别名化,自动为你处理。要启用 shell-integration 特定功能,需要在配置中指定 shell-integration-features = sudo。

更多信息请见 shell-integration-features 关于此配置选项的说明。

SSH

如果你通过 SSH 连接到没有 Ghostty terminfo 条目 的机器,你将看到诸如 missing or unsuitable terminal: xterm-ghostty, Error opening terminal: xterm-ghostty. 或 WARNING: terminal is not fully functional 这样的错误消息。

希望将来某天 Ghostty 的 terminfo 条目会被各处预先分发,但在此之前, 有两种方法可以解决这个问题:

方法 1:把 Ghostty 的 terminfo 条目复制到远程机器

  1. 在本地机器上,运行以下单行命令:
    infocmp -x xterm-ghostty | ssh YOUR-SERVER -- tic -x -
    
  2. 在服务器上,确认配置已保存到 /usr/share/terminfo/...。 如果没有,检查 $HOME/.terminfo/... 并把它搬过去。

服务器上的 tic 命令可能会给出 “<stdin>”,第 2 行、第 31 列,终端 'xterm-ghostty':较旧的 tic 版本可能把描述 字段当作别名 的警告,可以安全忽略。

tic 通常会把结果放到系统数据库 /usr/share/terminfo 中。 该位置可通过 TERMINFO 环境变量覆盖。 如果 TERMINFO 未设置,且 tic 无法写入系统位置,则 若 $HOME/.terminfo 存在,它会把结果放到那里。 若发生这种情况,请参阅 man tic 了解详情。

Note

macOS Sonoma 之前的版本无法使用系统自带的 infocmp。 内置的 ncurses 版本过旧,无法产生能被更新版本的 tic 读取的 terminfo 条目,命令会因一堆 Illegal character 消息而失败。你可以用 Homebrew 以 brew install ncurses 安装新版的 ncurses,并把上面的 infocmp 替换为完整路径 /opt/homebrew/opt/ncurses/bin/infocmp 或 /usr/local/opt/ncurses/bin/infocmp 来解决。

方法 2:配置 SSH 以回退到已知的 terminfo 条目

  1. 在本地机器上,添加下列 SSH 配置 (需要 OpenSSH 8.7 或 更新版本):
    # .ssh/config
    Host example.com
      SetEnv TERM=xterm-256color
    

Ghostty 可以把这两种方式都自动化。请见 SSH 了解 ghostty +ssh CLI 动作以及 ssh-env / ssh-terminfo shell integration 功能的详情,包括这些自动化在何时生效的几个 重要限制。

Warning

回退不支持高级终端功能。 由于 xterm-256color 并不包含 Ghostty 的所有能力, 超出 xterm 的终端功能(例如带颜色和样式的下划线)将无法工作。