5

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.)

2

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.

2

That's several questions:

  • If the Linux console supported italics, that would use a different font or use some technique such as slanting the characters to imitate italics.
  • Assuming it did that, you would need a tool that can dump the image of what's displayed on the console to see this in a program. But the Linux console screen dumps give only text — no images. There is no font information available in the dump (not even bold or color).
  • Both setterm and screendump open the raw vcsa device (though screendump as an alternative uses the the default for the TIOCLINUX ioctl, which has the same content)
  • You could write a suitable tool to dump attributes such as color and whether bold was used, with this obsolete ioctl (i.e., your kernel is very old):

    TIOCLINUX, subcode=8
    Dump screen width and height, cursor position, and all the character-attribute pairs. (Kernels 1.1.67 through 1.1.91 only. With kernel 1.1.92 or later, read from /dev/vcsa* instead.)

  • In short, there's no supported mechanism for finding what's on the screen of the Linux console.

Besides there being no solution to programmatically determining if italics are implemented, aside from using some special feature to increase resolution, there's little reason to expect that Linux console fonts will be drawn in italics. The Terminus font page (which is relevant, since it tries to give the same effect in X as the Linux console fonts) says this in its Frequently Asked Questions section:

Q. Italic version?

A. No. The quality is significantly lower, and preserving the font width requires overlapping characters, which are not handled very well by X11/Xft. Anyway, the modern GUIs support automatic slanting; if you are not satisfied with it, try mkitalic from FreeBSD or bdfslant from Debian.

Q. Scalable version?

A. Long story short, when the average display resolution becomes at least 150 DPI. Prefferably 200.

Further reading:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.