Check out my first novel, midnight's simulacra!

Ncurses: Difference between revisions

From dankwiki
(add note about ESCDELAY and notimeout)
Line 28: Line 28:
| ncurses-term
| ncurses-term
|}
|}
===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.


==[[Unicode]]==
==[[Unicode]]==

Revision as of 19:39, 9 November 2019

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.

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