Ncurses: Difference between revisions
| Line 31: | Line 31: | ||
===Color attributes=== | ===Color attributes=== | ||
Using color pairs beyond 256 requires a 16-bit attribute. By default, only 8 bits are provided (see <tt>A_COLOR</tt>). Thus for instance <tt>wattron(w, COLOR_PAIR(260))</tt> is equivalent to <tt>wattron(w, COLOR_PAIR(4))</tt>. In order to use pairs above 256, drop <tt>COLOR_PAIR</tt>, and always refer to the pair via pointer using the <tt>void* opts</tt> parameter to functions like <tt>wattron</tt>. What, there is not such parameter? Ahhh, of course; you need to use <tt>wattr_on</tt>. Note the underscore, and hate life. | Using color pairs beyond 256 requires a 16-bit attribute. By default, only 8 bits are provided (see <tt>A_COLOR</tt>). Thus for instance <tt>wattron(w, COLOR_PAIR(260))</tt> is equivalent to <tt>wattron(w, COLOR_PAIR(4))</tt>. In order to use pairs above 256, drop <tt>COLOR_PAIR</tt>, and always refer to the pair via pointer using the <tt>void* opts</tt> parameter to functions like <tt>wattron</tt>. What, there is not such parameter? Ahhh, of course; you need to use <tt>wattr_on</tt>. Note the underscore, and hate life. | ||
===True Color=== | |||
Test for terminal support (courtesy [https://gist.github.com/XVilka/8346728 XVilka]: | |||
<pre>awk 'BEGIN{ | |||
s="/\\/\\/\\/\\/\\"; s=s s s s s s s s; | |||
for (colnum = 0; colnum<77; colnum++) { | |||
r = 255-(colnum*255/76); | |||
g = (colnum*510/76); | |||
b = (colnum*255/76); | |||
if (g>255) g = 510-g; | |||
printf "\033[48;2;%d;%d;%dm", r,g,b; | |||
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b; | |||
printf "%s\033[0m", substr(s,colnum+1,1); | |||
} | |||
printf "\n"; | |||
}'</pre> | |||
==[[Unicode]]== | ==[[Unicode]]== | ||