Can I define my own character forms in ncurses?

The name reads almost everything. Once, when I was less than 13 years old, my older brother did what struck me at BorlandPascal. He determined the type of table [8] [8] with values ​​of 1 and 0, which means the foreground and background, respectively. Having several such tables, he could somehow override the default ASCII characters so that they look in these tables. I have no idea how this was done, but it worked.

My question is: can I do this in ncurses, and if I can, how can I do this?

+4
source share
2 answers

The short answer is no. What ncurses does is generate ANSI cancel codes , which are interpreted by the terminal. There are no codes for changing the font. (Althou there were extensions that are not supported, commonly used terminals support them, as well as ncurses.) And there is no general way to communicate with the terminal through some kind of side channel to change the font. But in some specific situations, there may be ways.

If you have direct access to the Linux console, for example, you could do all kinds of things, like in Borland Pascal. But it is likely to be messier and less impressive.

+1
source

As you can see from the selected answer, NCurses cannot display custom glyphs. ncurses only manages the state of the terminal screen using escape codes (Clear and rewrite strings to achieve interactivity).

However, it should be noted that it is very convenient to use custom glyphs in the terminal through custom fonts .

This is what Powerline does (a popular terminal terminal status bar for vim, tmux and friends): https://github.com/powerline/fonts

Replacing fonts, you can enter glyphs into an existing font used by the terminal, which you can then receive and process through ncurses like any other character.

Of course, this is not an ideal solution, but with some automatic font corrections and rigorous testing, it allows you to create an application that uses custom glyphs - when you really click on more expressive user interface tools than ncurses can offer.

Further reading: https://apw-bash-settings.readthedocs.io/en/latest/fontpatching.html

+1
source

Source: https://habr.com/ru/post/1485514/


All Articles