]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
ncurses 6.5 - patch 20240511
[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.86 2024/05/11 20:39:53 tom Exp $
32 .TH curs_addch 3X 2024-05-11 "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 .PP
185 .TS
186 Lb Lb Lb Lb
187 Lb Lb Lb Lb
188 Lb L  L  Lx.
189 \&      ACS     acsc    \&
190 Symbol  Default char    Glyph Name
191 _
192 ACS_BLOCK       #       0       solid square block
193 ACS_BOARD       #       h       board of squares
194 ACS_BTEE        +       v       bottom tee
195 ACS_BULLET      o       \*~     bullet
196 ACS_CKBOARD     :       a       checker board (stipple)
197 ACS_DARROW      v       .       arrow pointing down
198 ACS_DEGREE      \*'     f       degree symbol
199 ACS_DIAMOND     +       \(ga    diamond
200 ACS_GEQUAL      >       >       greater-than-or-equal-to
201 ACS_HLINE       \-      q       horizontal line
202 ACS_LANTERN     #       i       lantern symbol
203 ACS_LARROW      <       ,       arrow pointing left
204 ACS_LEQUAL      <       y       less-than-or-equal-to
205 ACS_LLCORNER    +       m       lower left-hand corner
206 ACS_LRCORNER    +       j       lower right-hand corner
207 ACS_LTEE        +       t       left tee
208 ACS_NEQUAL      !       |       not-equal
209 ACS_PI  *       {       greek pi
210 ACS_PLMINUS     #       g       plus/minus
211 ACS_PLUS        +       n       plus
212 ACS_RARROW      >       +       arrow pointing right
213 ACS_RTEE        +       u       right tee
214 ACS_S1  \-      o       scan line 1
215 ACS_S3  \-      p       scan line 3
216 ACS_S7  \-      r       scan line 7
217 ACS_S9  \&_     s       scan line 9
218 ACS_STERLING    f       }       pound-sterling symbol
219 ACS_TTEE        +       w       top tee
220 ACS_UARROW      \*^     \-      arrow pointing up
221 ACS_ULCORNER    +       l       upper left-hand corner
222 ACS_URCORNER    +       k       upper right-hand corner
223 ACS_VLINE       |       x       vertical line
224 .TE
225 .SH RETURN VALUE
226 These functions return
227 .B OK
228 on success and
229 .B ERR
230 on failure.
231 .PP
232 In
233 .IR \%ncurses ,
234 .B \%waddch
235 returns
236 .B ERR
237 if
238 .bP
239 .I win
240 is
241 .BR NULL ","
242 .bP
243 wrapping to a new line is impossible because \fB\%scrollok\fP(3X) has
244 not been called on
245 .I win
246 when a write to its bottom right location is attempted,
247 or
248 .bP
249 it is not possible to add a complete character at the cursor position.
250 .PP
251 The last may be due to different causes:
252 .bP
253 conversion of a multibyte character to a byte sequence can fail,
254 or
255 .bP
256 at least one of the bytes resulting from conversion from a multibyte
257 sequence cannot be added to the window.
258 See section \*(``PORTABILITY\*('' below regarding the use of
259 .B \%waddch
260 with multibyte characters.
261 .PP
262 Functions prefixed with \*(``mv\*('' first perform cursor movement and
263 fail if the position
264 .RI ( y ,
265 .IR x )
266 is outside the window boundaries.
267 .SH NOTES
268 .BR \%addch ","
269 .BR \%mvaddch ","
270 .BR \%mvwaddch ","
271 and
272 .B \%echochar
273 may be implemented as macros.
274 .SH EXTENSIONS
275 .SS TABSIZE
276 SVr4 and other versions of
277 .I curses
278 implement the
279 .B \%TABSIZE
280 variable,
281 but X/Open Curses does not specify it;
282 see \fB\%curs_variables\fP(3X).
283 .SH PORTABILITY
284 X/Open Curses,
285 Issue 4 describes these functions.
286 It specifies no error conditions for them.
287 .PP
288 SVr4
289 .I curses
290 describes a successful return value only as
291 \*(``an integer value other than
292 .BR ERR \*(''.
293 .PP
294 The defaults specified for forms-drawing characters apply in the POSIX
295 locale.
296 .SS "ACS Symbols"
297 X/Open Curses states that the
298 .B \%ACS_
299 definitions are
300 .I char
301 constants.
302 .PP
303 Some implementations are problematic.
304 .bP
305 Solaris
306 .IR curses ,
307 for example,
308 defines the ACS symbols as constants;
309 others define them as elements of an array.
310 .IP
311 This implementation uses an array,
312 .BR \%acs_map ,
313 as did SVr4
314 .IR curses .
315 NetBSD also uses an array,
316 actually named
317 .BR \%_acs_char ,
318 with a
319 .B \%#define
320 for compatibility.
321 .bP
322 HP-UX
323 .I curses
324 equates some of the
325 .B \%ACS_
326 symbols to the analogous
327 .B \%WACS_
328 symbols as if the
329 .B \%ACS_
330 symbols were wide characters
331 (see \fB\%curs_add_wch\fP(3X)).
332 The misdefined symbols are the arrows and others that are not used for
333 line drawing.
334 .bP
335 X/Open Curses
336 (Issues 2 through 7)
337 has a typographical error
338 for the
339 .B \%ACS_LANTERN
340 symbol, equating its \*(``VT100+ Character\*('' to \*(``I\*(''
341 (capital I),
342 while the header files for SVr4
343 .I curses
344 and other implementations use \*(``i\*(''
345 (small i).
346 .IP
347 None of the terminal descriptions on Unix platforms use uppercase I,
348 except for Solaris
349 (in its
350 .I \%term\%info
351 entry for \fI\%screen\fP(1),
352 apparently based on the X/Open documentation around 1995).
353 On the other hand,
354 its
355 .B \%gs6300
356 (AT&T PC6300 with EMOTS Terminal Emulator)
357 description uses lowercase i.
358 .PP
359 Some ACS symbols
360 .RB ( \%ACS_S3 ,
361 .BR \%ACS_S7 ,
362 .BR \%ACS_LEQUAL ,
363 .BR \%ACS_GEQUAL ,
364 .BR \%ACS_PI ,
365 .BR \%ACS_NEQUAL ,
366 and
367 .BR \%ACS_STERLING )
368 were not documented in any publicly released System\ V.
369 However,
370 many publicly available
371 .I \%term\%info
372 entries include
373 .B \%acsc
374 capabilities in which their key characters
375 .RB ( pryz{|} )
376 are embedded,
377 and a second-hand list of their character descriptions has come to
378 light.
379 The
380 .I \%ncurses
381 developers invented ACS-prefixed names for them.
382 .PP
383 The
384 .I displayed
385 values of
386 .B \%ACS_
387 constants depend on
388 .bP
389 the
390 .I \%ncurses
391 ABI\(emfor example,
392 wide-character versus non-wide-character configurations
393 (the former is capable of displaying Unicode while the latter is not),
394 and
395 .bP
396 whether the locale uses UTF-8 encoding.
397 .PP
398 In certain cases,
399 the terminal is unable to display forms-drawing characters
400 .I except
401 by using UTF-8;
402 see the discussion of the
403 .I \%NCURSES_NO_UTF8_ACS
404 environment variable in \fB\%ncurses\fP(3X).
405 .SS "Character Set"
406 X/Open Curses assumes that the parameter passed to
407 .B \%waddch
408 contains a single character.
409 That character may have been more than eight bits wide in an SVr3 or
410 SVr4 implementation,
411 but X/Open Curses leaves the width of a non-wide character code
412 unspecified.
413 The standard further does not specify the internal structure of a
414 .IR chtype ","
415 though the use of bit operations to combine the character code with
416 attributes and a color pair identifier into a
417 .I \%chtype
418 for passage to
419 .B \%waddch
420 is common.
421 A portable application uses only the macros discussed in
422 \fB\%curs_attr\fP(3X) to manipulate a
423 .IR \%chtype "."
424 .PP
425 In
426 .IR \%ncurses ,
427 .I \%chtype
428 holds an eight-bit character,
429 but the library allows a multibyte character to be passed in a
430 succession of calls to
431 .BR \%waddch "."
432 Other implementations do not;
433 a
434 .B \%waddch
435 call transmits exactly one character,
436 which may be rendered in one or more screen locations depending on
437 whether it is printable
438 (see \fB\%unctrl\fP(3X)).
439 Depending on the locale,
440 .I \%ncurses
441 inspects the byte passed in each
442 .B \%waddch
443 call and checks whether the latest call continues a multibyte sequence.
444 When a character is
445 .IR complete ","
446 .I \%ncurses
447 displays the character and advances the cursor.
448 If the calling application interrupts the succession of bytes in
449 a multibyte character sequence by changing the current location\(emfor
450 example,
451 with \fB\%wmove\fP(3X)\(em\c
452 .I \%ncurses
453 discards the incomplete character.
454 .PP
455 For portability to other implementations,
456 do not rely upon the foregoing behavior.
457 Check whether a character can be represented as a single byte in the
458 current locale.
459 .bP
460 If it can,
461 call either
462 .B \%waddch
463 or \fB\%wadd_wch\fP(3X).
464 .bP
465 If it cannot,
466 use only
467 \fB\%wadd_wch\fP(3X).
468 .SH SEE ALSO
469 \fB\%curs_add_wch\fP(3X) describes comparable functions of the
470 .I \%ncurses
471 library in its wide-character configuration
472 .RI ( \%ncursesw ).
473 .PP
474 \fB\%curses\fP(3X),
475 \fB\%curs_addchstr\fP(3X),
476 \fB\%curs_addstr\fP(3X),
477 \fB\%curs_attr\fP(3X),
478 \fB\%curs_clear\fP(3X),
479 \fB\%curs_inch\fP(3X),
480 \fB\%curs_outopts\fP(3X),
481 \fB\%curs_refresh\fP(3X),
482 \fB\%curs_variables\fP(3X),
483 \fB\%putchar\fP(3)