Linux xterm-color 和 xterm-256color 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10003136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:36:19  来源:igfitidea点击:

What is the difference between xterm-color & xterm-256color?

linuxmacosterminalncursesxterm

提问by user12345

I've come across both xterm-colorand xterm-256coloras options when trying to set up my terminal program to use color - i.e. you can set your TERMenvironment variable to either one.

在尝试设置我的终端程序以使用颜色时,我遇到了两者xterm-colorxterm-256color作为选项 - 即您可以将TERM环境变量设置为任一。

I was wondering if anyone can describe the difference between the two?

我想知道是否有人可以描述两者之间的区别?

I've searched for documentation on my Ubuntu server as well as my mac but haven't found any. I've only been able to find various binary files in /usr/share/terminfo.

我在我的 Ubuntu 服务器和 Mac 上搜索过文档,但没有找到。我只能在/usr/share/terminfo.

采纳答案by Chris Page

xterm-256colordescribes Xterm with support for 256 colors enabled. xterm-colordescribes an older branch of Xterm that supports eight colors. xterm-coloris not recommended, since it describes a variant of Xterm that's less functional and that you're not likely to be using. Usually you'll want to use xterm, xterm-16coloror xterm-256color.

xterm-256color描述启用了 256 色支持的 Xterm。xterm-color描述了支持八种颜色的 Xterm 的旧分支。xterm-color不推荐使用,因为它描述了功能较弱且您不太可能使用的 Xterm 变体。通常你会想要使用xterm,xterm-16colorxterm-256color

In particular, xterm-256coloris the default for Terminal starting with Mac OS X 10.7 Lion, with the next-best recommended values being xterm-16coloror xterm(which only describes support for eight ANSI colors). Prior to 10.7, xterm-colorwas the default because Terminal didn't support some critical features described by the recommended Xterm terminfo values, e.g., Background Color Erase (BCE), modern codes for switching main/alternate screens, 256 colors.

特别是,xterm-256color从 Mac OS X 10.7 Lion 开始的终端的默认值,次佳推荐值是xterm-16colorxterm(仅描述对八种 ANSI 颜色的支持)。在 10.7 之前,这xterm-color是默认设置,因为终端不支持推荐的 Xterm terminfo 值描述的一些关键功能,例如,背景颜色擦除 (BCE)、用于切换主/备用屏幕的现代代码、256 色。

Sometimes people explicitly set TERMto xterm-color(as opposed to the recommended Xterm values) to disable functionality or work around incompatibilities between the available terminfo values on a particular computer and the terminal emulator being used.

有时人们明确设置TERMxterm-color(与推荐的 Xterm 值相反)以禁用功能或解决特定计算机上可用的 terminfo 值与正在使用的终端仿真器之间的不兼容问题。

Note that technically Terminal should have its own up-to-date terminfo values that describe exactly which features it supports, instead of using the values for Xterm, but:

请注意,从技术上讲,终端应该有自己的最新 terminfo 值,准确描述它支持哪些功能,而不是使用 Xterm 的值,但是:

  1. There isn't one that's up to date currently. nstermrepresents Terminal's ancestor from NeXTSTEP. Someone apparently has updated nstermrecently (sometime in the past couple of years), but I don't know whether that has made its way into the ncurses distribution, and it may not be completely up to date with Terminal in 10.7.
  2. A number of programs and shell customization scripts explicitly check whether $TERMstarts with (or is equal to) xterm. So some users would still need to know about using the recommended Xterm values with Terminal for compatibility with those.
  1. 目前没有一个是最新的。nsterm代表来自 NeXTSTEP 的 Terminal 的祖先。显然nsterm最近有人更新了(过去几年的某个时间),但我不知道这是否已进入 ncurses 发行版,并且它可能不完全与 10.7 中的 Terminal 保持同步。
  2. 许多程序和外壳自定义脚本明确检查是否$TERM以(或等于)开头xterm。因此,一些用户仍需要了解将推荐的 Xterm 值与 Terminal 一起使用以与这些值兼容。

If you're not familiar with the terminfo system, take a look at the x-man-page://5/terminfo man page. Also, you can use the infocmpcommand to view the current terminfo settings or compare two different ones, e.g., infocmp xterm-color xterm-256colorwill show you all the differences between those two.

如果您不熟悉 terminfo 系统,请查看 x-man-page://5/terminfo 手册页。此外,您可以使用该infocmp命令查看当前的 terminfo 设置或比较两个不同的设置,例如,infocmp xterm-color xterm-256color将向您显示这两者之间的所有差异。

回答by user1277476

It appears that xterm-256coloris Terminal.app on OS/X. The differences are not tiny - I infocmp'd xterm-colorand xterm-256coloron an Ubuntu box and normalized them a bit, and got quite a few differences. I might even say xterm-256colorisn't really xterm anymore.

似乎xterm-256color是 OS/X 上的 Terminal.app。差异并不小 - 我在 Ubuntu机器上对它们进行了infocmp'd 处理xterm-color并对xterm-256color它们进行了一些规范化,并得到了很多差异。我什至可以说xterm-256color不再是真正的 xterm。

Normally when you use a specific terminal emulator, you need to "just know" which terminfo entry works best with it. They're a matching pair, though sometimes you can, EG, use a vt100 terminfo entry on a vt220 terminal.

通常,当您使用特定的终端仿真器时,您需要“只知道”哪个 terminfo 条目最适合它。它们是一对匹配,但有时您可以,例如,在 vt220 终端上使用 vt100 terminfo 条目。

On the plus side, almost everything is vt100-compatible today.

从好的方面来说,今天几乎所有东西都与 vt100 兼容。

回答by Thomas Dickey

According to the ncurses FAQ, xterm-coloris long obsolete:

根据ncurses FAQxterm-color已经过时了:

Originally, xterm-color corresponded to the color_xterm from the mid-1990s. That was superseded by XFree86 xterm in 1996.

最初,xterm-color 对应于 1990 年代中期的 color_xterm。这在 1996 年被 XFree86 xterm 取代。

and the terminal database gives details. It was originally intended as a generic terminal description, but from the outset that never was successful because it did not match XFree86 xterm, in particular the color behavior (i.e., the back color erasefeature). No one uses nxtermnow.

终端数据库提供详细信息。它最初旨在作为通用终端描述,但从一开始就从未成功,因为它与XFree86 xterm不匹配,特别是颜色行为(即,背景颜色擦除功能)。现在没有人使用nxterm

The xterm-256colorterminal description is built up from the (XFree86) xterm terminal description by modifying the color behavior (adding more colors, but notthe background color erase feature. Use infocmpto see the difference:

所述的xterm-256color终端描述从(XFree86的)的xterm终端描述通过修改颜色行为(添加更多的颜色建立起来的,但不是背景颜色擦除特性的应用。infocmp看出差别:

$ infocmp xterm-color xterm-256color |wc -l
122
$ infocmp xterm xterm-256color |wc -l
14
$ infocmp xterm xterm-256color
comparing xterm to xterm-256color.
    comparing booleans.
        ccc: F:T.
    comparing numbers.
        colors: 8, 256.
        pairs: 64, 32767.
    comparing strings.
        initc: NULL, '\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\'.
        oc: NULL, '\E]104##代码##7'.
        rs1: '\Ec', '\Ec\E]104##代码##7'.
        setab: '\E[4%p1%dm', '\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m'.
        setaf: '\E[3%p1%dm', '\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m'.
        setb: '\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m', NULL.
        setf: '\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m', NULL.

Because xterm-color was obsolete, it was largely ignored until some (anonymous, of course) developer at Apple decided to reuse it for Terminal.app (in 10.5 Leopard), although it was a poor fit. The nsterm-16colordescription in ncurses was contributed by someone (apparently outside Apple), to match the 10.5 behavior. Although xterm-color uses 8colors, nsterm-16color as one might guess uses 16. Perhaps that contributed to users' confusion. In any case, the choice of terminal description for Terminal.app had no effect on Terminal.app other than to set the TERMenvironment variable, which many applications use to decide how to use the terminal.

因为 xterm-color 已经过时,它在很大程度上被忽略了,直到 Apple 的一些(当然是匿名的)开发人员决定将它重用于 Terminal.app(在 10.5 Leopard 中),尽管它不太合适。ncurses 中的nsterm-16color描述是由某人(显然在 Apple 之外)提供的,以匹配 10.5 行为。尽管 xterm-color 使用8种颜色,但 nsterm-16color 可能会使用16种颜色。也许这导致了用户的困惑。在任何情况下,Terminal.app 的终端描述的选择对 Terminal.app 没有影响,只是设置TERM环境变量,许多应用程序使用它来决定如何使用终端。

Interesting enough, although much of the MacOS userland is from the BSDs, its ncurses configuration is not. MacOS has tic/infocmp utilities, unlike the BSDs (though Apple has not updated it for more than ten years: ncurses 5.7 was released in 2008). In later releases of MacOS, Terminal.app's developers changed the menu to provide "xterm-256color" rather than "xterm-color". That did not improve the user experience because the terminal behavior using the corresponding terminal descriptions was still different. The ncurses FAQmentions that:

有趣的是,虽然大部分 MacOS 用户空间来自 BSD,但它的 ncurses 配置不是。与 BSD 不同,MacOS 具有 tic/infocmp 实用程序(尽管 Apple 已经十多年没有更新它了:ncurses 5.7 于2008年发布)。在 MacOS 的后续版本中,Terminal.app 的开发人员更改了菜单以提供“xterm-256color”而不是“xterm-color”。这并没有改善用户体验,因为使用相应终端描述的终端行为仍然不同。该ncurses的常见问题提到:

Additionally, Mac OS X 10.7 is reported to use xterm-256color as a default $TERM value. This differs from xterm-color in several ways, in particular, the support for bce. It also differs from the recommended nsterm-256color (infocmp reports 111 differences).

此外,据报道 Mac OS X 10.7 使用 xterm-256color 作为默认的 $TERM 值。这在几个方面与 xterm-color 不同,特别是对 bce 的支持。它也与推荐的 nsterm-256color 不同(infocmp 报告了 111 个差异)。