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