14

So, I decided to give Alacritty a try, and in their default configuration there is the following comment:

#env:
  # TERM variable
  #
  # This value is used to set the `$TERM` environment variable for
  # each instance of Alacritty. If it is not present, alacritty will
  # check the local terminfo database and use `alacritty` if it is
  # available, otherwise `xterm-256color` is used.
  #TERM: alacritty

What I don't get it is: why would I want to set TERM to xterm-256color when using alacritty? Isn't xterm the default terminal emulator for Linux? In the old OSX days I remember using iTerm2 but the variable TERM was set to xterm-256color if I'm not mistake - back then I never thought the reason why that was the case.

mamonas
  • 181
  • 1
  • 2
  • 7
  • 4
    Actually you shouldn't want to use TERM=xterm-256color with alacritty, because alacritty doesn't support the full terminal description, just parts. – Thomas Dickey Jul 09 '20 at 01:17
  • Bringing my comment below up to the top level. Simply put you want TERM=xterm-256color if you are accessing other systems that don't have alacritty terminfo installed (ie. most systems at this point). Setting TERM=alacritty gets you nothing except status-line support which is a legacy setting from terminals that had a separate status line (and tmux and other TUIs with status lines don't use this). – John Eikenberry Jul 09 '21 at 18:30
  • Don't use xterm-256color. Read this superb answer by Neovim expert. – Niing Nov 24 '21 at 16:21

5 Answers5

6

As a Neovim master, I'm here to save thousands of folks who want to use beautiful true color Alacritty with tmux. I've confirmed that this will work on both macOS and ubuntu VM. Follow me!

In alacritty / INSTALL.md from the official Alacritty GitHub.

If you build alacritty yourself

great! Make sure you're in the alacritty/ folder you cloned and run one command:

sudo tic -xe alacritty,alacritty-direct extra/alacritty.info

then go to your rc file (In my case .zshrc) and add:

export TERM=alacritty

If you install alacritty via Homebrew

Great! I'm on the same side as you! Instead of cloning the entire alacritty/ folder, run this anywhere in your computer:

mkdir alacritty

and then download the alacritty/extra/ folder and copy it into the alacritty/ you just create, then (the following steps the same as bulid step above) run:

sudo tic -xe alacritty,alacritty-direct extra/alacritty.info

then go to your rc file (In my case .zshrc) and add:

export TERM=alacritty

Enjoy!

Niing
  • 813
5

You wouldn't.

The correct terminal type for Alacritty is, as the comment even says, alacritty.

What the comment is telling you is that, if you don't explicitly specify the terminal type, Alacritty goes and looks to see whether your terminfo database has an alacritty entry, sets the terminal type to alacritty if so, and uses a bad fallback if it doesn't have such an entry.

xterm-anything is the wrong terminal type to set unless your terminal emulator is actually the XTerm program.

The right thing to do is to put an alacritty entry in your terminfo database if it is missing. terminfo both allows entries to be exported from and imported to machines, and allows people to locally add terminal capabilities records in their home directories.

It shouldn't be missing. Dickey terminfo has had an alacritty entry since 2018, and the Alacritty developers themselves have supplied a terminfo entry that one can add to one's database since 2017.

Further reading

JdeBP
  • 68,745
  • 7
    In practice, many servers may not have the alacritty term info installed. Using export TERM=xterm-256color is likely to fix problems like htop not running due the missing alacritty term info and you are unlikely to notice any problems. I'm unaware of any reference that explains that works with TERM=alacritty vs TERM=xterm-256color. In my experience xterm-256color is sufficiently good. – Mark Stosberg Nov 09 '20 at 14:57
  • 1
    As Mark said above, the terminfo check doesn't take into account that you may SSH to a server with different terminfo (eg. Debian minimal install for a server) that doesn't have an alacritty entry. – walnut_salami Apr 10 '21 at 08:36
  • as i commented above, note LESS='-j3 -p~/.ssh/environment' man ssh to set an environment specific to machine when using ssh – Jack Wasey Jun 12 '21 at 09:06
  • This answer doesn't actually answer the question "why?". Comments and other answers express some good reasons why you might set it to xterm-256color, but the answer telling you not to doesn't give any reason why other than it tells you not to. – John Eikenberry Jul 05 '21 at 01:27
  • I reviewed the differences between alacritty terminfo and xterm-256color and the only real difference is that alacritty's supports a status line. Terminfo docs say ncurses doesn't use these terminfo entries yet and all other mentions are legacy uses. So I'm thinking this answer is just wrong and it is generally better to use xterm-256color until alacritty (and it's terminfo) is more wide spread. – John Eikenberry Jul 09 '21 at 18:27
  • 2
    There's another difference: xterm supports left/right margins, alacritty does not. Some programs (such as tmux) will malfunction because of the suggested substitution. – Thomas Dickey Oct 10 '21 at 01:52
  • I don't have dircolors as command? – Niing Nov 06 '21 at 12:24
2

One reason is to make sure that the output of ls is colorized: dircolors is used to set the LS_COLORS environment variable. dircolors reads TERM to determine whether the terminal supports colors. If you run

dircolors --print-database | grep '^TERM'

you get a list of all color terminals that dircolors knows. alacritty is not on the list. I assume that more programs with such behavior exist or else Alacritty’s default value for TERM could be alacritty-color (since *color* is on dircolors’ list).

Because of a bug in Mono, some games do not launch. The official workaround is to use TERM=xterm.

Devon
  • 847
  • Hmm, wouldn't toe -a be a better choice to see what the curses library knows about? ... what dircolors -p gives you seems to be more a list of patterns it matches against ... – 0xC0000022L Jul 08 '20 at 21:02
  • dircolors (and GNU ls) ignore the terminal database. According to those programs, vt100's did ANSI color. The mono bug report doesn't actually say what this answer implies. What it actually says is that mono was unable to read the newer terminfo binary format, and as a workaround, suggested using one of the terminal descriptions that didn't use the newer format. It's only been 3 years, without a fix in mono (be patient). – Thomas Dickey Oct 09 '21 at 23:25
2

Voice to the contrary (and why I am contemplating switch myself):

When connecting to a remote system from an Alacritty terminal, for instance over SSH, it can occur that the system does not have an entry for Alacritty in its terminfo database (/usr/share/terminfo/a/alacritty*). Therefore, all interactive terminal functionality does not work. This can be fixed by explicitly exporting the value of the TERM variable set to xterm-256color instead of the default alacritty.

mcepl
  • 125
2

The current top rated answer states:

The right thing to do is to put an alacritty entry in your terminfo database if it is missing. terminfo both allows entries to be exported from and imported to machines, and allows people to locally add terminal capabilities records in their home directories.

Here is a oneliner that does the export locally and the import remotely via ssh:

infocmp | ssh $user@$host 'tic -x -'

See man infocmp and man tic for more info on the export and import commands respectively.

Bonus Unix/Linux tip (Don't downvote the messenger ;-)

The use of - as a filename is a common (though not universal) convention for telling a command that expects a file argument to instead read from /dev/stdin. Many commands (including tic) support it without stating so in the man page. You can use the explicit device path in most cases.

infocmp | ssh $user@$host 'tic -x /dev/stdin'