]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_inopts.3x
4f4c25549c8ae0e80718bb700a4e464846cdf4f8
[ncurses.git] / man / curs_inopts.3x
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2023,2024 Thomas E. Dickey                                *
4 .\" Copyright 1998-2016,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_inopts.3x,v 1.70 2024/06/01 22:28:41 tom Exp $
32 .TH curs_inopts 3X 2024-06-01 "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 .
44 .de bP
45 .ie n  .IP \(bu 4
46 .el    .IP \(bu 2
47 ..
48 .SH NAME
49 \fB\%cbreak\fP,
50 \fB\%echo\fP,
51 \fB\%halfdelay\fP,
52 \fB\%intrflush\fP,
53 \fB\%is_cbreak\fP,
54 \fB\%is_echo\fP,
55 \fB\%is_nl\fP,
56 \fB\%is_raw\fP,
57 \fB\%keypad\fP,
58 \fB\%meta\fP,
59 \fB\%nl\fP,
60 \fB\%nocbreak\fP,
61 \fB\%nodelay\fP,
62 \fB\%noecho\fP,
63 \fB\%nonl\fP,
64 \fB\%noqiflush\fP,
65 \fB\%noraw\fP,
66 \fB\%notimeout\fP,
67 \fB\%qiflush\fP,
68 \fB\%raw\fP,
69 \fB\%timeout\fP,
70 \fB\%wtimeout\fP,
71 \fB\%typeahead\fP \-
72 get and set \fIcurses\fR terminal input options
73 .SH SYNOPSIS
74 .nf
75 \fB#include <curses.h>
76 .PP
77 \fBint cbreak(void);
78 \fBint nocbreak(void);
79 .PP
80 \fBint echo(void);
81 \fBint noecho(void);
82 .PP
83 \fBint intrflush(WINDOW * \fIwin\fP \fI/* ignored */\fP, bool \fIbf\fP);
84 \fBint keypad(WINDOW * \fIwin\fP, bool \fIbf\fP);
85 \fBint meta(WINDOW * \fIwin\fP \fI/* ignored */\fP, bool \fIbf\fP);
86 \fBint nodelay(WINDOW * \fIwin\fP, bool \fIbf\fP);
87 \fBint notimeout(WINDOW * \fIwin\fP, bool \fIbf\fP);
88 .PP
89 \fBint nl(void);
90 \fBint nonl(void);
91 .PP
92 \fBvoid qiflush(void);
93 \fBvoid noqiflush(void);
94 .PP
95 \fBint raw(void);
96 \fBint noraw(void);
97 .PP
98 \fBint halfdelay(int \fItenths\fP);
99 \fBvoid timeout(int \fIdelay\fP);
100 \fBvoid wtimeout(WINDOW * \fIwin\fP, int \fIdelay\fP);
101 .PP
102 \fBint typeahead(int \fIfd\fP);
103 .PP
104 \fI/* extensions */
105 \fBint is_cbreak(void);
106 \fBint is_echo(void);
107 \fBint is_nl(void);
108 \fBint is_raw(void);
109 .fi
110 .SH DESCRIPTION
111 .I curses
112 offers configurable parameters permitting an application to control the
113 handling of input from the terminal.
114 Some are global,
115 applying to all windows;
116 others apply only to a specific window.
117 The library does not automatically apply such parameters to new or
118 derived windows;
119 an application must configure each window for the desired behavior.
120 .PP
121 Some descriptions below make reference to an
122 .IR "input character reading function" ":"
123 this is \fB\%wgetch\fP(3X) in the non-wide character
124 .I curses
125 API and \fB\%wget_wch\fP(3X) in the wide character API.
126 In addition to the variant forms of these described in
127 \fB\%ncurses\fP(3X),
128 the
129 .I curses
130 functions \fB\%wgetstr\fP(3X) and \fB\%wget_wstr\fP(3X) and their own
131 variants call the appropriate input character reading function.
132 .\"
133 .SS "cbreak, nocbreak"
134 Normally,
135 the terminal driver buffers typed characters,
136 not delivering them to an application
137 until a line feed or carriage return is typed.
138 .B \%cbreak
139 configures the terminal in
140 .IR "cbreak mode" ","
141 which disables line buffering
142 and erase and kill character processing
143 (the interrupt,
144 quit,
145 suspend,
146 and flow control characters are unaffected)
147 and makes characters typed by the user immediately available to the
148 program.
149 .B \%nocbreak
150 returns the terminal to normal (\*(``cooked\*('') mode.
151 .PP
152 The state of the terminal is unknown to a
153 .I curses
154 application when it starts;
155 therefore,
156 a program should call
157 .B \%cbreak
158 or
159 .B \%nocbreak
160 explicitly.
161 Most interactive programs using
162 .I curses
163 set \%cbreak
164 mode.
165 Calling
166 .B \%cbreak
167 overrides
168 .BR raw "."
169 The man page for the input character reading function
170 discusses how
171 .B \%cbreak
172 and
173 .B \%nocbreak
174 interact with
175 .B echo
176 and
177 .BR \%noecho "."
178 .\"
179 .SS "echo, noecho"
180 .B echo
181 and
182 .B \%noecho
183 determine whether characters typed by the user are written to the
184 .I curses
185 window by the input character reading function as they are typed.
186 .I curses
187 always disables the terminal driver's own echoing.
188 By default,
189 a
190 .I curses
191 window has its echo flag set.
192 Authors of most interactive programs prefer
193 to do their own echoing in a controlled area of the screen,
194 or not to echo at all,
195 so they call
196 .BR \%noecho "."
197 The man page for the input character reading function
198 discusses how
199 .B echo
200 and
201 .B \%noecho
202 interact with
203 .B \%cbreak
204 and
205 .BR \%nocbreak "."
206 .\"
207 .SS halfdelay
208 .B \%halfdelay
209 configures
210 .IR "half-delay mode" ","
211 which is similar to \%cbreak mode in that characters typed by the user
212 are immediately available to the program.
213 However,
214 after blocking for
215 .I tenths
216 tenths of seconds,
217 an input character reading function returns
218 .B ERR
219 if no input is pending.
220 The value of
221 .I tenths
222 must be between 1 and 255.
223 Use
224 .B \%nocbreak
225 to leave half-delay mode.
226 .\"
227 .SS intrflush
228 .B \%intrflush
229 calls
230 .B \%qiflush
231 (see below)
232 if
233 .I bf
234 is
235 .BR TRUE ","
236 and
237 .B \%noqiflush
238 if
239 .I bf
240 is
241 .BR FALSE "."
242 It ignores its
243 .I win
244 argument.
245 .\"
246 .SS keypad
247 .B keypad
248 enables recognition of a terminal's function keys.
249 If
250 enabled
251 .RI ( bf
252 is
253 .BR TRUE ),
254 the input character reading function returns a value representing
255 the function key,
256 such as
257 .BR KEY_LEFT "."
258 (Wide-character API users:
259 \fB\%wget_wch\fP(3X) returns
260 .B \%KEY_CODE_YES
261 to indicate the availability of a function key code in its
262 .I wch
263 parameter.)
264 If disabled
265 .RI ( bf
266 is
267 .BR FALSE ),
268 .I curses
269 does not treat function keys specially and the program has to interpret
270 escape sequences itself.
271 If the terminal's keypad can be turned on
272 (made to transmit)
273 and off
274 (made to work locally),
275 .B \%keypad
276 configures it consistently with the
277 .I bf
278 parameter.
279 By default,
280 a window's keypad mode is off.
281 .\"
282 .SS meta
283 Initially,
284 whether the terminal returns 7- or 8-bit character codes on input
285 depends on the configuration of the terminal driver;
286 see \fI\%termios\fP(3).
287 To force 8 bits to be returned,
288 call
289 .BR meta( .\|.\|. ,
290 .BR TRUE) ;
291 this is equivalent,
292 on POSIX systems,
293 to setting the CS8 flag on the terminal.
294 To force 7 bits to be returned,
295 call
296 .BR meta( .\|.\|. ,
297 .BR FALSE) ;
298 this is equivalent,
299 on POSIX systems,
300 to setting the CS7 flag on the terminal.
301 The window argument,
302 .IR win ,
303 is always ignored.
304 If the
305 .I \%term\%info
306 string capabilities
307 .B \%meta_on
308 .RB ( smm )
309 and
310 .B \%meta_off
311 .RB ( rmm )
312 are defined for the terminal type,
313 enabling meta mode sends
314 .B smm
315 to the terminal and disabling it sends
316 .B rmm
317 to the terminal.
318 .\"
319 .SS "nl, nonl"
320 Initially,
321 whether the terminal reports a carriage return
322 using the character code for a line feed
323 depends on the configuration of the terminal driver;
324 see \fI\%termios\fP(3).
325 .B nl
326 configures the terminal to perform this translation.
327 .B nonl
328 disables it.
329 .\"
330 .SS nodelay
331 .B \%nodelay
332 configures the input character reading function to be non-blocking for
333 window
334 .IR "win" .
335 If no input is ready,
336 the reading function returns
337 .BR ERR "."
338 If disabled
339 .RI ( bf
340 is
341 .BR FALSE ),
342 the reading function does not return until it has input.
343 .SS notimeout
344 When the input character reading function reads an ESC character,
345 it sets a timer while waiting for the next character.
346 .BI \%notimeout( win ,
347 .B TRUE)
348 disables this timer.
349 The purpose of the timeout is to distinguish sequences produced by a
350 function key from those typed by a user.
351 To configure the timeout rather than disabling it,
352 see
353 .B \%wtimeout
354 below.
355 .\"
356 .SS "qiflush, noqiflush"
357 .\"
358 .B \%qiflush
359 and
360 .B \%noqiflush
361 configure the terminal driver's treatment of its input and output queues
362 when it handles the interrupt,
363 suspend,
364 or quit characters in
365 .I \%cbreak
366 and \*(``cooked\*('' modes;
367 on POSIX systems,
368 see \fI\%termios\fP(3).
369 The default behavior is inherited from the terminal driver settings.
370 Calling
371 .B \%qiflush
372 configures the terminal to flush the queues when any of these events
373 occurs,
374 giving the impression of faster response to user input,
375 but making the library's model of the screen contents incorrect.
376 Calling
377 .B \%noqiflush
378 prevents such flushing,
379 but might frustrate impatient users on slow connections if a
380 .I curses
381 update of the screen is in progress when the event occurs;
382 see
383 .B \%typeahead
384 below for a mitigation of this problem.
385 You may want to call
386 .B \%noqiflush
387 in a signal handler
388 if you want output to continue
389 after the handler exits
390 as though the interrupt had not occurred.
391 .\"
392 .SS "raw, noraw"
393 .B raw
394 configures the terminal to read input in
395 .IR "raw mode" ,
396 which is similar to cbreak mode
397 (see
398 .B \%cbreak
399 above)
400 except that it furthermore passes through the terminal's configured
401 interrupt,
402 quit,
403 suspend,
404 and flow control characters
405 uninterpreted to the application,
406 instead of generating a signal or acting on I/O flow.
407 The behavior of the terminal's \*(``Break\*('' key
408 (if any)
409 depends on terminal driver configuration parameters that
410 .I curses
411 does not handle.
412 .B \%noraw
413 returns the terminal to normal (\*(``cooked\*('') mode.
414 .\"
415 .SS "timeout, wtimeout"
416 .B \%wtimeout
417 configures whether a
418 .I curses
419 input character reading function called on window
420 .I win
421 uses blocking or non-blocking reads.
422 If
423 .I delay
424 is negative,
425 a blocking read is used,
426 waiting indefinitely for input.
427 If
428 .I delay
429 is zero,
430 a non-blocking read is used;
431 an input character reading function returns
432 .B ERR
433 if no input is pending.
434 If
435 .I delay
436 is positive,
437 an input character reading function
438 blocks for
439 .I delay
440 milliseconds,
441 and returns
442 .B ERR
443 if the delay elapses and there is still no input pending.
444 .B \%timeout
445 calls
446 .B \%wtimeout
447 on
448 .BR stdscr "."
449 .\"
450 .SS typeahead
451 Normally,
452 a
453 .I curses
454 library checks the terminal for input while updating the screen.
455 If any is found,
456 the update is postponed until the next \fB\%wrefresh\fP(3X) or
457 \fB\%doupdate\fP(3X) call,
458 allowing faster response to user key strokes.
459 The library tests the file descriptor corresponding to the
460 .I FILE
461 stream pointer passed to \fB\%newterm\fP(3X)
462 (or
463 .I stdin
464 if \fB\%initscr\fP(3X) was called),
465 for pending input.
466 .B \%typeahead
467 instructs
468 .I curses
469 to test file descriptor
470 .I fd
471 instead.
472 An
473 .I fd
474 of
475 .B \-1
476 disables the check.
477 .\"
478 .SH RETURN VALUE
479 .B \%timeout
480 and
481 .B \%wtimeout
482 return no value.
483 .PP
484 .BR \%cbreak ","
485 .BR \%nocbreak ","
486 .BR \%echo ","
487 .BR \%noecho ","
488 .BR \%halfdelay ","
489 .BR \%intrflush ","
490 .BR \%keypad ","
491 .BR \%meta ","
492 .BR \%nodelay ","
493 .BR \%notimeout ","
494 .BR \%nl ","
495 .BR \%nonl ","
496 .BR \%raw ","
497 .BR \%noraw ","
498 and
499 .B \%typeahead
500 return
501 .B OK
502 on success and
503 .B ERR
504 on failure.
505 .PP
506 In
507 .IR \%ncurses ","
508 the functions in the previous paragraph return
509 .B ERR
510 if
511 .bP
512 the terminal is not initialized or
513 .bP
514 .I win
515 is
516 .B NULL
517 (except for
518 .B \%intrflush
519 and
520 .BR meta ","
521 which ignore its value).
522 .PP
523 Further,
524 .B \%halfdelay
525 returns
526 .B ERR
527 if
528 .I delay
529 is outside the range 1..255.
530 .PP
531 See section \*(``EXTENSIONS\*('' below for the
532 return values of
533 .BR is_cbreak ","
534 .BR is_echo ","
535 .BR is_nl ","
536 and
537 .BR is_raw "."
538 .SH NOTES
539 .BR echo ","
540 .BR \%noecho ","
541 .BR \%halfdelay ","
542 .BR \%intrflush ","
543 .BR meta ","
544 .BR nl ","
545 .BR nonl ","
546 .BR \%nodelay ","
547 .BR \%notimeout ","
548 .BR \%noqiflush ","
549 .BR \%qiflush ","
550 .BR \%timeout ","
551 and
552 .B \%wtimeout
553 may be implemented as macros.
554 .PP
555 .B \%noraw
556 and
557 .B \%nocbreak
558 follow historical practice in that they attempt to restore normal
559 (\*(``cooked\*('') mode from raw and cbreak modes,
560 respectively.
561 Mixing
562 .BR raw / \%noraw
563 calls with
564 .BR cbreak / \%nocbreak
565 calls leads to terminal driver control states that are hard to predict
566 or understand;
567 doing so is not recommended.
568 .SH EXTENSIONS
569 .I \%ncurses
570 provides four \*(``is_\*('' functions corresponding to
571 .BR \%cbreak ","
572 .BR echo ","
573 .BR nl ","
574 and
575 .BR raw ","
576 permitting their states to be queried by the application.
577 .PP
578 .TS
579 center;
580 Lb Lb Lb
581 L  L  L .
582 Query   Set     Reset
583 _
584 is_cbreak       cbreak  nocbreak
585 is_echo echo    noecho
586 is_nl   nl      nonl
587 is_raw  raw     noraw
588 .TE
589 .PP
590 In each case,
591 the function returns
592 .TP 5 \" "-1" + 2n tag separation + 1n fudge for typesetters like grops
593 .B 1
594 if the flag is set,
595 .TP
596 .B 0
597 if the flag is reset,
598 or
599 .TP
600 .B \-1
601 if the library is not initialized.
602 .SH PORTABILITY
603 Applications employing
604 .I \%ncurses
605 extensions should condition their use on the visibility of the
606 .B \%NCURSES_VERSION
607 preprocessor macro.
608 .PP
609 Except as noted in section \*(``EXTENSIONS\*('' above,
610 X/Open Curses,
611 Issue 4 describes these functions.
612 It specifies no error conditions for them.
613 .PP
614 SVr4
615 .I curses
616 describes a successful return value only as
617 \*(``an integer value other than
618 .BR ERR \*(''.
619 .PP
620 .I \%ncurses
621 follows X/Open Curses
622 and the historical practice of System\ V
623 .IR curses ","
624 clearing the terminal driver's \*(``echo\*('' flag when initializing the
625 screen.
626 BSD
627 .I curses
628 did not,
629 but its
630 .I raw
631 function turned it off as a side effect.
632 .\" SGTTY's sg_flags had a "RAW" symbol; termio in SVr1 for the PDP-11
633 .\" did not.
634 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/include/curses.h
635 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/sysv-pdp11_man/a_man/man7/termio.7
636 For best portability,
637 call
638 .B echo
639 or
640 .B \%noecho
641 explicitly just after initialization,
642 even if your program remains in normal (\*(``cooked\*('') mode.
643 .PP
644 X/Open Curses is ambiguous regarding whether
645 .I raw
646 should disable the carriage return and line feed translation feature
647 controlled by
648 .I nl
649 and
650 .IR \%nonl "."
651 BSD
652 .I curses
653 did turn off these translations;
654 System\ V
655 .I curses
656 did not.
657 .I \%ncurses
658 does so,
659 on the assumption that a programmer requesting raw input wants a clean
660 (ideally,
661 8-bit clean)
662 connection that the operating system will not alter.
663 .PP
664 When
665 .B \%keypad
666 is first enabled,
667 .I \%ncurses
668 loads the key definitions for the current terminal description.
669 If the terminal description includes extended string capabilities,
670 for example,
671 by using the
672 .B \-x
673 option of \fB\%@TIC@\fP(1),
674 then
675 .I \%ncurses
676 also defines keys for the capabilities whose names begin with
677 \*(``k\*(''.
678 Corresponding key codes are generated and
679 (depending on previous loads of terminal descriptions)
680 may differ from one execution of a program to the next.
681 The generated key codes are recognized by \fB\%keyname\fP(3X),
682 which then returns a name beginning with \*(``k\*('' denoting the
683 .I \%term\%info
684 capability name rather than \*(``K\*('',
685 used for
686 .I curses
687 key names.
688 On the other hand,
689 an application can use \fB\%define_key\fP(3X) to bind
690 a specific key to a string of the programmer's choice.
691 This feature enables an application to check for its presence
692 with \fB\%tigetstr\fP(3X),
693 and reassign the key code to match its own needs.
694 .PP
695 Low-level applications can use \fB\%tigetstr\fP(3X) to obtain the
696 definition of any string capability.
697 .I curses
698 applications use the input character reading function
699 to obtain key codes from input
700 and rely upon the order in which the string capabilities are loaded.
701 Multiple key capability strings can have the same value,
702 but the input character reading function can report only one key code.
703 Most
704 .I curses
705 implementations
706 (including
707 .IR \%ncurses )
708 load key definitions in the order
709 they appear in the
710 .B \%strfnames
711 array of string capability names;
712 see \fB\%term_variables\fP(3X).
713 .\" ncurses/tinfo/parse_entry.c:lookup_fullname, I think --GBR
714 The last capability read using a particular definition determines the
715 key code to be reported.
716 In
717 .IR \%ncurses ,
718 extended capabilities can be interpreted as key definitions.
719 These are loaded after the predefined keys,
720 and if a capability's value is the same as a previously loaded
721 key definition,
722 the later definition is the one used.
723 .SH HISTORY
724 4BSD
725 .I curses
726 (1980)
727 introduced
728 .IR echo ","
729 .IR \%noecho ","
730 .IR nl ","
731 .IR \%nonl ","
732 .IR raw ","
733 and
734 .IR \%noraw "." \" also crmod and nocrmod, never standardized
735 .PP
736 SVr2 (1984) featured a new terminal driver,
737 extending the
738 .I curses
739 API to support it with
740 .IR \%cbreak ","
741 .IR \%nocbreak ","
742 .IR \%intrflush ","
743 .IR \%keypad ","
744 .IR \%meta ","
745 .IR \%nodelay ","
746 and
747 .IR \%typeahead "."
748 .PP
749 SVr3 (1987)
750 added
751 .IR \%halfdelay ","
752 .IR \%notimeout ","
753 and
754 .IR \%wtimeout "."
755 .I \%qiflush
756 and
757 .I \%noqiflush
758 appeared in SVr3.1 (1987),
759 at which point
760 .I \%intrflush
761 became a wrapper for either of these functions,
762 depending on the value of its Boolean argument.
763 SVr3.1 also added
764 .IR \%timeout "."
765 .PP
766 .I \%ncurses
767 6.5 (2024) introduced
768 .IR is_cbreak ","
769 .IR is_echo ","
770 .IR is_nl ","
771 and
772 .IR is_raw "."
773 .PP
774 Formerly,
775 .I \%ncurses
776 used
777 .I \%nl
778 and
779 .I \%nonl
780 to control the conversion of newlines to carriage return/line feed
781 on output as well as input.
782 X/Open Curses documents the use of these functions only for input.
783 This difference arose from converting the
784 .I \%pcurses
785 source (1986),
786 which used
787 \fI\%ioctl\fP(2) calls and the
788 .I \%sgttyb
789 structure,
790 to
791 .I \%termios
792 (the POSIX terminal API).
793 In the former,
794 both input and output were controlled via a single option
795 \*(``CRMOD\*('',
796 while the latter separates these features.
797 Because that conversion interferes with output optimization,
798 .I \%ncurses
799 6.2 (2020) amended
800 .I \%nl
801 and
802 .I \%nonl
803 to eliminate their effect on output.
804 .SH SEE ALSO
805 \fB\%curses\fP(3X),
806 \fB\%curs_getch\fP(3X),
807 \fB\%curs_initscr\fP(3X),
808 \fB\%curs_util\fP(3X),
809 \fB\%define_key\fP(3X),
810 \fB\%term_variables\fP(3X),
811 \fB\%termios\fP(3)