2

I would like to get italic fonts working correctly inside tmux, as currently they only work outside of it. Research suggests this might be accomplished by setting the default_terminal setting so I have the below in my tmux.conf. This doesn't seem to accomplish anything however. My understanding is this should set $TERM, but this is still set to screen. Even if I run tmux prefaced with TERM=tmux-256color, it immediately sets it back to screen. What's going on here?

set -g default-terminal "tmux-256color" 
1

2 Answers 2

2

I suspect that terminal database for screen and its derivatives like screen-256color simply do not declare any support for italic text, this may be evident with e.g.:

tput sitm | xxd 

...which prints nothing, meaning there isn't any escape sequence that will instruct your terminal (when it declares itself to be screen-like) to switch to italic mode when asked.

The database for the tmux TERM identifier, however, on a RHEL 9 host at least, does support italic mode, because the above command line will print:

00000000: 1b5b 336d .[3m 

Subsequently, the support can be tested with:

echo $(tput sitm) test $(tput sgr0) 

, where the text "test" should be printed in italic.

sitm is the terminal-invariant option to tput to generate the necessary escape sequence for switching to italic, while sgr0 resets color and mode of the text back to default (the "SGR" abbreviation stands for Select Graphic Rendition).

Do not set TERM in your shell or anywhere except where the terminal emulator can be known, unless you know what you're doing and are sure your system is otherwise broken somehow -- the TERM specifies your terminal emulator and the shell cannot possibly know that (well, it could only ever know through querying the TERM in the first place, right?)

I don't know how many people, for how many years, must have warned against setting TERM in all the wrong places (which are, really, all of the places), but it's still being proliferated on the Internet, as can be plainly seen. Just avoid setting TERM for as long and longer than you possibly can, chances are it will break something, unless you are absolulutely, positively, cross-your-heart sure you only ever use one terminal emulator. Which you don't. Besides, like I said, if you need to set TERM, something is broken somewhere in your system, which would be odd for a sufficiently modern operating system, unless you broke something there in the first place.

In a similar vein, do not set tmux's default-terminal option to anything else but screen or tmux or their derivatives ({screen,tmux}{.,-}*), there is a very good reason the manual pages of tmux warn you against it:

For tmux to work correctly, this must be set to ‘screen’, ‘tmux’ or a derivative of them.

Tmux is not "Xterm", so if you think you've gotten away with set-option default-terminal xterm-256color or perhaps some form of set-option terminal-overrides ..., you most likely are waiting for a slew of issues to crop up, which may force you to re-think the "hack". Depending on what you're doing in the terminal, correct rendering will be subtly broken without requiring even more hacks to "correct" the first hack and so on.

I suspect the reason tmux uses screen as TERM by default, is because at the time screen was prevalent and the terminfo database supported it (and not tmux which was a novelty). Today I suspect many distributions support tmux explicitly, so set-option default-terminal tmux (or a derivative like tmux-256color, depending on installed terminfo database) may be exactly what you need, no more but no less.

0

I may be late, but this may help whoever lands here. I had this issue and also some others around setting truecolors, I'm also still learning this stuff so I am probably going to mix multiple fixes, but below is some info/steps I did to set it to tmux-256color and also have truecolor working correctly.

  1. It's not advisable to change the TERM var from your alacritty config. You should do it on your .tmux.conf file.

  2. An important detail about tmux that I figured after some hours is that it seems some configs won't reload unless you kill all your sessions. So, when trying new stuff or fixes, work under a session and kill it every time you want to reload to guarantee the changes take effect i.e. a (tmux new / :kill-session) workflow.

  3. Before setting my default-terminal to tmux-256color I did 2 things. (this is where I am currently discovering if this part was really relevant or just point 2 where we have to kill sessions)

  • set an alias tmux="tmux -2"
  • get terminfo profiles for tmux-256color: sudo apt install ncurses-term
  1. I have tmux 3.2 and I am setting my terminal and features like so:
set -g default-terminal "tmux-256color" set -as terminal-features ",xterm-256color:RGB" 

Anyway point 3 and 4 may not be too relevant for your issue, so point 2 may be the reason. But I'll leave 3 and 4 for anyone who may face this next challenge.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.