Reputation: 1555
I'm writing a console program that needs to output styled text. Right now I'm using fixed ANSI escape codes for foreground and background colours, bold, and underline. For example, I can write \033[35m
to change the foreground colour to purple.
The benefit of writing the codes myself is that I can chain them. I can change the background colour and the foreground colour with one command, which saves precious bytes:
\033[48;5;200;38;5;100m
I'd like to switch to using the terminfo library to make my program work on other types of terminals. However, I can't find a way to update multiple colours at once - I want to set bold and underline and the colours with only one \033
and only one m
.
There are the following commands listed in the standard, but not only do none of these seem to do what I want, I can't actually find what the first and second sets of video attributes actually are:
Is there a way to get what I want using only terminfo
commands? Thanks in advance.
Upvotes: 1
Views: 1742
Reputation: 54475
No - terminfo does not do this:
sgr
, which can set up to 9 video attributes at a time. None of those are color.If you happen to be using ncurses, you could define your own capabilities, using tic -x
, and use your own interpretation for those (see for example ncurses user-definable capabilities in the terminal database). As long as their syntax matches the other terminfo strings, you could then use tparm
to fill in the numbers (a little better than printf
).
Upvotes: 1