]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.2 - patch 20210828
[ncurses.git] / man / curs_addch.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2020,2021 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.56 2021/06/17 21:30:22 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 \fP\fIch\fP\fB);\fR
52 .br
53 \fBint waddch(WINDOW *\fP\fIwin\fP\fB, const chtype \fP\fIch\fP\fB);\fR
54 .br
55 \fBint mvaddch(int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, const chtype \fP\fIch\fP\fB);\fR
56 .br
57 \fBint mvwaddch(WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, const chtype \fP\fIch\fP\fB);\fR
58 .sp
59 \fBint echochar(const chtype \fP\fIch\fP\fB);\fR
60 .br
61 \fBint wechochar(WINDOW *\fP\fIwin\fP\fB, const chtype \fP\fIch\fP\fB);\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 nonprintable character,
98 it is drawn in printable form,
99 i.e., the \fB^\fR\fIX\fR notation used by \fBunctrl\fR(3X).
100 Calling \fBwinch\fR after adding a
101 nonprintable character does not return the character itself,
102 but instead returns the printable representation of the character.
103 .PP
104 Video attributes can be combined with a character argument passed to
105 \fBaddch\fR or related functions by logical-ORing them into the character.
106 (Thus, text, including attributes, can be copied from one place to another
107 using \fBinch\fR(3X) and \fBaddch\fR.)  See the \fBcurs_attr\fR(3X) page for
108 values of predefined video attribute constants that can be usefully OR'ed
109 into characters.
110 .SS Echoing characters
111 .PP
112 The \fBechochar\fR and \fBwechochar\fR routines are equivalent to a call to
113 \fBaddch\fR followed by a call to \fBrefresh\fR(3X), or a call to \fBwaddch\fR
114 followed by a call to \fBwrefresh\fR.
115 The knowledge that only a single
116 character is being output is used and, for non-control characters, a
117 considerable performance gain may be seen by using these routines instead of
118 their equivalents.
119 .SS Line Graphics
120 The following variables may be used to add line drawing characters to the
121 screen with routines of the \fBaddch\fR family.
122 The default character listed
123 below is used if the \fBacsc\fR capability does not define a terminal-specific
124 replacement for it,
125 or if the terminal and locale configuration requires Unicode but the
126 library is unable to use Unicode.
127 .PP
128 The names are taken from VT100 nomenclature.
129 .PP
130 .TS
131 l l l l
132 l l l l
133 _ _ _ _
134 l l l l.
135 \fBACS\fR       \fBACS\fR       \fBacsc\fP      \fBGlyph\fR
136 \fBName\fR      \fBDefault\fR   \fBchar\fP      \fBName\fR
137 ACS_BLOCK       #       0       solid square block
138 ACS_BOARD       #       h       board of squares
139 ACS_BTEE        +       v       bottom tee
140 ACS_BULLET      o       ~       bullet
141 ACS_CKBOARD     :       a       checker board (stipple)
142 ACS_DARROW      v       .       arrow pointing down
143 ACS_DEGREE      '       f       degree symbol
144 ACS_DIAMOND     +       `       diamond
145 ACS_GEQUAL      >       >       greater-than-or-equal-to
146 ACS_HLINE       \-      q       horizontal line
147 ACS_LANTERN     #       i       lantern symbol
148 ACS_LARROW      <       ,       arrow pointing left
149 ACS_LEQUAL      <       y       less-than-or-equal-to
150 ACS_LLCORNER    +       m       lower left-hand corner
151 ACS_LRCORNER    +       j       lower right-hand corner
152 ACS_LTEE        +       t       left tee
153 ACS_NEQUAL      !       |       not-equal
154 ACS_PI  *       {       greek pi
155 ACS_PLMINUS     #       g       plus/minus
156 ACS_PLUS        +       n       plus
157 ACS_RARROW      >       +       arrow pointing right
158 ACS_RTEE        +       u       right tee
159 ACS_S1  \-      o       scan line 1
160 ACS_S3  \-      p       scan line 3
161 ACS_S7  \-      r       scan line 7
162 ACS_S9  \&_     s       scan line 9
163 ACS_STERLING    f       }       pound-sterling symbol
164 ACS_TTEE        +       w       top tee
165 ACS_UARROW      ^       \-      arrow pointing up
166 ACS_ULCORNER    +       l       upper left-hand corner
167 ACS_URCORNER    +       k       upper right-hand corner
168 ACS_VLINE       |       x       vertical line
169 .TE
170 .SH RETURN VALUE
171 All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success
172 (the SVr4 manuals specify only
173 \*(``an integer value other than \fBERR\fR\*('') upon successful completion,
174 unless otherwise noted in the preceding routine descriptions.
175 .PP
176 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
177 \fBwmove\fP, and return an error if the position is outside the window,
178 or if the window pointer is null.
179 .PP
180 If it is not possible to add a complete character,
181 an error is returned:
182 .bP
183 If \fBscrollok\fR is not enabled,
184 writing a character at the lower right margin succeeds.
185 However, an error is returned because
186 it is not possible to wrap to a new line
187 .bP
188 If an error is detected when converting a multibyte character to a sequence
189 of bytes,
190 or if it is not possible to add all of the resulting bytes in the window,
191 an error is returned.
192 .SH NOTES
193 Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and
194 \fBechochar\fR may be macros.
195 .SH PORTABILITY
196 All these functions are described in the XSI Curses standard, Issue 4.
197 The defaults specified for forms-drawing characters apply in the POSIX locale.
198 .SS ACS Symbols
199 .LP
200 X/Open Curses states that the \fIACS_\fP definitions are \fBchar\fP constants.
201 For the wide-character implementation (see \fBcurs_add_wch\fP),
202 there are analogous \fIWACS_\fP definitions which are \fBcchar_t\fP constants.
203 Some implementations are problematic:
204 .bP
205 Some implementations define the ACS symbols to a constant
206 (such as Solaris), while others define those to entries in an array.
207 .IP
208 This implementation uses an array \fBacs_map\fP, as done in SVr4 curses.
209 NetBSD also uses an array, actually named \fB_acs_char\fP, with a \fB#define\fP
210 for compatibility.
211 .bP
212 HPUX curses equates some of the \fIACS_\fP symbols
213 to the analogous \fIWACS_\fP symbols as if the \fIACS_\fP symbols were
214 wide characters.
215 The misdefined symbols are the arrows
216 and other symbols which are not used for line-drawing.
217 .bP
218 X/Open Curses (issues 2 through 7) has a typographical error
219 for the ACS_LANTERN symbol, equating its \*(``VT100+ Character\*(''
220 to \fBI\fP (capital I), while the header files for SVr4 curses
221 and the various implementations use \fBi\fP (lowercase).
222 .IP
223 None of the terminal descriptions on Unix platforms use uppercase-I,
224 except for Solaris (i.e., \fIscreen\fP's terminal description,
225 apparently based on the X/Open documentation around 1995).
226 On the other hand, the terminal description \fIgs6300\fP
227 (AT&T PC6300 with EMOTS Terminal Emulator) uses lowercase-i.
228 .LP
229 Some ACS symbols
230 (ACS_S3,
231 ACS_S7,
232 ACS_LEQUAL,
233 ACS_GEQUAL,
234 ACS_PI,
235 ACS_NEQUAL,
236 ACS_STERLING)
237 were not documented in
238 any publicly released System V.
239 However, many publicly available terminfos
240 include \fBacsc\fR strings in which their key characters (pryz{|}) are
241 embedded, and a second-hand list of their character descriptions has come
242 to light.
243 The ACS-prefixed names for them were invented for \fBncurses\fR(3X).
244 .LP
245 The \fIdisplayed\fP values for the \fIACS_\fP and \fIWACS_\fP constants
246 depend on
247 .bP
248 the library configuration, i.e., \fBncurses\fP versus \fBncursesw\fP,
249 where the latter is capable of displaying Unicode while the former is not, and
250 .bP
251 whether the \fIlocale\fP uses UTF-8 encoding.
252 .LP
253 In certain cases, the terminal is unable to display line-drawing characters
254 except by using UTF-8 (see the discussion of \fBNCURSES_NO_UTF8_ACS\fP in
255 ncurses(3X)).
256 .SS Character Set
257 X/Open Curses assumes that the parameter passed to \fBwaddch\fP contains
258 a single character.
259 As discussed in \fBcurs_attr\fP(3X), that character may have been
260 more than eight bits in an SVr3 or SVr4 implementation,
261 but in the X/Open Curses model, the details are not given.
262 The important distinction between SVr4 curses and X/Open Curses is
263 that the non-character information (attributes and color) was
264 separated from the character information which is packed in a \fBchtype\fP
265 to pass to \fBwaddch\fP.
266 .PP
267 In this implementation, \fBchtype\fP holds an eight-bit character.
268 But ncurses allows multibyte characters to be passed in a succession
269 of calls to \fBwaddch\fP.
270 The other implementations do not do this;
271 a call to \fBwaddch\fP passes exactly one character
272 which may be rendered as one or more cells on the screen
273 depending on whether it is printable.
274 .PP
275 Depending on the locale settings,
276 ncurses will inspect the byte passed in each call to \fBwaddch\fP,
277 and check if the latest call will continue a multibyte sequence.
278 When a character is \fIcomplete\fP,
279 ncurses displays the character and moves to the next position in the screen.
280 .PP
281 If the calling application interrupts the succession of bytes in
282 a multibyte character by moving the current location (e.g., using \fBwmove\fP),
283 ncurses discards the partially built character,
284 starting over again.
285 .PP
286 For portability to other implementations,
287 do not rely upon this behavior:
288 .bP
289 check if a character can be represented as a single byte in the current locale
290 before attempting call \fBwaddch\fP, and
291 .bP
292 call \fBwadd_wch\fP for characters which cannot be handled by \fBwaddch\fP.
293 .SS TABSIZE
294 .LP
295 The \fBTABSIZE\fR variable is implemented in SVr4 and other versions of curses,
296 but is not part of X/Open curses
297 (see \fBcurs_variables\fR(3X) for more details).
298 .LP
299 If \fIch\fR is a carriage return,
300 the cursor is moved to the beginning of the current row of the window.
301 This is true of other implementations, but is not documented.
302 .SH SEE ALSO
303 \fBcurses\fR(3X),
304 \fBcurs_attr\fR(3X),
305 \fBcurs_clear\fR(3X),
306 \fBcurs_inch\fR(3X),
307 \fBcurs_outopts\fR(3X),
308 \fBcurs_refresh\fR(3X),
309 \fBcurs_variables\fR(3X),
310 \fBputc\fR(3).
311 .PP
312 Comparable functions in the wide-character (ncursesw) library are
313 described in
314 \fBcurs_add_wch\fR(3X).