]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.5 - patch 20240601
[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.90 2024/06/01 22:29:08 tom Exp $
32 .TH curs_addch 3X 2024-06-01 "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 .PP
306 Some implementations are problematic.
307 .bP
308 Solaris
309 .IR curses ,
310 for example,
311 defines the ACS symbols as constants;
312 others define them as elements of an array.
313 .IP
314 This implementation uses an array,
315 .BR \%acs_map ,
316 as did SVr4
317 .IR curses .
318 NetBSD also uses an array,
319 actually named
320 .BR \%_acs_char ,
321 with a
322 .B \%#define
323 for compatibility.
324 .bP
325 HP-UX
326 .I curses
327 equates some of the
328 .B \%ACS_
329 symbols to the analogous
330 .B \%WACS_
331 symbols as if the
332 .B \%ACS_
333 symbols were wide characters
334 (see \fB\%curs_add_wch\fP(3X)).
335 The misdefined symbols are the arrows and others that are not used for
336 line drawing.
337 .bP
338 X/Open Curses
339 (Issues 2 through 7)
340 has a typographical error
341 for the
342 .B \%ACS_LANTERN
343 symbol, equating its \*(``VT100+ Character\*('' to \*(``I\*(''
344 (capital I),
345 while the header files for SVr4
346 .I curses
347 and other implementations use \*(``i\*(''
348 (small i).
349 .IP
350 None of the terminal descriptions on Unix platforms use uppercase I,
351 except for Solaris
352 (in its
353 .I \%term\%info
354 entry for \fI\%screen\fP(1),
355 apparently based on the X/Open documentation around 1995).
356 On the other hand,
357 its
358 .B \%gs6300
359 (AT&T PC6300 with EMOTS Terminal Emulator)
360 description uses lowercase i.
361 .PP
362 Some ACS symbols
363 .RB \%( ACS_S3 ,
364 .BR \%ACS_S7 ,
365 .BR \%ACS_LEQUAL ,
366 .BR \%ACS_GEQUAL ,
367 .BR \%ACS_PI ,
368 .BR \%ACS_NEQUAL ,
369 and
370 .BR \%ACS_STERLING )
371 were not documented in any publicly released System\ V.
372 .\" And did not exist yet as late as SVr4.
373 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/\
374 .\"   sysvr4/svr4/lib/xlibcurses/screen/curses.ed
375 However,
376 many publicly available
377 .I \%term\%info
378 entries include
379 .B \%acsc
380 capabilities in which their key characters
381 .RB ( pryz{|} )
382 are embedded,
383 and a second-hand list of their character descriptions has come to
384 light.
385 The
386 .I \%ncurses
387 developers invented ACS-prefixed names for them.
388 .PP
389 The
390 .I displayed
391 values of
392 .B \%ACS_
393 constants depend on
394 .bP
395 the
396 .I \%ncurses
397 ABI\(emfor example,
398 wide-character versus non-wide-character configurations
399 (the former is capable of displaying Unicode while the latter is not),
400 and
401 .bP
402 whether the locale uses UTF-8 encoding.
403 .PP
404 In certain cases,
405 the terminal is unable to display forms-drawing characters
406 .I except
407 by using UTF-8;
408 see the discussion of the
409 .I \%NCURSES_NO_UTF8_ACS
410 environment variable in \fB\%ncurses\fP(3X).
411 .SS "Character Set"
412 X/Open Curses assumes that the parameter passed to
413 .B \%waddch
414 contains a single character.
415 That character may have been more than eight bits wide in an SVr3 or
416 SVr4 implementation,
417 but X/Open Curses leaves the width of a non-wide character code
418 unspecified.
419 The standard further does not specify the internal structure of a
420 .IR chtype ","
421 though the use of bit operations to combine the character code with
422 attributes and a color pair identifier into a
423 .I \%chtype
424 for passage to
425 .B \%waddch
426 is common.
427 A portable application uses only the macros discussed in
428 \fB\%curs_attr\fP(3X) to manipulate a
429 .IR \%chtype "."
430 .PP
431 In
432 .IR \%ncurses ,
433 .I \%chtype
434 holds an eight-bit character,
435 but the library allows a multibyte character sequence to be passed via a
436 succession of calls to
437 .BR \%waddch "."
438 Other implementations do not;
439 a
440 .B \%waddch
441 call transmits exactly one character,
442 which may be rendered in one or more screen locations depending on
443 whether it is printable
444 (see \fB\%unctrl\fP(3X)).
445 Depending on the locale,
446 .I \%ncurses
447 inspects the byte passed in each
448 .B \%waddch
449 call and checks whether the latest call continues a multibyte character.
450 When a character is
451 .IR complete ","
452 .I \%ncurses
453 displays the character and advances the cursor.
454 If the calling application interrupts the succession of bytes in
455 a multibyte character sequence by changing the current location\(emfor
456 example,
457 with \fB\%wmove\fP(3X)\(em\c
458 .I \%ncurses
459 discards the incomplete character.
460 .PP
461 For portability to other implementations,
462 do not rely upon the foregoing behavior.
463 Check whether a character can be represented as a single byte in the
464 current locale.
465 .bP
466 If it can,
467 call either
468 .B \%waddch
469 or \fB\%wadd_wch\fP(3X).
470 .bP
471 If it cannot,
472 use only
473 \fB\%wadd_wch\fP(3X).
474 .SH HISTORY
475 The original
476 .I curses
477 in 4BSD (1980) introduced
478 .IR \%waddch "."
479 .PP
480 SVr3 (1987)
481 added
482 .IR \%wechochar "."
483 .SH SEE ALSO
484 \fB\%curs_add_wch\fP(3X) describes comparable functions of the
485 .I \%ncurses
486 library in its wide-character configuration
487 .RI \%( ncursesw ).
488 .PP
489 \fB\%curses\fP(3X),
490 \fB\%curs_addchstr\fP(3X),
491 \fB\%curs_addstr\fP(3X),
492 \fB\%curs_attr\fP(3X),
493 \fB\%curs_clear\fP(3X),
494 \fB\%curs_inch\fP(3X),
495 \fB\%curs_outopts\fP(3X),
496 \fB\%curs_refresh\fP(3X),
497 \fB\%curs_variables\fP(3X),
498 \fB\%putchar\fP(3)