How to programmatically check if the terminal supports italics

consoleterminalterminal-emulator

I'd like to check if the current terminal is able to display italics correctly.

Checking that manually is easy:

echo -e "\e[3mfoo\e[23m"

If the output is foo, the terminal (-emulator) supports italics.
However, I'd like to test in my .zshrc if italics are supported programmatically.

What is the best practice to do that?


If (at all) possible, I'd like my standard Linux console to be able to use italics as well. Problem is, the manual test fails, any ideas how to make italics possible in there?

(this is not part of the original question. It's too vague and meaningless to ask as a stand-along question, though.)

Best Answer

It's not possible to reliably test whether the terminal actually supports italics. You can, by checking the output of tput sitm or tput ritm, test whether the value of $TERM and its corresponding terminal description claims to support it – but the claim and the actual behavior might easily be out of sync in either direction.

I really doubt the Linux console supports or will support italics in the foreseeable future.