curs_add_wch.3x - Man Page

add a curses complex character to a window, possibly advancing the cursor

Synopsis

#include <curses.h>

int add_wch(const cchar_t *wch);
int wadd_wch(WINDOW *win, const cchar_t *wch);
int mvadd_wch(int y, int x, const cchar_t *wch);
int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch);

int echo_wchar(const cchar_t *wch);
int wecho_wchar(WINDOW *win, const cchar_t *wch);

Description

wadd_wch

wadd_wch writes the complex character wch to the window win, then may advance the cursor position, analogously to the standard C library's putwchar(3). ncurses(3X) describes the variants of this function.

Much behavior depends on whether the wide characters in wch are spacing or non-spacing; see subsection “Complex Characters” below.

  • If wch contains a spacing character, then any character at the cursor is first removed. The complex character wch, with its attributes and color pair identifier, becomes the base of the active complex character.
  • If wch contains only non-spacing characters, they are combined with the active complex character. curses ignores its attributes and color pair identifier, and does not advance the cursor.

Further non-spacing characters added with wadd_wch are not written at the new cursor position but combine with the active complex character until another spacing character is written to the window or the cursor is moved.

If advancement occurs at the right margin,

  • the cursor automatically wraps to the beginning of the next line, then,
  • if it was at the bottom of the scrolling region, and if scrollok(3X) is enabled for win, the scrolling region scrolls up one line.

If wch is a backspace, carriage return, line feed, or tab, the cursor moves appropriately within the window.

  • Backspace moves the cursor one character left; at the left margin of a window, it does nothing.
  • Carriage return moves the cursor to the left margin on the current line of the window.
  • Line feed does a clrtoeol(3X), then advances as if from the right margin.
  • Tab advances the cursor to the next tab stop (possibly on the next line); these are placed at every eighth column by default. Alter the tab interval with the Tabsize extension; see curs_variables(3X).

If wch is any other nonprintable character, it is drawn in printable form using the same convention as wunctrl(3X). Calling win_wch(3X) on the location of a nonprintable character does not return the character itself, but its wunctrl(3X) representation.

A cchar_t can be copied from place to place using win_wch(3X) and wadd_wch.

wecho_wchar

echo_wchar and wecho_wchar are equivalent to calling (w)add_wch followed by (w)refresh. curses interprets these functions as a hint that only a single (complex) character is being output; for non-control characters, a considerable performance gain may be enjoyed by employing them.

Forms-Drawing Characters

curses defines macros starting with WACS_ that can be used with wadd_wch to write line-drawing and other special characters to the screen. ncurses terms these forms-drawing characters. The ACS default listed below is used if the acs_chars (acsc) terminfo capability does not define a terminal-specific replacement for it, or if the terminal and locale configuration requires Unicode to access these characters but the library is unable to use Unicode. The “acsc char” column corresponds to how the characters are specified in the acs_chars (acsc) string capability, and the characters in it may appear on the screen if the terminal type's database entry incorrectly advertises ACS support. The name “ACS” originates in the Alternate Character Set feature of the DEC VT100 terminal.

UnicodeACSacsc
SymbolDefaultDefaultcharGlyph Name
WACS_BLOCK0x25ae#0solid square block
WACS_BOARD0x2592#hboard of squares
WACS_BTEE0x2534+vbottom tee
WACS_BULLET0x00b7o~bullet
WACS_CKBOARD0x2592:achecker board (stipple)
WACS_DARROW0x2193v.arrow pointing down
WACS_DEGREE0x00b0'fdegree symbol
WACS_DIAMOND0x25c6+`diamond
WACS_GEQUAL0x2265>>greater-than-or-equal-to
WACS_HLINE0x2500-qhorizontal line
WACS_LANTERN0x2603#ilantern symbol
WACS_LARROW0x2190<,arrow pointing left
WACS_LEQUAL0x2264<yless-than-or-equal-to
WACS_LLCORNER0x2514+mlower left-hand corner
WACS_LRCORNER0x2518+jlower right-hand corner
WACS_LTEE0x2524+tleft tee
WACS_NEQUAL0x2260!|not-equal
WACS_PI0x03c0*{greek pi
WACS_PLMINUS0x00b1#gplus/minus
WACS_PLUS0x253c+nplus
WACS_RARROW0x2192>+arrow pointing right
WACS_RTEE0x251c+uright tee
WACS_S10x23ba-oscan line 1
WACS_S30x23bb-pscan line 3
WACS_S70x23bc-rscan line 7
WACS_S90x23bd_sscan line 9
WACS_STERLING0x00a3f}pound-sterling symbol
WACS_TTEE0x252c+wtop tee
WACS_UARROW0x2191 ^-arrow pointing up
WACS_ULCORNER0x250c+lupper left-hand corner
WACS_URCORNER0x2510+kupper right-hand corner
WACS_VLINE0x2502|xvertical line

The wide-character configuration of ncurses also defines symbols for thick lines (acsc “J” to “V”):

UnicodeASCIIacsc
ACS NameDefaultDefaultCharGlyph Name
WACS_T_BTEE0x253b+Vthick tee pointing up
WACS_T_HLINE0x2501-Qthick horizontal line
WACS_T_LLCORNER0x2517+Mthick lower left corner
WACS_T_LRCORNER0x251b+Jthick lower right corner
WACS_T_LTEE0x252b+Tthick tee pointing right
WACS_T_PLUS0x254b+Nthick large plus
WACS_T_RTEE0x2523+Uthick tee pointing left
WACS_T_TTEE0x2533+Wthick tee pointing down
WACS_T_ULCORNER0x250f+Lthick upper left corner
WACS_T_URCORNER0x2513+Kthick upper right corner
WACS_T_VLINE0x2503|Xthick vertical line

and for double-lines (acsc “A” to “I”):

UnicodeASCIIacsc
ACS NameDefaultDefaultCharGlyph Name
WACS_D_BTEE0x2569+Hdouble tee pointing up
WACS_D_HLINE0x2550-Rdouble horizontal line
WACS_D_LLCORNER0x255a+Ddouble lower left corner
WACS_D_LRCORNER0x255d+Adouble lower right corner
WACS_D_LTEE0x2560+Fdouble tee pointing right
WACS_D_PLUS0x256c+Edouble large plus
WACS_D_RTEE0x2563+Gdouble tee pointing left
WACS_D_TTEE0x2566+Idouble tee pointing down
WACS_D_ULCORNER0x2554+Cdouble upper left corner
WACS_D_URCORNER0x2557+Bdouble upper right corner
WACS_D_VLINE0x2551|Ydouble vertical line

Unicode's descriptions for these characters differs slightly from ncurses, by introducing the term “light” (along with less important details). Here are its descriptions for the normal, thick, and double horizontal lines:

  • U+2500 BOX DRAWINGS LIGHT HORIZONTAL
  • U+2501 BOX DRAWINGS HEAVY HORIZONTAL
  • U+2550 BOX DRAWINGS DOUBLE HORIZONTAL

Return Value

These functions return OK on success and ERR on failure. In ncurses, wadd_wch returns ERR if

Functions prefixed with “mv” first perform cursor movement and fail if the position (y, x) is outside the window boundaries.

Notes

add_wch, mvadd_wch, mvwadd_wch, and echo_wchar may be implemented as macros.

Extensions

Tabsize

The TABSIZE variable is implemented in SVr4 and other versions of curses, but is not specified by X/Open Curses (see curs_variables(3X)).

Portability

These functions are described in X/Open Curses, Issue 4. It specifies no error conditions for them.

The defaults specified for forms-drawing characters apply in the POSIX locale. X/Open Curses makes it clear that the WACS_ symbols should be defined as a pointer to cchar_t data, e.g., in the discussion of border_set. A few implementations are problematic:

X/Open Curses does not specify symbols for thick- or double-lines. SVr4 curses implementations defined their line-drawing symbols in terms of intermediate symbols. This implementation extends those symbols, providing new definitions which are not in the SVr4 implementations.

Not all Unicode-capable terminals provide support for VT100-style alternate character sets (i.e., the acsc capability), with their corresponding line-drawing characters. X/Open Curses did not address the aspect of integrating Unicode with line-drawing characters. Existing implementations of Unix curses (AIX, HP-UX, Solaris) use only the acsc character-mapping to provide this feature. As a result, those implementations can only use single-byte line-drawing characters. ncurses 5.3 (2002) provided a table of Unicode values to solve these problems. NetBSD curses incorporated that table in 2010.

In this implementation, the Unicode values are used instead of the terminal description's acsc mapping as discussed in ncurses(3X) for the environment variable NCURSES_NO_UTF8_ACS. In contrast, for the same cases, the line-drawing characters described in addch(3X) will use only the ASCII default values.

Having Unicode available does not solve all of the problems with line-drawing for curses:

Complex Characters

The complex character type cchar_t can store more than one wide character (wchar_t). X/Open Curses does not mention this possibility, specifying behavior only where wch is a single character, either spacing or non-spacing.

ncurses assumes that wch is constructed using setcchar(3X), and in turn that the result

  • contains at most one spacing character at the beginning of its list of wide characters, and zero or more non-spacing characters, or
  • holds one non-spacing character.

In the latter case, ncurses adds the non-spacing character to the active complex character.

History

These functions were initially specified by X/Open Curses, Issue 4. The System V Interface Definition, Version 4 (1995), specified functions named waddwch and wechowchar (and the usual variants). These were later additions to SVr4.x, not appearing in the first SVr4 (1989). They differed from X/Open's wadd_wch and wecho_wchar in that they each took an argument of type wchar_t instead of cchar_t.

See Also

curs_addch(3X) describes comparable functions of the ncurses library in its non-wide-character configuration.

curses(3X), curs_addwstr(3X), curs_add_wchstr(3X), curs_attr(3X), curs_clear(3X), curs_getcchar(3X), curs_outopts(3X), curs_refresh(3X), curs_variables(3X), putwc(3)

Referenced By

The man pages add_wch.3x(3), echo_wchar.3x(3), mvadd_wch.3x(3), mvwadd_wch.3x(3), wadd_wch.3x(3) and wecho_wchar.3x(3) are aliases of curs_add_wch.3x(3).

2024-06-01 ncurses 6.5 Library calls