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