Many modern terminal emulators include definitions for box drawing glyphs directly in their own source code, and disregard the versions provided by the font when rendering the display. Is there a general way for a program running in the terminal to detect which glyphs are rendered this way? Specifically, if a program makes use of additional box glyphs that might not be widely supported, what's the best way to check if they're available? Perhaps in terminfo
?
My current use case is a small personal-use project written in Python using ncurses
for the graphical component, so bonus points for something that plays nicely with those, but I'm interested in all solutions.
EDIT: As an example, here's a set of characters provided by kitty
; a comment in the source code indicates they're intended for Powerline integration:
If we try to render the same glyphs in Konsole, though, we get this:
The glyphs displayed by Kitty are defined by the terminal itself, whereas the ones displayed by Konsole are provided by whatever font it's configured to use. Is there a general way for a program running in some arbitrary terminal to detect whether we'll see the something like the former vs. the latter?
Best Answer
You're apparently using characters that are part of the Unicode 1.0.1 Private Use Area. Box-drawing characters in this area are not really standardized, but are used by the
powerline
plugins for thevim
editor, certain shells and other command-line tools.See this question on Superuser.SE for more information.
It appears the developer of KiTTY may be an user of the
powerline
plugins, and has implemented support for their box drawing characters directly into the terminal emulator.As far as I know, there is no standard programmatic way to test for the availability of the
powerline
box-drawing characters: you will need to check the feature list of your terminal emulator, and if it does not include a directpowerline
support, use apowerline
-patched font.The classical way to use line-drawing characters on Unix-style terminals (and terminal emulators) would rely on the terminfo
smacs
/rmacs
andacsc
values.smacs
andrmacs
are control codes to switch into and out of line-drawing mode, andacsc
describes the characters to use. Some software might also use PC default codepage #437's box-drawing characters, but that usually requires a font-switching capability and a font with the correct character set.The modern way would be to use the Unicode standard box-drawing characters, in the range 0x2500-0x257f. Whether those are provided by the font or directly by the terminal emulator should be an implementation detail that has no significance to the application.
Personally, I find
powerline
and similar terminal configuration hacks typical products of a certain development stage of Unix/Linux power users, similar to the larval stage of programmers described in the Jargon File.Once exposed to the realities of working as a group of system administrators maintaining tens or hundreds of systems, desires to intensely customize the terminal environment tend to pass, and be replaced by the ability to seamlessly work with whatever is the standard or factory default setup of the systems you most commonly come across. One might still have certain preferred customizations, but they tend to get pared down to a hard core of important functionality at the expense of fancy looks.
Perhaps this helps you understand why some might not find
powerline
and similar fancy terminal displays very important.