]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.5 - patch 20240608
[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.92 2024/06/08 20:51:41 tom Exp $
32 .TH curs_addch 3X 2024-06-08 "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 X/Open Curses,
288 Issue 4 describes these functions.
289 It specifies no error conditions for them.
290 .PP
291 SVr4
292 .I curses
293 describes a successful return value only as
294 \*(``an integer value other than
295 .BR ERR \*(''.
296 .PP
297 The defaults specified for forms-drawing characters apply in the POSIX
298 locale.
299 .SS "ACS Symbols"
300 X/Open Curses states that the
301 .B \%ACS_
302 definitions are
303 .I char
304 constants.
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 .\" And did not exist yet as late as SVr4.
372 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/\
373 .\"   sysvr4/svr4/lib/xlibcurses/screen/curses.ed
374 However,
375 many publicly available
376 .I \%term\%info
377 entries include
378 .B \%acsc
379 capabilities in which their key characters
380 .RB ( pryz{|} )
381 are embedded,
382 and a second-hand list of their character descriptions has come to
383 light.
384 The
385 .I \%ncurses
386 developers invented ACS-prefixed names for them.
387 .PP
388 The
389 .I displayed
390 values of
391 .B \%ACS_
392 constants depend on
393 .bP
394 the
395 .I \%ncurses
396 ABI\(emfor example,
397 wide-character versus non-wide-character configurations
398 (the former is capable of displaying Unicode while the latter is not),
399 and
400 .bP
401 whether the locale uses UTF-8 encoding.
402 .PP
403 In certain cases,
404 the terminal is unable to display forms-drawing characters
405 .I except
406 by using UTF-8;
407 see the discussion of the
408 .I \%NCURSES_NO_UTF8_ACS
409 environment variable in \fB\%ncurses\fP(3X).
410 .SS "Character Set"
411 X/Open Curses assumes that the parameter passed to
412 .B \%waddch
413 contains a single character.
414 That character may have been more than eight bits wide in an SVr3 or
415 SVr4 implementation,
416 but X/Open Curses leaves the width of a non-wide character code
417 unspecified.
418 The standard further does not specify the internal structure of a
419 .IR chtype ","
420 though the use of bit operations to combine the character code with
421 attributes and a color pair identifier into a
422 .I \%chtype
423 for passage to
424 .B \%waddch
425 is common.
426 A portable application uses only the macros discussed in
427 \fB\%curs_attr\fP(3X) to manipulate a
428 .IR \%chtype "."
429 .PP
430 In
431 .IR \%ncurses ,
432 .I \%chtype
433 holds an eight-bit character,
434 but the library allows a multibyte character sequence to be passed via a
435 succession of calls to
436 .BR \%waddch "."
437 Other implementations do not;
438 a
439 .B \%waddch
440 call transmits exactly one character,
441 which may be rendered in one or more screen locations depending on
442 whether it is printable
443 (see \fB\%unctrl\fP(3X)).
444 Depending on the locale,
445 .I \%ncurses
446 inspects the byte passed in each
447 .B \%waddch
448 call and checks whether the latest call continues a multibyte character.
449 When a character is
450 .IR complete ","
451 .I \%ncurses
452 displays the character and advances the cursor.
453 If the calling application interrupts the succession of bytes in
454 a multibyte character sequence by changing the current location\(emfor
455 example,
456 with \fB\%wmove\fP(3X)\(em\c
457 .I \%ncurses
458 discards the incomplete character.
459 .PP
460 For portability to other implementations,
461 do not rely upon the foregoing behavior.
462 Check whether a character can be represented as a single byte in the
463 current locale.
464 .bP
465 If it can,
466 call either
467 .B \%waddch
468 or \fB\%wadd_wch\fP(3X).
469 .bP
470 If it cannot,
471 use only
472 \fB\%wadd_wch\fP(3X).
473 .SH HISTORY
474 The original
475 .I curses
476 in 4BSD (1980) introduced
477 .IR \%waddch "."
478 .PP
479 SVr3 (1987)
480 added
481 .IR \%wechochar "."
482 .SH SEE ALSO
483 \fB\%curs_add_wch\fP(3X) describes comparable functions of the
484 .I \%ncurses
485 library in its wide-character configuration
486 .RI \%( ncursesw ).
487 .PP
488 \fB\%curses\fP(3X),
489 \fB\%curs_addchstr\fP(3X),
490 \fB\%curs_addstr\fP(3X),
491 \fB\%curs_attr\fP(3X),
492 \fB\%curs_clear\fP(3X),
493 \fB\%curs_inch\fP(3X),
494 \fB\%curs_outopts\fP(3X),
495 \fB\%curs_refresh\fP(3X),
496 \fB\%curs_variables\fP(3X),
497 \fB\%putchar\fP(3)