]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.5 - patch 20240622
[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.94 2024/06/22 21:34:49 tom Exp $
32 .TH curs_addch 3X 2024-06-22 "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 Calling \fB\%winch\fP(3X) on the location of a nonprintable character
131 does not return the character itself,
132 but its \fB\%unctrl\fP(3X) representation.
133 .PP
134 The object or expression
135 .I ch
136 may contain attributes and/or a color pair identifier.
137 (A
138 .I \%chtype
139 can be copied from place to place using \fB\%winch\fP(3X) and
140 .BR \%waddch .)
141 See \fB\%curs_attr\fP(3X) for values of predefined constants that can be
142 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 .PP
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 wide character to a multibyte character sequence can
256 fail,
257 or
258 .bP
259 at least one of the bytes resulting from wide character conversion to a
260 multibyte character sequence cannot be added to the window.
261 See section \*(``PORTABILITY\*('' below regarding the use of
262 .B \%waddch
263 with wide characters.
264 .PP
265 Functions prefixed with \*(``mv\*('' first perform cursor movement and
266 fail if the position
267 .RI ( y ,
268 .IR x )
269 is outside the window boundaries.
270 .SH NOTES
271 .BR \%addch ","
272 .BR \%mvaddch ","
273 .BR \%mvwaddch ","
274 and
275 .B \%echochar
276 may be implemented as macros.
277 .SH EXTENSIONS
278 .SS TABSIZE
279 SVr4 and other versions of
280 .I curses
281 implement the
282 .B \%TABSIZE
283 variable,
284 but X/Open Curses does not specify it;
285 see \fB\%curs_variables\fP(3X).
286 .SH PORTABILITY
287 Applications employing
288 .I \%ncurses
289 extensions should condition their use on the visibility of the
290 .B \%NCURSES_VERSION
291 preprocessor macro.
292 .PP
293 X/Open Curses,
294 Issue 4 describes these functions.
295 It specifies no error conditions for them.
296 .PP
297 SVr4
298 .I curses
299 describes a successful return value only as
300 \*(``an integer value other than
301 .BR ERR \*(''.
302 .PP
303 The defaults specified for forms-drawing characters apply in the POSIX
304 locale.
305 .SS "ACS Symbols"
306 X/Open Curses states that the
307 .B \%ACS_
308 definitions are
309 .I char
310 constants.
311 Some implementations are problematic.
312 .bP
313 Solaris
314 .IR curses ,
315 for example,
316 defines the ACS symbols as constants;
317 others define them as elements of an array.
318 .IP
319 This implementation uses an array,
320 .BR \%acs_map ,
321 as did SVr4
322 .IR curses .
323 NetBSD also uses an array,
324 actually named
325 .BR \%_acs_char ,
326 with a
327 .B \%#define
328 for compatibility.
329 .bP
330 HP-UX
331 .I curses
332 equates some of the
333 .B \%ACS_
334 symbols to the analogous
335 .B \%WACS_
336 symbols as if the
337 .B \%ACS_
338 symbols were wide characters
339 (see \fB\%curs_add_wch\fP(3X)).
340 The misdefined symbols are the arrows and others that are not used for
341 line drawing.
342 .bP
343 X/Open Curses
344 (Issues 2 through 7)
345 has a typographical error
346 for the
347 .B \%ACS_LANTERN
348 symbol, equating its \*(``VT100+ Character\*('' to \*(``I\*(''
349 (capital I),
350 while the header files for SVr4
351 .I curses
352 and other implementations use \*(``i\*(''
353 (small i).
354 .IP
355 None of the terminal descriptions on Unix platforms use uppercase I,
356 except for Solaris
357 (in its
358 .I \%term\%info
359 entry for \fI\%screen\fP(1),
360 apparently based on the X/Open documentation around 1995).
361 On the other hand,
362 its
363 .B \%gs6300
364 (AT&T PC6300 with EMOTS Terminal Emulator)
365 description uses lowercase i.
366 .PP
367 Some ACS symbols
368 .RB \%( ACS_S3 ,
369 .BR \%ACS_S7 ,
370 .BR \%ACS_LEQUAL ,
371 .BR \%ACS_GEQUAL ,
372 .BR \%ACS_PI ,
373 .BR \%ACS_NEQUAL ,
374 and
375 .BR \%ACS_STERLING )
376 were not documented in any publicly released System\ V.
377 .\" And did not exist yet as late as SVr4.
378 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/\
379 .\"   sysvr4/svr4/lib/xlibcurses/screen/curses.ed
380 However,
381 many publicly available
382 .I \%term\%info
383 entries include
384 .B \%acsc
385 capabilities in which their key characters
386 .RB ( pryz{|} )
387 are embedded,
388 and a second-hand list of their character descriptions has come to
389 light.
390 The
391 .I \%ncurses
392 developers invented ACS-prefixed names for them.
393 .PP
394 The
395 .I displayed
396 values of
397 .B \%ACS_
398 constants depend on
399 .bP
400 the
401 .I \%ncurses
402 ABI\(emfor example,
403 wide-character versus non-wide-character configurations
404 (the former is capable of displaying Unicode while the latter is not),
405 and
406 .bP
407 whether the locale uses UTF-8 encoding.
408 .PP
409 In certain cases,
410 the terminal is unable to display forms-drawing characters
411 .I except
412 by using UTF-8;
413 see the discussion of the
414 .I \%NCURSES_NO_UTF8_ACS
415 environment variable in \fB\%ncurses\fP(3X).
416 .SS "Character Set"
417 X/Open Curses assumes that the parameter passed to
418 .B \%waddch
419 contains a single character.
420 That character may have been more than eight bits wide in an SVr3 or
421 SVr4 implementation,
422 but X/Open Curses leaves the width of a non-wide character code
423 unspecified.
424 The standard further does not specify the internal structure of a
425 .IR chtype ","
426 though the use of bit operations to combine the character code with
427 attributes and a color pair identifier into a
428 .I \%chtype
429 for passage to
430 .B \%waddch
431 is common.
432 A portable application uses only the macros discussed in
433 \fB\%curs_attr\fP(3X) to manipulate a
434 .IR \%chtype "."
435 .PP
436 In
437 .IR \%ncurses ,
438 .I \%chtype
439 holds an eight-bit character,
440 but the library allows a multibyte character sequence to be passed via a
441 succession of calls to
442 .BR \%waddch "."
443 Other implementations do not;
444 a
445 .B \%waddch
446 call transmits exactly one character,
447 which may be rendered in one or more screen locations depending on
448 whether it is printable
449 (see \fB\%unctrl\fP(3X)).
450 Depending on the locale,
451 .I \%ncurses
452 inspects the byte passed in each
453 .B \%waddch
454 call and checks whether the latest call continues a multibyte character.
455 When a character is
456 .IR complete ","
457 .I \%ncurses
458 displays the character and advances the cursor.
459 If the calling application interrupts the succession of bytes in
460 a multibyte character sequence by changing the current location\(emfor
461 example,
462 with \fB\%wmove\fP(3X)\(em\c
463 .I \%ncurses
464 discards the incomplete character.
465 .PP
466 For portability to other implementations,
467 do not rely upon the foregoing behavior.
468 Check whether a character can be represented as a single byte in the
469 current locale.
470 .bP
471 If it can,
472 call either
473 .B \%waddch
474 or \fB\%wadd_wch\fP(3X).
475 .bP
476 If it cannot,
477 use only
478 \fB\%wadd_wch\fP(3X).
479 .SH HISTORY
480 4BSD (1980)
481 .I curses
482 introduced
483 .IR \%waddch "."
484 .PP
485 SVr3 (1987)
486 added
487 .IR \%wechochar "."
488 .SH SEE ALSO
489 \fB\%curs_add_wch\fP(3X) describes comparable functions of the
490 .I \%ncurses
491 library in its wide-character configuration
492 .RI \%( ncursesw ).
493 .PP
494 \fB\%curses\fP(3X),
495 \fB\%curs_addchstr\fP(3X),
496 \fB\%curs_addstr\fP(3X),
497 \fB\%curs_attr\fP(3X),
498 \fB\%curs_clear\fP(3X),
499 \fB\%curs_inch\fP(3X),
500 \fB\%curs_outopts\fP(3X),
501 \fB\%curs_refresh\fP(3X),
502 \fB\%curs_variables\fP(3X),
503 \fB\%putchar\fP(3)