Check out my first novel, midnight's simulacra!
Ncurses: Difference between revisions
(→Colors) |
No edit summary |
||
Line 1: | Line 1: | ||
Quality character cell graphics since [https://invisible-island.net/ncurses/ncurses.faq.html 1982]. | |||
==Escape== | ==Escape== | ||
You can get Escape with no delay by using <tt>notimeout(3ncurses)</tt>, but this eliminates use of the function and arrow keys on terminals where those sequences are composed with Escape. You probably don't want that. You can use the ESCDELAY environment variable (see <tt>ncurses(3ncurses)</tt>) to change this (ncurses also provides a global of the same name). [[Vim]] uses a 25ms default. The ncurses default appears to be 1s (1000ms), which makes one's application feel kinda seasick when running on any reasonable connection (not to mention locally). This seems difficult to manipulate programaticly, though. :/ | You can get Escape with no delay by using <tt>notimeout(3ncurses)</tt>, but this eliminates use of the function and arrow keys on terminals where those sequences are composed with Escape. You probably don't want that. You can use the ESCDELAY environment variable (see <tt>ncurses(3ncurses)</tt>) to change this (ncurses also provides a global of the same name). [[Vim]] uses a 25ms default. The ncurses default appears to be 1s (1000ms), which makes one's application feel kinda seasick when running on any reasonable connection (not to mention locally). This seems difficult to manipulate programaticly, though. :/ |
Revision as of 21:51, 10 November 2019
Quality character cell graphics since 1982.
Escape
You can get Escape with no delay by using notimeout(3ncurses), but this eliminates use of the function and arrow keys on terminals where those sequences are composed with Escape. You probably don't want that. You can use the ESCDELAY environment variable (see ncurses(3ncurses)) to change this (ncurses also provides a global of the same name). Vim uses a 25ms default. The ncurses default appears to be 1s (1000ms), which makes one's application feel kinda seasick when running on any reasonable connection (not to mention locally). This seems difficult to manipulate programaticly, though. :/
Colors
- When modifying the palette via init_color(), this only affects the normal form of the color. Using A_BOLD with the color, for instance, will not reflect palette changes.
- Modifying the palette requires a terminal that supports it, like "linux" or "xterm-256color"
- The latter can be had from the ncurses-term package on Debian.
- ncurses will need have been compiled with --enable-ext-colors
Terminal emulator | Default terminfo | 256-color terminfo | Debian package |
---|---|---|---|
xterm | xterm | xterm-256color | ncurses-base |
Gnome-Terminal | gnome | gnome-256color | ncurses-term |
Konsole | konsole | konsole-256color | ncurses-term |
Color attributes
Using color pairs beyond 256 requires a 16-bit attribute. By default, only 8 bits are provided (see A_COLOR). Thus for instance wattron(w, COLOR_PAIR(260)) is equivalent to wattron(w, COLOR_PAIR(4)). In order to use pairs above 256, drop COLOR_PAIR, and always refer to the pair via pointer using the void* opts parameter to functions like wattron. What, there is not such parameter? Ahhh, of course; you need to use wattr_on. Note the underscore, and hate life.
True Color
Test for terminal support (courtesy XVilka:
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"; }'
Unicode
- You need use ncursesw, which ought have been built with --enable-widec
- _XOPEN_SOURCE_EXTENDED must be #defined prior to including any ncurses headers (use -D_XOPEN_SOURCE_EXTENDED with gcc)
- setlocale() needs have been called prior to calling any ncurses functions
- ncurses assumes that the locale does not change once started