blob: d1eb9a311fc81ae718d564648c615a80b053b957 [file] [log] [blame]
micky3879b9f5e72025-07-08 18:04:53 -04001'\" t
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302.\"***************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04003.\" Copyright 2019-2023,2024 Thomas E. Dickey *
4.\" Copyright 2001-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_add_wch.3x,v 1.62 2024/04/20 21:20:07 tom Exp $
32.TH curs_add_wch 3X 2024-04-20 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
33.ie \n(.g \{\
34.ds `` \(lq
35.ds '' \(rq
36.\}
37.el \{\
38.ie t .ds `` ``
39.el .ds `` ""
40.ie t .ds '' ''
41.el .ds '' ""
42.\}
43.
Steve Kondikae271bc2015-11-15 02:50:53 +010044.de bP
micky3879b9f5e72025-07-08 18:04:53 -040045.ie n .IP \(bu 4
46.el .IP \(bu 2
Steve Kondikae271bc2015-11-15 02:50:53 +010047..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053048.SH NAME
micky3879b9f5e72025-07-08 18:04:53 -040049\fB\%add_wch\fP,
50\fB\%wadd_wch\fP,
51\fB\%mvadd_wch\fP,
52\fB\%mvwadd_wch\fP,
53\fB\%echo_wchar\fP,
54\fB\%wecho_wchar\fP \-
55add a \fIcurses\fR complex character to a window and advance the cursor
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056.SH SYNOPSIS
micky3879b9f5e72025-07-08 18:04:53 -040057.nf
58\fB#include <curses.h>
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053059.PP
micky3879b9f5e72025-07-08 18:04:53 -040060\fBint add_wch(const cchar_t *\fIwch\fP);
61\fBint wadd_wch(WINDOW *\fIwin\fP, const cchar_t *\fIwch\fP);
62\fBint mvadd_wch(int \fIy\fP, int \fIx\fP, const cchar_t *\fIwch\fP);
63\fBint mvwadd_wch(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, const cchar_t *\fIwch\fP);
64.PP
65\fBint echo_wchar(const cchar_t *\fIwch\fP);
66\fBint wecho_wchar(WINDOW *\fIwin\fP, const cchar_t *\fIwch\fP);
67.fi
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053068.SH DESCRIPTION
Steve Kondikae271bc2015-11-15 02:50:53 +010069.SS add_wch
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053070The
71\fBadd_wch\fP,
72\fBwadd_wch\fP,
73\fBmvadd_wch\fP, and
74\fBmvwadd_wch\fP
75functions put the complex character \fIwch\fP into the given
76window at its current position,
77which is then advanced.
78These functions perform
79wrapping and special-character processing as follows:
Steve Kondikae271bc2015-11-15 02:50:53 +010080.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053081If \fIwch\fP refers to a spacing character,
82then any previous character at that location is removed.
83A new character specified by \fIwch\fP is
84placed at that location with rendition specified by \fIwch\fP.
micky3879b9f5e72025-07-08 18:04:53 -040085The cursor then advances after this spacing character,
86to prepare for writing the next character on the screen.
87.IP
88The newly added spacing character is the base of the active complex character.
89Subsequent non-spacing characters can be combined with this base
90until another spacing character is written to the screen,
91or the cursor is moved, e.g., using \fBwmove\fP.
Steve Kondikae271bc2015-11-15 02:50:53 +010092.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053093If \fIwch\fP refers to a non-spacing character,
micky3879b9f5e72025-07-08 18:04:53 -040094it is appended to the active complex character,
95retaining the previous characters at that location.
96The rendition specified by \fIwch\fP is ignored.
97.IP
98The cursor is not advanced after adding a non-spacing character.
99Subsequent calls to add non-spacing characters will update the same position.
Steve Kondikae271bc2015-11-15 02:50:53 +0100100.bP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530101If the character part of \fIwch\fP is
102a tab, newline, backspace or other control character,
micky3879b9f5e72025-07-08 18:04:53 -0400103the window is updated and the cursor moves as if \fBaddch\fP were called.
Steve Kondikae271bc2015-11-15 02:50:53 +0100104.SS echo_wchar
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530105The \fBecho_wchar\fP
106function is functionally equivalent to a call to
107\fBadd_wch\fP
108followed by a call to
micky3879b9f5e72025-07-08 18:04:53 -0400109\fB\%refresh\fP(3X).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530110Similarly, the
111\fBwecho_wchar\fP
112is functionally equivalent to a call to
113\fBwadd_wch\fP
114followed by a call to
115\fBwrefresh\fP.
116The knowledge
117that only a single character is being output is taken into consideration and,
118for non-control characters, a considerable performance gain might be seen
119by using the *\fBecho\fP* functions instead of their equivalents.
micky3879b9f5e72025-07-08 18:04:53 -0400120.SS "Line Graphics"
121Like \fB\%addch\fP(3X),
Steve Kondikae271bc2015-11-15 02:50:53 +0100122\fBaddch_wch\fP accepts symbols which make it simple to draw lines and other
123frequently used special characters.
124These symbols correspond to the same VT100 line-drawing set as
micky3879b9f5e72025-07-08 18:04:53 -0400125\fB\%addch\fP(3X).
Steve Kondikae271bc2015-11-15 02:50:53 +0100126.PP
127.TS
micky3879b9f5e72025-07-08 18:04:53 -0400128Lb Lb Lb Lb Lb
129Lb Lb Lb Lb Lb
130Lb L L L Lx.
131\& Unicode ASCII acsc \&
132ACS Name Default Default Char Glyph Name
133_
134WACS_BLOCK 0x25ae # 0 T{
135solid square block
136T}
137WACS_BOARD 0x2592 # h board of squares
138WACS_BTEE 0x2534 + v bottom tee
139WACS_BULLET 0x00b7 o ~ bullet
140WACS_CKBOARD 0x2592 : a T{
141checker board (stipple)
142T}
143WACS_DARROW 0x2193 v . T{
144arrow pointing down
145T}
146WACS_DEGREE 0x00b0 ' f degree symbol
147WACS_DIAMOND 0x25c6 + \(ga diamond
148WACS_GEQUAL 0x2265 > > T{
149greater-than-or-equal-to
150T}
151WACS_HLINE 0x2500 \- q horizontal line
152WACS_LANTERN 0x2603 # i lantern symbol
153WACS_LARROW 0x2190 < , T{
154arrow pointing left
155T}
156WACS_LEQUAL 0x2264 < y T{
157less-than-or-equal-to
158T}
159WACS_LLCORNER 0x2514 + m T{
160lower left-hand corner
161T}
162WACS_LRCORNER 0x2518 + j T{
163lower right-hand corner
164T}
165WACS_LTEE 0x2524 + t left tee
166WACS_NEQUAL 0x2260 ! | not-equal
167WACS_PI 0x03c0 * { greek pi
168WACS_PLMINUS 0x00b1 # g plus/minus
169WACS_PLUS 0x253c + n plus
170WACS_RARROW 0x2192 > + T{
171arrow pointing right
172T}
173WACS_RTEE 0x251c + u right tee
174WACS_S1 0x23ba \- o scan line 1
175WACS_S3 0x23bb \- p scan line 3
176WACS_S7 0x23bc \- r scan line 7
177WACS_S9 0x23bd \&_ s scan line 9
178WACS_STERLING 0x00a3 f } T{
179pound-sterling symbol
180T}
181WACS_TTEE 0x252c + w top tee
182WACS_UARROW 0x2191 ^ \- T{
183arrow pointing up
184T}
185WACS_ULCORNER 0x250c + l T{
186upper left-hand corner
187T}
188WACS_URCORNER 0x2510 + k T{
189upper right-hand corner
190T}
191WACS_VLINE 0x2502 | x vertical line
Steve Kondikae271bc2015-11-15 02:50:53 +0100192.TE
193.PP
micky3879b9f5e72025-07-08 18:04:53 -0400194The wide-character configuration of \fI\%ncurses\fP also defines symbols
195for thick lines (\fBacsc\fP \*(``J\*('' to \*(``V\*(''):
Steve Kondikae271bc2015-11-15 02:50:53 +0100196.PP
197.TS
micky3879b9f5e72025-07-08 18:04:53 -0400198Lb Lb Lb Lb Lb
199Lb Lb Lb Lb Lb
200Lb L L L Lx.
201\& Unicode ASCII acsc \&
202ACS Name Default Default Char Glyph Name
203_
204WACS_T_BTEE 0x253b + V T{
205thick tee pointing up
206T}
207WACS_T_HLINE 0x2501 - Q T{
208thick horizontal line
209T}
210WACS_T_LLCORNER 0x2517 + M T{
211thick lower left corner
212T}
213WACS_T_LRCORNER 0x251b + J T{
214thick lower right corner
215T}
216WACS_T_LTEE 0x252b + T T{
217thick tee pointing right
218T}
219WACS_T_PLUS 0x254b + N T{
220thick large plus
221T}
222WACS_T_RTEE 0x2523 + U T{
223thick tee pointing left
224T}
225WACS_T_TTEE 0x2533 + W T{
226thick tee pointing down
227T}
228WACS_T_ULCORNER 0x250f + L T{
229thick upper left corner
230T}
231WACS_T_URCORNER 0x2513 + K T{
232thick upper right corner
233T}
234WACS_T_VLINE 0x2503 | X T{
235thick vertical line
236T}
Steve Kondikae271bc2015-11-15 02:50:53 +0100237.TE
micky3879b9f5e72025-07-08 18:04:53 -0400238.PP
239and for double-lines (\fBacsc\fP \*(``A\*('' to \*(``I\*(''):
240.PP
241.TS
242Lb Lb Lb Lb Lb
243Lb Lb Lb Lb Lb
244Lb L L L Lx.
245\& Unicode ASCII acsc \&
246ACS Name Default Default Char Glyph Name
247_
248WACS_D_BTEE 0x2569 + H T{
249double tee pointing up
250T}
251WACS_D_HLINE 0x2550 - R T{
252double horizontal line
253T}
254WACS_D_LLCORNER 0x255a + D T{
255double lower left corner
256T}
257WACS_D_LRCORNER 0x255d + A T{
258double lower right corner
259T}
260WACS_D_LTEE 0x2560 + F T{
261double tee pointing right
262T}
263WACS_D_PLUS 0x256c + E T{
264double large plus
265T}
266WACS_D_RTEE 0x2563 + G T{
267double tee pointing left
268T}
269WACS_D_TTEE 0x2566 + I T{
270double tee pointing down
271T}
272WACS_D_ULCORNER 0x2554 + C T{
273double upper left corner
274T}
275WACS_D_URCORNER 0x2557 + B T{
276double upper right corner
277T}
278WACS_D_VLINE 0x2551 | Y T{
279double vertical line
280T}
281.TE
282.PP
283Unicode's descriptions for these characters differs slightly from
284\fI\%ncurses\fP,
285by introducing the term \*(``light\*('' (along with less important details).
286Here are its descriptions for the normal, thick, and double horizontal lines:
287.bP
288U+2500 BOX DRAWINGS LIGHT HORIZONTAL
289.bP
290U+2501 BOX DRAWINGS HEAVY HORIZONTAL
291.bP
292U+2550 BOX DRAWINGS DOUBLE HORIZONTAL
Steve Kondikae271bc2015-11-15 02:50:53 +0100293.SH RETURN VALUE
micky3879b9f5e72025-07-08 18:04:53 -0400294All routines return the integer \fBERR\fP upon failure and \fBOK\fP on success.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530295.PP
micky3879b9f5e72025-07-08 18:04:53 -0400296X/Open Curses does not specify any error conditions.
297This implementation returns an error
298.bP
299if the window pointer is null or
300.bP
301if it is not possible to add a complete character in the window.
Steve Kondikae271bc2015-11-15 02:50:53 +0100302.PP
micky3879b9f5e72025-07-08 18:04:53 -0400303The latter may be due to different causes:
304.bP
305If \fB\%scrollok\fP(3X) is not enabled,
306writing a character at the lower right margin succeeds.
307However,
308an error is returned because it is not possible to wrap to a new line.
309.bP
310If an error is detected when converting a multibyte character to a sequence
311of bytes,
312or if it is not possible to add all of the resulting bytes in the window,
313an error is returned.
314.PP
315Functions prefixed with \*(``mv\*('' first perform cursor movement and
316fail if the position
317.RI ( y ,
318.IR x )
319is outside the window boundaries.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530320.SH NOTES
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530321Note that
322\fBadd_wch\fP,
323\fBmvadd_wch\fP,
324\fBmvwadd_wch\fP, and
325\fBecho_wchar\fP
326may be macros.
327.SH PORTABILITY
micky3879b9f5e72025-07-08 18:04:53 -0400328These functions are described in X/Open Curses, Issue 4.
Steve Kondikae271bc2015-11-15 02:50:53 +0100329The defaults specified for line-drawing characters apply in the POSIX locale.
micky3879b9f5e72025-07-08 18:04:53 -0400330.SS "WACS Symbols"
Steve Kondikae271bc2015-11-15 02:50:53 +0100331X/Open Curses makes it clear that the WACS_ symbols should be defined as
micky3879b9f5e72025-07-08 18:04:53 -0400332a pointer to \fBcchar_t\fP data, e.g., in the discussion of \fBborder_set\fP.
Steve Kondikae271bc2015-11-15 02:50:53 +0100333A few implementations are problematic:
334.bP
335NetBSD curses defines the symbols as a \fBwchar_t\fP within a \fBcchar_t\fP.
336.bP
micky3879b9f5e72025-07-08 18:04:53 -0400337HP-UX curses equates some of the \fBACS_\fP symbols
338to the analogous \fBWACS_\fP symbols as if the \fBACS_\fP symbols were
Steve Kondikae271bc2015-11-15 02:50:53 +0100339wide characters.
340The misdefined symbols are the arrows
341and other symbols which are not used for line-drawing.
342.PP
micky3879b9f5e72025-07-08 18:04:53 -0400343X/Open Curses does not specify symbols for thick- or double-lines.
Steve Kondikae271bc2015-11-15 02:50:53 +0100344SVr4 curses implementations defined their line-drawing symbols in
345terms of intermediate symbols.
346This implementation extends those symbols, providing new definitions
347which are not in the SVr4 implementations.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530348.PP
micky3879b9f5e72025-07-08 18:04:53 -0400349Not all Unicode-capable terminals provide support for VT100-style
350alternate character sets (i.e., the \fBacsc\fP capability),
351with their corresponding line-drawing characters.
352X/Open Curses did not address the aspect of integrating Unicode with
353line-drawing characters.
354Existing implementations of Unix curses (AIX, HP-UX, Solaris)
355use only the \fBacsc\fP character-mapping to provide this feature.
356As a result, those implementations can only use single-byte line-drawing
357characters.
358\fI\%ncurses\fP 5.3 (2002) provided a table of Unicode values to solve
359these problems.
360NetBSD curses incorporated that table in 2010.
361.PP
362In this implementation, the Unicode values are used instead of the
363terminal description's \fBacsc\fP mapping as discussed in
364\fB\%ncurses\fP(3X) for the environment variable
365\fINCURSES_NO_UTF8_ACS\fP.
366In contrast, for the same cases, the line-drawing characters
367described in \fB\%addch\fP(3X) will use only the ASCII default values.
368.PP
369Having Unicode available does not solve all of the problems with
370line-drawing for curses:
371.bP
372The closest Unicode equivalents to the
373VT100 graphics \fIS1\fP, \fIS3\fP, \fIS7\fP and \fIS9\fP
374frequently are not displayed at
375the regular intervals which the terminal used.
376.bP
377The \fIlantern\fP is a special case.
378It originated with the AT&T 4410 terminal in the early 1980s.
379There is no accessible documentation depicting the lantern symbol
380on the AT&T terminal.
381.IP
382Lacking documentation, most readers assume that a \fIstorm lantern\fP
383was intended.
384But there are several possibilities, all with problems.
385.IP
386Unicode 6.0 (2010) does provide two lantern symbols: U+1F383 and U+1F3EE.
387Those were not available in 2002, and are irrelevant since
388they lie outside the BMP and as a result are not generally available
389in terminals.
390They are not storm lanterns, in any case.
391.IP
392Most \fIstorm lanterns\fP have a tapering glass chimney
393(to guard against tipping);
394some have a wire grid protecting the chimney.
395.IP
396For the tapering appearance, \[u2603] U+2603 was adequate.
397In use on a terminal, no one can tell what the image represents.
398Unicode calls it a snowman.
399.IP
400Others have suggested these alternatives:
401\[sc] U+00A7 (section mark),
402\[u0398] U+0398 (theta),
403\[u03A6] U+03A6 (phi),
404\[u03B4] U+03B4 (delta),
405\[u2327] U+2327 (x in a rectangle),
406\[u256C] U+256C (forms double vertical and horizontal), and
407\[u2612] U+2612 (ballot box with x).
408.SS "Complex Characters"
409The complex character type \fBcchar_t\fR
410can store more than one wide character (\fBwchar_t\fR).
411The X/Open Curses description does not mention this possibility,
412describing only the cases where \fIwch\fP is a spacing character
413or a non-spacing character.
414.PP
415This implementation assumes that \fIwch\fP is constructed using
416\fB\%setcchar\fP(3X), and in turn that the result
417.bP
418contains at most one spacing character in the beginning of its list of wide
419characters,
420and zero or more non-spacing characters
421or
422.bP
423may hold one non-spacing character.
424.PP
425In the latter case,
426\fI\%ncurses\fP adds the non-spacing character to the active
427(base) spacing character.
428.SS TABSIZE
429The
430.B TABSIZE
431variable is implemented in SVr4 and other versions of
432.IR curses ,
433but is not specified by X/Open Curses
434(see \fBcurs_variables\fP(3X)).
435.SH SEE ALSO
436\fB\%curs_addch\fP(3X) describes comparable functions of the
437.I \%ncurses
438library in its non-wide-character configuration.
439.PP
440\fB\%curses\fP(3X),
441\fB\%curs_addwstr\fP(3X),
442\fB\%curs_add_wchstr\fP(3X),
443\fB\%curs_attr\fP(3X),
444\fB\%curs_clear\fP(3X),
445\fB\%curs_getcchar\fP(3X),
446\fB\%curs_outopts\fP(3X),
447\fB\%curs_refresh\fP(3X),
448\fB\%curs_variables\fP(3X),
449\fB\%putwc\fP(3)