]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.5 - patch 20240525
[ncurses.git] / man / curs_addch.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2023,2024 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.88 2024/05/25 21:13:32 tom Exp $
32 .TH curs_addch 3X 2024-05-25 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
33 .ie \n(.g \{\
34 .ds `` \(lq
35 .ds '' \(rq
36 .ds '  \(aq
37 .ds ^  \(ha
38 .ds ~  \(ti
39 .\}
40 .el \{\
41 .ie t .ds `` ``
42 .el   .ds `` ""
43 .ie t .ds '' ''
44 .el   .ds '' ""
45 .ds       '  '
46 .ds       ^  ^
47 .ds       ~  ~
48 .\}
49 .
50 .de bP
51 .ie n  .IP \(bu 4
52 .el    .IP \(bu 2
53 ..
54 .SH NAME
55 \fB\%addch\fP,
56 \fB\%waddch\fP,
57 \fB\%mvaddch\fP,
58 \fB\%mvwaddch\fP,
59 \fB\%echochar\fP,
60 \fB\%wechochar\fP \-
61 add a \fIcurses\fP character to a window and advance the cursor
62 .SH SYNOPSIS
63 .nf
64 \fB#include <curses.h>
65 .PP
66 \fBint addch(const chtype \fIch\fP);
67 \fBint waddch(WINDOW *\fIwin\fP, const chtype \fIch\fP);
68 \fBint mvaddch(int \fIy\fP, int \fIx\fP, const chtype \fIch\fP);
69 \fBint mvwaddch(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, const chtype \fIch\fP);
70 .PP
71 \fBint echochar(const chtype \fIch\fP);
72 \fBint wechochar(WINDOW *\fIwin\fP, const chtype \fIch\fP);
73 .fi
74 .SH DESCRIPTION
75 .SS waddch
76 .B \%waddch
77 writes the
78 .I curses
79 character
80 .I ch
81 to the window
82 .IR win ","
83 then advances the cursor position,
84 analogously to the standard C library's \fI\%putchar\fP(3).
85 \fB\%ncurses\fP(3X) describes the variants of this function.
86 .PP
87 If advancement occurs at the right margin,
88 .bP
89 the cursor automatically wraps to the beginning of the next line,
90 then,
91 .bP
92 if it was at the bottom of the scrolling region,
93 and if \fB\%scrollok\fP(3X) is enabled for
94 .IR win ,
95 the scrolling region scrolls up one line.
96 .PP
97 If
98 .I ch
99 is a
100 backspace,
101 carriage return,
102 line feed,
103 or
104 tab,
105 the cursor moves appropriately within the window.
106 .bP
107 Backspace moves the cursor one character left;
108 at the left margin of a window,
109 it does nothing.
110 .bP
111 Carriage return moves the cursor to the left margin on the current line
112 of the window.
113 .bP
114 Line feed does a \fB\%clrtoeol\fP(3X),
115 then advances as if from the right margin.
116 .bP
117 Tab advances the cursor to the next tab stop
118 (possibly on the next line);
119 these are placed at every eighth column by default.
120 Alter the tab interval with the
121 .B \%TABSIZE
122 extension;
123 see \fB\%curs_variables\fP(3X).
124 .PP
125 If
126 .I ch
127 is any other nonprintable character,
128 it is drawn in printable form using the same convention as
129 \fB\%unctrl\fP(3X).
130 .PP
131 Calling \fB\%winch\fP(3X) on the location of a nonprintable character
132 does not return the character itself,
133 but its \fB\%unctrl\fP(3X) representation.
134 .PP
135 The object or expression
136 .I ch
137 may contain attributes and/or a color pair identifier.
138 (A character with its attributes can be copied from place to place
139 using \fB\%winch\fP(3X) and
140 .BR \%waddch .)
141 See \fB\%curs_attr\fP(3X) for values of predefined video attribute
142 constants that can be usefully \*(``or\*(''ed with characters.
143 .SS wechochar
144 .B \%echochar
145 and
146 .B \%wechochar
147 are equivalent to calling
148 .RB \%( w ) addch
149 followed by
150 .RB \%( w ) refresh .
151 .I curses
152 interprets these functions as a hint that only a single character is
153 being output;
154 for non-control characters,
155 a considerable performance gain may be enjoyed by employing them.
156 .\" TODO: Combine the following with the "Line Drawing" subsection of
157 .\" terminfo(5) and replace this with a cross reference there.
158 .SS "Forms-Drawing Characters"
159 .I curses
160 defines macros starting with
161 .B \%ACS_
162 that can be used with
163 .B \%waddch
164 to write line-drawing and other special characters to the screen.
165 .I \%ncurses
166 terms these
167 .I "forms-drawing characters."
168 The ACS default listed below is used if the
169 .B \%acs_chars
170 .RB \%( acsc )
171 .I \%term\%info
172 capability does not define a terminal-specific replacement for it,
173 or if the terminal and locale configuration requires Unicode to access
174 these characters but the library is unable to use Unicode.
175 The \*(``acsc char\*('' column corresponds to how the characters are
176 specified in the
177 .B \%acs_chars
178 .RB \%( acsc )
179 string capability,
180 and the characters in it may appear on the screen if the terminal type's
181 database entry incorrectly advertises ACS support.
182 The name \*(``ACS\*('' originates in the Alternate Character Set feature
183 of the DEC VT100 terminal.
184 .br
185 .ie t .ne 4v
186 .el   .ne 5v
187 .TS
188 Lb Lb Lb Lb
189 Lb Lb Lb Lb
190 Lb L  L  Lx.
191 \&      ACS     acsc    \&
192 Symbol  Default char    Glyph Name
193 _
194 ACS_BLOCK       #       0       solid square block
195 ACS_BOARD       #       h       board of squares
196 ACS_BTEE        +       v       bottom tee
197 ACS_BULLET      o       \*~     bullet
198 ACS_CKBOARD     :       a       checker board (stipple)
199 ACS_DARROW      v       .       arrow pointing down
200 ACS_DEGREE      \*'     f       degree symbol
201 ACS_DIAMOND     +       \(ga    diamond
202 ACS_GEQUAL      >       >       greater-than-or-equal-to
203 ACS_HLINE       \-      q       horizontal line
204 ACS_LANTERN     #       i       lantern symbol
205 ACS_LARROW      <       ,       arrow pointing left
206 ACS_LEQUAL      <       y       less-than-or-equal-to
207 ACS_LLCORNER    +       m       lower left-hand corner
208 ACS_LRCORNER    +       j       lower right-hand corner
209 ACS_LTEE        +       t       left tee
210 ACS_NEQUAL      !       |       not-equal
211 ACS_PI  *       {       greek pi
212 ACS_PLMINUS     #       g       plus/minus
213 ACS_PLUS        +       n       plus
214 ACS_RARROW      >       +       arrow pointing right
215 ACS_RTEE        +       u       right tee
216 ACS_S1  \-      o       scan line 1
217 ACS_S3  \-      p       scan line 3
218 ACS_S7  \-      r       scan line 7
219 ACS_S9  \&_     s       scan line 9
220 ACS_STERLING    f       }       pound-sterling symbol
221 ACS_TTEE        +       w       top tee
222 ACS_UARROW      \*^     \-      arrow pointing up
223 ACS_ULCORNER    +       l       upper left-hand corner
224 ACS_URCORNER    +       k       upper right-hand corner
225 ACS_VLINE       |       x       vertical line
226 .TE
227 .SH RETURN VALUE
228 These functions return
229 .B OK
230 on success and
231 .B ERR
232 on failure.
233 .PP
234 In
235 .IR \%ncurses ,
236 .B \%waddch
237 returns
238 .B ERR
239 if
240 .bP
241 .I win
242 is
243 .BR NULL ","
244 .bP
245 wrapping to a new line is impossible because \fB\%scrollok\fP(3X) has
246 not been called on
247 .I win
248 when a write to its bottom right location is attempted,
249 or
250 .bP
251 it is not possible to add a complete character at the cursor position.
252 .PP
253 The last may be due to different causes:
254 .bP
255 conversion of a multibyte character to a byte sequence can fail,
256 or
257 .bP
258 at least one of the bytes resulting from conversion from a multibyte
259 sequence cannot be added to the window.
260 See section \*(``PORTABILITY\*('' below regarding the use of
261 .B \%waddch
262 with multibyte characters.
263 .PP
264 Functions prefixed with \*(``mv\*('' first perform cursor movement and
265 fail if the position
266 .RI ( y ,
267 .IR x )
268 is outside the window boundaries.
269 .SH NOTES
270 .BR \%addch ","
271 .BR \%mvaddch ","
272 .BR \%mvwaddch ","
273 and
274 .B \%echochar
275 may be implemented as macros.
276 .SH EXTENSIONS
277 .SS TABSIZE
278 SVr4 and other versions of
279 .I curses
280 implement the
281 .B \%TABSIZE
282 variable,
283 but X/Open Curses does not specify it;
284 see \fB\%curs_variables\fP(3X).
285 .SH PORTABILITY
286 X/Open Curses,
287 Issue 4 describes these functions.
288 It specifies no error conditions for them.
289 .PP
290 SVr4
291 .I curses
292 describes a successful return value only as
293 \*(``an integer value other than
294 .BR ERR \*(''.
295 .PP
296 The defaults specified for forms-drawing characters apply in the POSIX
297 locale.
298 .SS "ACS Symbols"
299 X/Open Curses states that the
300 .B \%ACS_
301 definitions are
302 .I char
303 constants.
304 .PP
305 Some implementations are problematic.
306 .bP
307 Solaris
308 .IR curses ,
309 for example,
310 defines the ACS symbols as constants;
311 others define them as elements of an array.
312 .IP
313 This implementation uses an array,
314 .BR \%acs_map ,
315 as did SVr4
316 .IR curses .
317 NetBSD also uses an array,
318 actually named
319 .BR \%_acs_char ,
320 with a
321 .B \%#define
322 for compatibility.
323 .bP
324 HP-UX
325 .I curses
326 equates some of the
327 .B \%ACS_
328 symbols to the analogous
329 .B \%WACS_
330 symbols as if the
331 .B \%ACS_
332 symbols were wide characters
333 (see \fB\%curs_add_wch\fP(3X)).
334 The misdefined symbols are the arrows and others that are not used for
335 line drawing.
336 .bP
337 X/Open Curses
338 (Issues 2 through 7)
339 has a typographical error
340 for the
341 .B \%ACS_LANTERN
342 symbol, equating its \*(``VT100+ Character\*('' to \*(``I\*(''
343 (capital I),
344 while the header files for SVr4
345 .I curses
346 and other implementations use \*(``i\*(''
347 (small i).
348 .IP
349 None of the terminal descriptions on Unix platforms use uppercase I,
350 except for Solaris
351 (in its
352 .I \%term\%info
353 entry for \fI\%screen\fP(1),
354 apparently based on the X/Open documentation around 1995).
355 On the other hand,
356 its
357 .B \%gs6300
358 (AT&T PC6300 with EMOTS Terminal Emulator)
359 description uses lowercase i.
360 .PP
361 Some ACS symbols
362 .RB ( \%ACS_S3 ,
363 .BR \%ACS_S7 ,
364 .BR \%ACS_LEQUAL ,
365 .BR \%ACS_GEQUAL ,
366 .BR \%ACS_PI ,
367 .BR \%ACS_NEQUAL ,
368 and
369 .BR \%ACS_STERLING )
370 were not documented in any publicly released System\ V.
371 However,
372 many publicly available
373 .I \%term\%info
374 entries include
375 .B \%acsc
376 capabilities in which their key characters
377 .RB ( pryz{|} )
378 are embedded,
379 and a second-hand list of their character descriptions has come to
380 light.
381 The
382 .I \%ncurses
383 developers invented ACS-prefixed names for them.
384 .PP
385 The
386 .I displayed
387 values of
388 .B \%ACS_
389 constants depend on
390 .bP
391 the
392 .I \%ncurses
393 ABI\(emfor example,
394 wide-character versus non-wide-character configurations
395 (the former is capable of displaying Unicode while the latter is not),
396 and
397 .bP
398 whether the locale uses UTF-8 encoding.
399 .PP
400 In certain cases,
401 the terminal is unable to display forms-drawing characters
402 .I except
403 by using UTF-8;
404 see the discussion of the
405 .I \%NCURSES_NO_UTF8_ACS
406 environment variable in \fB\%ncurses\fP(3X).
407 .SS "Character Set"
408 X/Open Curses assumes that the parameter passed to
409 .B \%waddch
410 contains a single character.
411 That character may have been more than eight bits wide in an SVr3 or
412 SVr4 implementation,
413 but X/Open Curses leaves the width of a non-wide character code
414 unspecified.
415 The standard further does not specify the internal structure of a
416 .IR chtype ","
417 though the use of bit operations to combine the character code with
418 attributes and a color pair identifier into a
419 .I \%chtype
420 for passage to
421 .B \%waddch
422 is common.
423 A portable application uses only the macros discussed in
424 \fB\%curs_attr\fP(3X) to manipulate a
425 .IR \%chtype "."
426 .PP
427 In
428 .IR \%ncurses ,
429 .I \%chtype
430 holds an eight-bit character,
431 but the library allows a multibyte character to be passed in a
432 succession of calls to
433 .BR \%waddch "."
434 Other implementations do not;
435 a
436 .B \%waddch
437 call transmits exactly one character,
438 which may be rendered in one or more screen locations depending on
439 whether it is printable
440 (see \fB\%unctrl\fP(3X)).
441 Depending on the locale,
442 .I \%ncurses
443 inspects the byte passed in each
444 .B \%waddch
445 call and checks whether the latest call continues a multibyte sequence.
446 When a character is
447 .IR complete ","
448 .I \%ncurses
449 displays the character and advances the cursor.
450 If the calling application interrupts the succession of bytes in
451 a multibyte character sequence by changing the current location\(emfor
452 example,
453 with \fB\%wmove\fP(3X)\(em\c
454 .I \%ncurses
455 discards the incomplete character.
456 .PP
457 For portability to other implementations,
458 do not rely upon the foregoing behavior.
459 Check whether a character can be represented as a single byte in the
460 current locale.
461 .bP
462 If it can,
463 call either
464 .B \%waddch
465 or \fB\%wadd_wch\fP(3X).
466 .bP
467 If it cannot,
468 use only
469 \fB\%wadd_wch\fP(3X).
470 .SH SEE ALSO
471 \fB\%curs_add_wch\fP(3X) describes comparable functions of the
472 .I \%ncurses
473 library in its wide-character configuration
474 .RI ( \%ncursesw ).
475 .PP
476 \fB\%curses\fP(3X),
477 \fB\%curs_addchstr\fP(3X),
478 \fB\%curs_addstr\fP(3X),
479 \fB\%curs_attr\fP(3X),
480 \fB\%curs_clear\fP(3X),
481 \fB\%curs_inch\fP(3X),
482 \fB\%curs_outopts\fP(3X),
483 \fB\%curs_refresh\fP(3X),
484 \fB\%curs_variables\fP(3X),
485 \fB\%putchar\fP(3)