1curs_addch(3X) curs_addch(3X)
2
3
4
6 addch, waddch, mvaddch, mvwaddch, echochar, wechochar - add a character
7 (with attributes) to a curses window, then advance the cursor
8
10 #include <curses.h>
11
12 int addch(const chtype ch);
13 int waddch(WINDOW *win, const chtype ch);
14 int mvaddch(int y, int x, const chtype ch);
15 int mvwaddch(WINDOW *win, int y, int x, const chtype ch);
16 int echochar(const chtype ch);
17 int wechochar(WINDOW *win, const chtype ch);
18
20 Adding characters
21 The addch, waddch, mvaddch and mvwaddch routines put the character ch
22 into the given window at its current window position, which is then
23 advanced. They are analogous to putchar(3) in stdio(3). If the
24 advance is at the right margin:
25
26 · The cursor automatically wraps to the beginning of the next line.
27
28 · At the bottom of the current scrolling region, and if scrollok is
29 enabled, the scrolling region is scrolled up one line.
30
31 · If scrollok is not enabled, writing a character at the lower right
32 margin succeeds. However, an error is returned because it is not
33 possible to wrap to a new line
34
35 If ch is a tab, newline, carriage return or backspace, the cursor is
36 moved appropriately within the window:
37
38 · Backspace moves the cursor one character left; at the left edge of
39 a window it does nothing.
40
41 · Carriage return moves the cursor to the window left margin on the
42 current line.
43
44 · Newline does a clrtoeol, then moves the cursor to the window left
45 margin on the next line, scrolling the window if on the last line.
46
47 · Tabs are considered to be at every eighth column. The tab interval
48 may be altered by setting the TABSIZE variable.
49
50 If ch is any other control character, it is drawn in ^X notation.
51 Calling winch after adding a control character does not return the
52 character itself, but instead returns the ^-representation of the con‐
53 trol character.
54
55 Video attributes can be combined with a character argument passed to
56 addch or related functions by logical-ORing them into the character.
57 (Thus, text, including attributes, can be copied from one place to
58 another using inch(3X) and addch.) See the curs_attr(3X) page for val‐
59 ues of predefined video attribute constants that can be usefully OR'ed
60 into characters.
61
62 Echoing characters
63 The echochar and wechochar routines are equivalent to a call to addch
64 followed by a call to refresh(3X), or a call to waddch followed by a
65 call to wrefresh. The knowledge that only a single character is being
66 output is used and, for non-control characters, a considerable perfor‐
67 mance gain may be seen by using these routines instead of their equiva‐
68 lents.
69
70 Line Graphics
71 The following variables may be used to add line drawing characters to
72 the screen with routines of the addch family. The default character
73 listed below is used if the acsc capability does not define a terminal-
74 specific replacement for it, or if the terminal and locale configura‐
75 tion requires Unicode but the library is unable to use Unicode.
76
77 The names are taken from VT100 nomenclature.
78
79 ACS ACS acsc Glyph
80 Name Default char Name
81 ─────────────────────────────────────────────────────────
82 ACS_BLOCK # 0 solid square block
83 ACS_BOARD # h board of squares
84 ACS_BTEE + v bottom tee
85 ACS_BULLET o ~ bullet
86 ACS_CKBOARD : a checker board (stipple)
87 ACS_DARROW v . arrow pointing down
88 ACS_DEGREE ' f degree symbol
89 ACS_DIAMOND + ` diamond
90 ACS_GEQUAL > > greater-than-or-equal-to
91 ACS_HLINE - q horizontal line
92 ACS_LANTERN # i lantern symbol
93 ACS_LARROW < , arrow pointing left
94 ACS_LEQUAL < y less-than-or-equal-to
95 ACS_LLCORNER + m lower left-hand corner
96 ACS_LRCORNER + j lower right-hand corner
97 ACS_LTEE + t left tee
98 ACS_NEQUAL ! | not-equal
99 ACS_PI * { greek pi
100 ACS_PLMINUS # g plus/minus
101 ACS_PLUS + n plus
102 ACS_RARROW > + arrow pointing right
103 ACS_RTEE + u right tee
104 ACS_S1 - o scan line 1
105 ACS_S3 - p scan line 3
106 ACS_S7 - r scan line 7
107 ACS_S9 _ s scan line 9
108 ACS_STERLING f } pound-sterling symbol
109 ACS_TTEE + w top tee
110 ACS_UARROW ^ - arrow pointing up
111 ACS_ULCORNER + l upper left-hand corner
112 ACS_URCORNER + k upper right-hand corner
113 ACS_VLINE | x vertical line
114
116 All routines return the integer ERR upon failure and OK on success (the
117 SVr4 manuals specify only “an integer value other than ERR”) upon suc‐
118 cessful completion, unless otherwise noted in the preceding routine
119 descriptions.
120
121 Functions with a “mv” prefix first perform a cursor movement using
122 wmove, and return an error if the position is outside the window, or if
123 the window pointer is null.
124
126 Note that addch, mvaddch, mvwaddch, and echochar may be macros.
127
129 All these functions are described in the XSI Curses standard, Issue 4.
130 The defaults specified for forms-drawing characters apply in the POSIX
131 locale.
132
133 ACS Symbols
134 X/Open Curses states that the ACS_ definitions are char constants. For
135 the wide-character implementation (see curs_add_wch), there are analo‐
136 gous WACS_ definitions which are cchar_t constants. Some implementa‐
137 tions are problematic:
138
139 · Some implementations define the ACS symbols to a constant (such as
140 Solaris), while others define those to entries in an array.
141
142 This implementation uses an array acs_map, as done in SVr4 curses.
143 NetBSD also uses an array, actually named _acs_char, with a #define
144 for compatibility.
145
146 · HPUX curses equates some of the ACS_ symbols to the analogous WACS_
147 symbols as if the ACS_ symbols were wide characters. The misde‐
148 fined symbols are the arrows and other symbols which are not used
149 for line-drawing.
150
151 · X/Open Curses (issues 2 through 7) has a typographical error for
152 the ACS_LANTERN symbol, equating its “VT100+ Character” to I (capi‐
153 tal I), while the header files for SVr4 curses and the various
154 implementations use i (lowercase).
155
156 None of the terminal descriptions on Unix platforms use uppercase-
157 I, except for Solaris (i.e., screen's terminal description, appar‐
158 ently based on the X/Open documentation around 1995). On the other
159 hand, the terminal description gs6300 (AT&T PC6300 with EMOTS Ter‐
160 minal Emulator) uses lowercase-i.
161
162 Some ACS symbols (ACS_S3, ACS_S7, ACS_LEQUAL, ACS_GEQUAL, ACS_PI,
163 ACS_NEQUAL, ACS_STERLING) were not documented in any publicly released
164 System V. However, many publicly available terminfos include acsc
165 strings in which their key characters (pryz{|}) are embedded, and a
166 second-hand list of their character descriptions has come to light.
167 The ACS-prefixed names for them were invented for ncurses(3X).
168
169 The displayed values for the ACS_ and WACS_ constants depend on
170
171 · the library configuration, i.e., ncurses versus ncursesw, where the
172 latter is capable of displaying Unicode while the former is not,
173 and
174
175 · whether the locale uses UTF-8 encoding.
176
177 In certain cases, the terminal is unable to display line-drawing char‐
178 acters except by using UTF-8 (see the discussion of NCURSES_NO_UTF8_ACS
179 in ncurses(3X)).
180
181 Character Set
182 X/Open Curses assumes that the parameter passed to waddch contains a
183 single character. As discussed in curs_attr(3X), that character may
184 have been more than eight bits in an SVr3 or SVr4 implementation, but
185 in the X/Open Curses model, the details are not given. The important
186 distinction between SVr4 curses and X/Open Curses is that the non-char‐
187 acter information (attributes and color) was separated from the charac‐
188 ter information which is packed in a chtype to pass to waddch.
189
190 In this implementation, chtype holds an eight-bit character. But
191 ncurses allows multibyte characters to be passed in a succession of
192 calls to waddch. The other implementations do not do this; a call to
193 waddch passes exactly one character which may be rendered as one or
194 more cells on the screen depending on whether it is printable.
195
196 Depending on the locale settings, ncurses will inspect the byte passed
197 in each call to waddch, and check if the latest call will continue a
198 multibyte sequence. When a character is complete, ncurses displays the
199 character and moves to the next position in the screen.
200
201 If the calling application interrupts the succession of bytes in a
202 multibyte character by moving the current location (e.g., using wmove),
203 ncurses discards the partially built character, starting over again.
204
205 For portability to other implementations, do not rely upon this behav‐
206 ior:
207
208 · check if a character can be represented as a single byte in the
209 current locale before attempting call waddch, and
210
211 · call wadd_wch for characters which cannot be handled by waddch.
212
213 TABSIZE
214 The TABSIZE variable is implemented in SVr4 and other versions of
215 curses, but is not part of X/Open curses (see curs_variables(3X) for
216 more details).
217
218 If ch is a carriage return, the cursor is moved to the beginning of the
219 current row of the window. This is true of other implementations, but
220 is not documented.
221
223 curses(3X), curs_attr(3X), curs_clear(3X), curs_inch(3X), curs_out‐
224 opts(3X), curs_refresh(3X), curs_variables(3X), putc(3).
225
226 Comparable functions in the wide-character (ncursesw) library are
227 described in curs_add_wch(3X).
228
229
230
231 curs_addch(3X)