]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_addch.3x
729382d49fcce828c3014db21c49bcd9587cc6fd
[ncurses.git] / man / curs_addch.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_addch.3x,v 1.47 2019/02/16 23:50:17 tom Exp $
31 .TH curs_addch 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .SH NAME
41 \fBaddch\fR,
42 \fBwaddch\fR,
43 \fBmvaddch\fR,
44 \fBmvwaddch\fR,
45 \fBechochar\fR,
46 \fBwechochar\fR \- add a character (with attributes) to a \fBcurses\fR window, then advance the cursor
47 .SH SYNOPSIS
48 \fB#include <curses.h>\fR
49 .PP
50 \fBint addch(const chtype ch);\fR
51 .br
52 \fBint waddch(WINDOW *win, const chtype ch);\fR
53 .br
54 \fBint mvaddch(int y, int x, const chtype ch);\fR
55 .br
56 \fBint mvwaddch(WINDOW *win, int y, int x, const chtype ch);\fR
57 .br
58 \fBint echochar(const chtype ch);\fR
59 .br
60 \fBint wechochar(WINDOW *win, const chtype ch);\fR
61 .br
62 .SH DESCRIPTION
63 .SS Adding characters
64 The \fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR and \fBmvwaddch\fR routines put
65 the character \fIch\fR into the given window at its current window position,
66 which is then advanced.
67 They are analogous to \fBputchar\fR(3) in \fBstdio\fR(3).
68 If the advance is at the right margin:
69 .bP
70 The cursor automatically wraps to the beginning of the next line.
71 .bP
72 At the bottom of the current scrolling region,
73 and if \fBscrollok\fR is enabled,
74 the scrolling region is scrolled up one line.
75 .bP
76 If \fBscrollok\fR is not enabled,
77 writing a character at the lower right margin succeeds.
78 However, an error is returned because
79 it is not possible to wrap to a new line
80 .PP
81 If \fIch\fR is a tab, newline, carriage return or backspace,
82 the cursor is moved appropriately within the window:
83 .bP
84 Backspace moves the cursor one character left; at the left
85 edge of a window it does nothing.
86 .bP
87 Carriage return moves the cursor to the window left margin on the current line.
88 .bP
89 Newline does a \fBclrtoeol\fR,
90 then moves the cursor to the window left margin on the next line,
91 scrolling the window if on the last line.
92 .bP
93 Tabs are considered to be at every eighth column.
94 The tab interval may be altered by setting the \fBTABSIZE\fR variable.
95 .PP
96 If \fIch\fR is any other control character, it
97 is drawn in \fB^\fR\fIX\fR notation.
98 Calling \fBwinch\fR after adding a
99 control character does not return the character itself, but instead returns
100 the ^-representation of the control character.
101 .PP
102 Video attributes can be combined with a character argument passed to
103 \fBaddch\fR or related functions by logical-ORing them into the character.
104 (Thus, text, including attributes, can be copied from one place to another
105 using \fBinch\fR(3X) and \fBaddch\fR.)  See the \fBcurs_attr\fR(3X) page for
106 values of predefined video attribute constants that can be usefully OR'ed
107 into characters.
108 .SS Echoing characters
109 .PP
110 The \fBechochar\fR and \fBwechochar\fR routines are equivalent to a call to
111 \fBaddch\fR followed by a call to \fBrefresh\fR(3X), or a call to \fBwaddch\fR
112 followed by a call to \fBwrefresh\fR.
113 The knowledge that only a single
114 character is being output is used and, for non-control characters, a
115 considerable performance gain may be seen by using these routines instead of
116 their equivalents.
117 .SS Line Graphics
118 The following variables may be used to add line drawing characters to the
119 screen with routines of the \fBaddch\fR family.
120 The default character listed
121 below is used if the \fBacsc\fR capability does not define a terminal-specific
122 replacement for it,
123 or if the terminal and locale configuration requires Unicode but the
124 library is unable to use Unicode.
125 .PP
126 The names are taken from VT100 nomenclature.
127 .PP
128 .TS
129 l l l l
130 l l l l
131 _ _ _ _
132 l l l l.
133 \fBACS\fR       \fBACS\fR       \fBacsc\fP      \fBGlyph\fR
134 \fBName\fR      \fBDefault\fR   \fBchar\fP      \fBName\fR
135 ACS_BLOCK       #       0       solid square block
136 ACS_BOARD       #       h       board of squares
137 ACS_BTEE        +       v       bottom tee
138 ACS_BULLET      o       ~       bullet
139 ACS_CKBOARD     :       a       checker board (stipple)
140 ACS_DARROW      v       .       arrow pointing down
141 ACS_DEGREE      '       f       degree symbol
142 ACS_DIAMOND     +       `       diamond
143 ACS_GEQUAL      >       >       greater-than-or-equal-to
144 ACS_HLINE       \-      q       horizontal line
145 ACS_LANTERN     #       i       lantern symbol
146 ACS_LARROW      <       ,       arrow pointing left
147 ACS_LEQUAL      <       y       less-than-or-equal-to
148 ACS_LLCORNER    +       m       lower left-hand corner
149 ACS_LRCORNER    +       j       lower right-hand corner
150 ACS_LTEE        +       t       left tee
151 ACS_NEQUAL      !       |       not-equal
152 ACS_PI  *       {       greek pi
153 ACS_PLMINUS     #       g       plus/minus
154 ACS_PLUS        +       n       plus
155 ACS_RARROW      >       +       arrow pointing right
156 ACS_RTEE        +       u       right tee
157 ACS_S1  \-      o       scan line 1
158 ACS_S3  \-      p       scan line 3
159 ACS_S7  \-      r       scan line 7
160 ACS_S9  \&_     s       scan line 9
161 ACS_STERLING    f       }       pound-sterling symbol
162 ACS_TTEE        +       w       top tee
163 ACS_UARROW      ^       \-      arrow pointing up
164 ACS_ULCORNER    +       l       upper left-hand corner
165 ACS_URCORNER    +       k       upper right-hand corner
166 ACS_VLINE       |       x       vertical line
167 .TE
168 .SH RETURN VALUE
169 All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success
170 (the SVr4 manuals specify only
171 \*(``an integer value other than \fBERR\fR\*('') upon successful completion,
172 unless otherwise noted in the preceding routine descriptions.
173 .PP
174 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
175 \fBwmove\fP, and return an error if the position is outside the window,
176 or if the window pointer is null.
177 .SH NOTES
178 Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and
179 \fBechochar\fR may be macros.
180 .SH PORTABILITY
181 All these functions are described in the XSI Curses standard, Issue 4.
182 The defaults specified for forms-drawing characters apply in the POSIX locale.
183 .SS ACS Symbols
184 .LP
185 X/Open Curses states that the \fIACS_\fP definitions are \fBchar\fP constants.
186 For the wide-character implementation (see \fBcurs_add_wch\fP),
187 there are analogous \fIWACS_\fP definitions which are \fBcchar_t\fP constants.
188 .LP
189 Some ACS symbols
190 (ACS_S3,
191 ACS_S7,
192 ACS_LEQUAL,
193 ACS_GEQUAL,
194 ACS_PI,
195 ACS_NEQUAL,
196 ACS_STERLING)
197 were not documented in
198 any publicly released System V.
199 However, many publicly available terminfos
200 include \fBacsc\fR strings in which their key characters (pryz{|}) are
201 embedded, and a second-hand list of their character descriptions has come
202 to light.
203 The ACS-prefixed names for them were invented for \fBncurses\fR(3X).
204 .LP
205 The \fIdisplayed\fP values for the \fIACS_\fP and \fIWACS_\fP constants
206 depend on 
207 .bP
208 the library configuration, i.e., \fBncurses\fP versus \fBncursesw\fP,
209 where the latter is capable of displaying Unicode while the former is not, and
210 .bP
211 whether the \fIlocale\fP uses UTF-8 encoding.
212 .LP
213 In certain cases, the terminal is unable to display line-drawing characters
214 except by using UTF-8 (see the discussion of \fBNCURSES_NO_UTF8_ACS\fP in
215 ncurses(3X)).
216 .SS Character Set
217 X/Open Curses assumes that the parameter passed to \fBwaddch\fP contains
218 a single character.
219 As discussed in \fBcurs_attr\fP(3X), that character may have been
220 more than eight bits in an SVr3 or SVr4 implementation,
221 but in the X/Open Curses model, the details are not given.
222 The important distinction between SVr4 curses and X/Open Curses is
223 that the non-character information (attributes and color) was
224 separated from the character information which is packed in a \fBchtype\fP
225 to pass to \fBwaddch\fP.
226 .PP
227 In this implementation, \fBchtype\fP holds eight bits.
228 But ncurses allows multibyte characters to be passed in a succession
229 of calls to \fBwaddch\fP.
230 The other implementations do not do this;
231 a call to \fBwaddch\fP passes exactly one character
232 which may be rendered as one or more cells on the screen
233 depending on whether it is printable.
234 .PP
235 Depending on the locale settings,
236 ncurses will inspect the byte passed in each call to \fBwaddch\fP,
237 and check if the latest call will continue a multibyte sequence.
238 When a character is \fIcomplete\fP,
239 ncurses displays the character and moves to the next position in the screen.
240 .PP
241 If the calling application interrupts the succession of bytes in
242 a multibyte character by moving the current location (e.g., using \fBwmove\fP),
243 ncurses discards the partially built character,
244 starting over again.
245 .PP
246 For portability to other implementations,
247 do not rely upon this behavior:
248 .bP
249 check if a character can be represented as a single byte in the current locale
250 before attempting call \fBwaddch\fP, and
251 .bP
252 call \fBwadd_wch\fP for characters which cannot be handled by \fBwaddch\fP.
253 .SS TABSIZE
254 .LP
255 The \fBTABSIZE\fR variable is implemented in SVr4 and other versions of curses,
256 but is not part of X/Open curses
257 (see \fBcurs_variables\fR(3X) for more details).
258 .LP
259 If \fIch\fR is a carriage return,
260 the cursor is moved to the beginning of the current row of the window.
261 This is true of other implementations, but is not documented.
262 .SH SEE ALSO
263 \fBcurses\fR(3X),
264 \fBcurs_attr\fR(3X),
265 \fBcurs_clear\fR(3X),
266 \fBcurs_inch\fR(3X),
267 \fBcurs_outopts\fR(3X),
268 \fBcurs_refresh\fR(3X),
269 \fBcurs_variables\fR(3X),
270 \fBputc\fR(3).
271 .PP
272 Comparable functions in the wide-character (ncursesw) library are
273 described in
274 \fBcurs_add_wch\fR(3X).