]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.2 - patch 20200725
[ncurses.git] / man / curs_addch.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2019,2020 Thomas E. Dickey                                *
4 .\" Copyright 1998-2015,2017 Free Software Foundation, Inc.                  *
5 .\"                                                                          *
6 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
7 .\" copy of this software and associated documentation files (the            *
8 .\" "Software"), to deal in the Software without restriction, including      *
9 .\" without limitation the rights to use, copy, modify, merge, publish,      *
10 .\" distribute, distribute with modifications, sublicense, and/or sell       *
11 .\" copies of the Software, and to permit persons to whom the Software is    *
12 .\" furnished to do so, subject to the following conditions:                 *
13 .\"                                                                          *
14 .\" The above copyright notice and this permission notice shall be included  *
15 .\" in all copies or substantial portions of the Software.                   *
16 .\"                                                                          *
17 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24 .\"                                                                          *
25 .\" Except as contained in this notice, the name(s) of the above copyright   *
26 .\" holders shall not be used in advertising or otherwise to promote the     *
27 .\" sale, use or other dealings in this Software without prior written       *
28 .\" authorization.                                                           *
29 .\"***************************************************************************
30 .\"
31 .\" $Id: curs_addch.3x,v 1.52 2020/03/21 23:47:23 tom Exp $
32 .TH curs_addch 3X ""
33 .ie \n(.g .ds `` \(lq
34 .el       .ds `` ``
35 .ie \n(.g .ds '' \(rq
36 .el       .ds '' ''
37 .de bP
38 .ie n  .IP \(bu 4
39 .el    .IP \(bu 2
40 ..
41 .SH NAME
42 \fBaddch\fR,
43 \fBwaddch\fR,
44 \fBmvaddch\fR,
45 \fBmvwaddch\fR,
46 \fBechochar\fR,
47 \fBwechochar\fR \- add a character (with attributes) to a \fBcurses\fR window, then advance the cursor
48 .SH SYNOPSIS
49 \fB#include <curses.h>\fR
50 .PP
51 \fBint addch(const chtype ch);\fR
52 .br
53 \fBint waddch(WINDOW *win, const chtype ch);\fR
54 .br
55 \fBint mvaddch(int y, int x, const chtype ch);\fR
56 .br
57 \fBint mvwaddch(WINDOW *win, int y, int x, const chtype ch);\fR
58 .br
59 \fBint echochar(const chtype ch);\fR
60 .br
61 \fBint wechochar(WINDOW *win, const chtype ch);\fR
62 .br
63 .SH DESCRIPTION
64 .SS Adding characters
65 The \fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR and \fBmvwaddch\fR routines put
66 the character \fIch\fR into the given window at its current window position,
67 which is then advanced.
68 They are analogous to \fBputchar\fR(3) in \fBstdio\fR(3).
69 If the advance is at the right margin:
70 .bP
71 The cursor automatically wraps to the beginning of the next line.
72 .bP
73 At the bottom of the current scrolling region,
74 and if \fBscrollok\fR is enabled,
75 the scrolling region is scrolled up one line.
76 .bP
77 If \fBscrollok\fR is not enabled,
78 writing a character at the lower right margin succeeds.
79 However, an error is returned because
80 it is not possible to wrap to a new line
81 .PP
82 If \fIch\fR is a tab, newline, carriage return or backspace,
83 the cursor is moved appropriately within the window:
84 .bP
85 Backspace moves the cursor one character left; at the left
86 edge of a window it does nothing.
87 .bP
88 Carriage return moves the cursor to the window left margin on the current line.
89 .bP
90 Newline does a \fBclrtoeol\fR,
91 then moves the cursor to the window left margin on the next line,
92 scrolling the window if on the last line.
93 .bP
94 Tabs are considered to be at every eighth column.
95 The tab interval may be altered by setting the \fBTABSIZE\fR variable.
96 .PP
97 If \fIch\fR is any other control character, it
98 is drawn in \fB^\fR\fIX\fR notation.
99 Calling \fBwinch\fR after adding a
100 control character does not return the character itself, but instead returns
101 the ^-representation of the control character.
102 .PP
103 Video attributes can be combined with a character argument passed to
104 \fBaddch\fR or related functions by logical-ORing them into the character.
105 (Thus, text, including attributes, can be copied from one place to another
106 using \fBinch\fR(3X) and \fBaddch\fR.)  See the \fBcurs_attr\fR(3X) page for
107 values of predefined video attribute constants that can be usefully OR'ed
108 into characters.
109 .SS Echoing characters
110 .PP
111 The \fBechochar\fR and \fBwechochar\fR routines are equivalent to a call to
112 \fBaddch\fR followed by a call to \fBrefresh\fR(3X), or a call to \fBwaddch\fR
113 followed by a call to \fBwrefresh\fR.
114 The knowledge that only a single
115 character is being output is used and, for non-control characters, a
116 considerable performance gain may be seen by using these routines instead of
117 their equivalents.
118 .SS Line Graphics
119 The following variables may be used to add line drawing characters to the
120 screen with routines of the \fBaddch\fR family.
121 The default character listed
122 below is used if the \fBacsc\fR capability does not define a terminal-specific
123 replacement for it,
124 or if the terminal and locale configuration requires Unicode but the
125 library is unable to use Unicode.
126 .PP
127 The names are taken from VT100 nomenclature.
128 .PP
129 .TS
130 l l l l
131 l l l l
132 _ _ _ _
133 l l l l.
134 \fBACS\fR       \fBACS\fR       \fBacsc\fP      \fBGlyph\fR
135 \fBName\fR      \fBDefault\fR   \fBchar\fP      \fBName\fR
136 ACS_BLOCK       #       0       solid square block
137 ACS_BOARD       #       h       board of squares
138 ACS_BTEE        +       v       bottom tee
139 ACS_BULLET      o       ~       bullet
140 ACS_CKBOARD     :       a       checker board (stipple)
141 ACS_DARROW      v       .       arrow pointing down
142 ACS_DEGREE      '       f       degree symbol
143 ACS_DIAMOND     +       `       diamond
144 ACS_GEQUAL      >       >       greater-than-or-equal-to
145 ACS_HLINE       \-      q       horizontal line
146 ACS_LANTERN     #       i       lantern symbol
147 ACS_LARROW      <       ,       arrow pointing left
148 ACS_LEQUAL      <       y       less-than-or-equal-to
149 ACS_LLCORNER    +       m       lower left-hand corner
150 ACS_LRCORNER    +       j       lower right-hand corner
151 ACS_LTEE        +       t       left tee
152 ACS_NEQUAL      !       |       not-equal
153 ACS_PI  *       {       greek pi
154 ACS_PLMINUS     #       g       plus/minus
155 ACS_PLUS        +       n       plus
156 ACS_RARROW      >       +       arrow pointing right
157 ACS_RTEE        +       u       right tee
158 ACS_S1  \-      o       scan line 1
159 ACS_S3  \-      p       scan line 3
160 ACS_S7  \-      r       scan line 7
161 ACS_S9  \&_     s       scan line 9
162 ACS_STERLING    f       }       pound-sterling symbol
163 ACS_TTEE        +       w       top tee
164 ACS_UARROW      ^       \-      arrow pointing up
165 ACS_ULCORNER    +       l       upper left-hand corner
166 ACS_URCORNER    +       k       upper right-hand corner
167 ACS_VLINE       |       x       vertical line
168 .TE
169 .SH RETURN VALUE
170 All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success
171 (the SVr4 manuals specify only
172 \*(``an integer value other than \fBERR\fR\*('') upon successful completion,
173 unless otherwise noted in the preceding routine descriptions.
174 .PP
175 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
176 \fBwmove\fP, and return an error if the position is outside the window,
177 or if the window pointer is null.
178 .PP
179 If it is not possible to add a complete character,
180 an error is returned:
181 .bP
182 If \fBscrollok\fR is not enabled,
183 writing a character at the lower right margin succeeds.
184 However, an error is returned because
185 it is not possible to wrap to a new line
186 .bP
187 If an error is detected when converting a multibyte character to a sequence
188 of bytes,
189 or if it is not possible to add all of the resulting bytes in the window,
190 an error is returned.
191 .SH NOTES
192 Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and
193 \fBechochar\fR may be macros.
194 .SH PORTABILITY
195 All these functions are described in the XSI Curses standard, Issue 4.
196 The defaults specified for forms-drawing characters apply in the POSIX locale.
197 .SS ACS Symbols
198 .LP
199 X/Open Curses states that the \fIACS_\fP definitions are \fBchar\fP constants.
200 For the wide-character implementation (see \fBcurs_add_wch\fP),
201 there are analogous \fIWACS_\fP definitions which are \fBcchar_t\fP constants.
202 Some implementations are problematic:
203 .bP
204 Some implementations define the ACS symbols to a constant
205 (such as Solaris), while others define those to entries in an array.
206 .IP
207 This implementation uses an array \fBacs_map\fP, as done in SVr4 curses.
208 NetBSD also uses an array, actually named \fB_acs_char\fP, with a \fB#define\fP
209 for compatibility.
210 .bP
211 HPUX curses equates some of the \fIACS_\fP symbols
212 to the analogous \fIWACS_\fP symbols as if the \fIACS_\fP symbols were
213 wide characters.
214 The misdefined symbols are the arrows
215 and other symbols which are not used for line-drawing.
216 .bP
217 X/Open Curses (issues 2 through 7) has a typographical error
218 for the ACS_LANTERN symbol, equating its \*(``VT100+ Character\*(''
219 to \fBI\fP (capital I), while the header files for SVr4 curses
220 and the various implementations use \fBi\fP (lowercase).
221 .IP
222 None of the terminal descriptions on Unix platforms use uppercase-I,
223 except for Solaris (i.e., \fIscreen\fP's terminal description,
224 apparently based on the X/Open documentation around 1995).
225 On the other hand, the terminal description \fIgs6300\fP
226 (AT&T PC6300 with EMOTS Terminal Emulator) uses lowercase-i.
227 .LP
228 Some ACS symbols
229 (ACS_S3,
230 ACS_S7,
231 ACS_LEQUAL,
232 ACS_GEQUAL,
233 ACS_PI,
234 ACS_NEQUAL,
235 ACS_STERLING)
236 were not documented in
237 any publicly released System V.
238 However, many publicly available terminfos
239 include \fBacsc\fR strings in which their key characters (pryz{|}) are
240 embedded, and a second-hand list of their character descriptions has come
241 to light.
242 The ACS-prefixed names for them were invented for \fBncurses\fR(3X).
243 .LP
244 The \fIdisplayed\fP values for the \fIACS_\fP and \fIWACS_\fP constants
245 depend on 
246 .bP
247 the library configuration, i.e., \fBncurses\fP versus \fBncursesw\fP,
248 where the latter is capable of displaying Unicode while the former is not, and
249 .bP
250 whether the \fIlocale\fP uses UTF-8 encoding.
251 .LP
252 In certain cases, the terminal is unable to display line-drawing characters
253 except by using UTF-8 (see the discussion of \fBNCURSES_NO_UTF8_ACS\fP in
254 ncurses(3X)).
255 .SS Character Set
256 X/Open Curses assumes that the parameter passed to \fBwaddch\fP contains
257 a single character.
258 As discussed in \fBcurs_attr\fP(3X), that character may have been
259 more than eight bits in an SVr3 or SVr4 implementation,
260 but in the X/Open Curses model, the details are not given.
261 The important distinction between SVr4 curses and X/Open Curses is
262 that the non-character information (attributes and color) was
263 separated from the character information which is packed in a \fBchtype\fP
264 to pass to \fBwaddch\fP.
265 .PP
266 In this implementation, \fBchtype\fP holds an eight-bit character.
267 But ncurses allows multibyte characters to be passed in a succession
268 of calls to \fBwaddch\fP.
269 The other implementations do not do this;
270 a call to \fBwaddch\fP passes exactly one character
271 which may be rendered as one or more cells on the screen
272 depending on whether it is printable.
273 .PP
274 Depending on the locale settings,
275 ncurses will inspect the byte passed in each call to \fBwaddch\fP,
276 and check if the latest call will continue a multibyte sequence.
277 When a character is \fIcomplete\fP,
278 ncurses displays the character and moves to the next position in the screen.
279 .PP
280 If the calling application interrupts the succession of bytes in
281 a multibyte character by moving the current location (e.g., using \fBwmove\fP),
282 ncurses discards the partially built character,
283 starting over again.
284 .PP
285 For portability to other implementations,
286 do not rely upon this behavior:
287 .bP
288 check if a character can be represented as a single byte in the current locale
289 before attempting call \fBwaddch\fP, and
290 .bP
291 call \fBwadd_wch\fP for characters which cannot be handled by \fBwaddch\fP.
292 .SS TABSIZE
293 .LP
294 The \fBTABSIZE\fR variable is implemented in SVr4 and other versions of curses,
295 but is not part of X/Open curses
296 (see \fBcurs_variables\fR(3X) for more details).
297 .LP
298 If \fIch\fR is a carriage return,
299 the cursor is moved to the beginning of the current row of the window.
300 This is true of other implementations, but is not documented.
301 .SH SEE ALSO
302 \fBcurses\fR(3X),
303 \fBcurs_attr\fR(3X),
304 \fBcurs_clear\fR(3X),
305 \fBcurs_inch\fR(3X),
306 \fBcurs_outopts\fR(3X),
307 \fBcurs_refresh\fR(3X),
308 \fBcurs_variables\fR(3X),
309 \fBputc\fR(3).
310 .PP
311 Comparable functions in the wide-character (ncursesw) library are
312 described in
313 \fBcurs_add_wch\fR(3X).