]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_inopts.3x
2c5d7b69fb23cd832224add90bf1fb57fd143cbb
[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.75 2024/06/15 19:49:39 tom Exp $
32 .TH curs_inopts 3X 2024-06-15 "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 screen's echo option is 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 in cbreak or raw modes
324 depends on the configuration of the terminal driver;
325 see \fI\%termios\fP(3).
326 .B nl
327 configures the terminal to perform this translation.
328 .B nonl
329 disables it.
330 In normal (or \*(``cooked\*('') mode,
331 the terminal driver always translates carriage returns to line feeds.
332 .\"
333 .SS nodelay
334 .B \%nodelay
335 configures the input character reading function to be non-blocking for
336 window
337 .IR "win" .
338 If no input is ready,
339 the reading function returns
340 .BR ERR "."
341 If disabled
342 .RI ( bf
343 is
344 .BR FALSE ),
345 the reading function does not return until it has input.
346 .SS notimeout
347 When the input character reading function reads an ESC character,
348 it sets a timer while waiting for the next character.
349 .BI \%notimeout( win ,
350 .B TRUE)
351 disables this timer.
352 The purpose of the timeout is to distinguish sequences produced by a
353 function key from those typed by a user.
354 To configure the timeout rather than disabling it,
355 see
356 .B \%wtimeout
357 below.
358 .\"
359 .SS "qiflush, noqiflush"
360 .\"
361 .B \%qiflush
362 and
363 .B \%noqiflush
364 configure the terminal driver's treatment of its input and output queues
365 when it handles the interrupt,
366 suspend,
367 or quit characters in
368 .I \%cbreak
369 and \*(``cooked\*('' modes;
370 on POSIX systems,
371 see \fI\%termios\fP(3).
372 The default behavior is inherited from the terminal driver settings.
373 Calling
374 .B \%qiflush
375 configures the terminal to flush the queues when any of these events
376 occurs,
377 giving the impression of faster response to user input,
378 but making the library's model of the screen contents incorrect.
379 Calling
380 .B \%noqiflush
381 prevents such flushing,
382 but might frustrate impatient users on slow connections if a
383 .I curses
384 update of the screen is in progress when the event occurs;
385 see
386 .B \%typeahead
387 below for a mitigation of this problem.
388 You may want to call
389 .B \%noqiflush
390 in a signal handler
391 if you want output to continue
392 after the handler exits
393 as though the interrupt had not occurred.
394 .\"
395 .SS "raw, noraw"
396 .B raw
397 configures the terminal to read input in
398 .IR "raw mode" ,
399 which is similar to cbreak mode
400 (see
401 .B \%cbreak
402 above)
403 except that it furthermore passes through the terminal's configured
404 interrupt,
405 quit,
406 suspend,
407 and flow control characters
408 uninterpreted to the application,
409 instead of generating a signal or acting on I/O flow.
410 The behavior of the terminal's \*(``Break\*('' key
411 (if any)
412 depends on terminal driver configuration parameters that
413 .I curses
414 does not handle.
415 .B \%noraw
416 returns the terminal to normal (\*(``cooked\*('') mode.
417 .\"
418 .SS "timeout, wtimeout"
419 .B \%wtimeout
420 configures whether a
421 .I curses
422 input character reading function called on window
423 .I win
424 uses blocking or non-blocking reads.
425 If
426 .I delay
427 is negative,
428 a blocking read is used,
429 waiting indefinitely for input.
430 If
431 .I delay
432 is zero,
433 a non-blocking read is used;
434 an input character reading function returns
435 .B ERR
436 if no input is pending.
437 If
438 .I delay
439 is positive,
440 an input character reading function
441 blocks for
442 .I delay
443 milliseconds,
444 and returns
445 .B ERR
446 if the delay elapses and there is still no input pending.
447 .B \%timeout
448 calls
449 .B \%wtimeout
450 on
451 .BR stdscr "."
452 .\"
453 .SS typeahead
454 Normally,
455 a
456 .I curses
457 library checks the terminal for input while updating the screen.
458 If any is found,
459 the update is postponed until the next \fB\%wrefresh\fP(3X) or
460 \fB\%doupdate\fP(3X) call,
461 allowing faster response to user key strokes.
462 The library tests the file descriptor corresponding to the
463 .I FILE
464 stream pointer passed to \fB\%newterm\fP(3X)
465 (or
466 .I stdin
467 if \fB\%initscr\fP(3X) was called),
468 for pending input.
469 .B \%typeahead
470 instructs
471 .I curses
472 to test file descriptor
473 .I fd
474 instead.
475 An
476 .I fd
477 of
478 .B \-1
479 disables the check.
480 .\"
481 .SH RETURN VALUE
482 .B \%timeout
483 and
484 .B \%wtimeout
485 return no value.
486 .PP
487 .BR \%cbreak ","
488 .BR \%nocbreak ","
489 .BR \%echo ","
490 .BR \%noecho ","
491 .BR \%halfdelay ","
492 .BR \%intrflush ","
493 .BR \%keypad ","
494 .BR \%meta ","
495 .BR \%nodelay ","
496 .BR \%notimeout ","
497 .BR \%nl ","
498 .BR \%nonl ","
499 .BR \%raw ","
500 .BR \%noraw ","
501 and
502 .B \%typeahead
503 return
504 .B OK
505 on success and
506 .B ERR
507 on failure.
508 .PP
509 In
510 .IR \%ncurses ","
511 the functions in the previous paragraph return
512 .B ERR
513 if
514 .bP
515 the terminal is not initialized or
516 .bP
517 .I win
518 is
519 .B NULL
520 (except for
521 .B \%intrflush
522 and
523 .BR meta ","
524 which ignore its value).
525 .PP
526 Further,
527 .B \%halfdelay
528 returns
529 .B ERR
530 if
531 .I delay
532 is outside the range 1..255.
533 .PP
534 See section \*(``EXTENSIONS\*('' below for the
535 return values of
536 .BR is_cbreak ","
537 .BR is_echo ","
538 .BR is_nl ","
539 and
540 .BR is_raw "."
541 .SH NOTES
542 .BR echo ","
543 .BR \%noecho ","
544 .BR \%halfdelay ","
545 .BR \%intrflush ","
546 .BR meta ","
547 .BR nl ","
548 .BR nonl ","
549 .BR \%nodelay ","
550 .BR \%notimeout ","
551 .BR \%noqiflush ","
552 .BR \%qiflush ","
553 .BR \%timeout ","
554 and
555 .B \%wtimeout
556 may be implemented as macros.
557 .PP
558 .B \%noraw
559 and
560 .B \%nocbreak
561 follow historical practice in that they attempt to restore normal
562 (\*(``cooked\*('') mode from raw and cbreak modes,
563 respectively.
564 Mixing
565 .BR \%raw / noraw
566 calls with
567 .BR \%cbreak / nocbreak
568 calls leads to terminal driver control states that are hard to predict
569 or understand;
570 doing so is not recommended.
571 .SH EXTENSIONS
572 .I \%ncurses
573 provides four \*(``is_\*('' functions corresponding to
574 .BR \%cbreak ","
575 .BR echo ","
576 .BR nl ","
577 and
578 .BR raw ","
579 permitting their states to be queried by the application.
580 .PP
581 .TS
582 center;
583 Lb Lb Lb
584 L  L  L .
585 Query   Set     Reset
586 _
587 is_cbreak       cbreak  nocbreak
588 is_echo echo    noecho
589 is_nl   nl      nonl
590 is_raw  raw     noraw
591 .TE
592 .PP
593 In each case,
594 the function returns
595 .TP 5 \" "-1" + 2n tag separation + 1n fudge for typesetters like grops
596 .B 1
597 if the option is set,
598 .TP
599 .B 0
600 if the option is reset,
601 or
602 .TP
603 .B \-1
604 if the library is not initialized.
605 .SH PORTABILITY
606 Applications employing
607 .I \%ncurses
608 extensions should condition their use on the visibility of the
609 .B \%NCURSES_VERSION
610 preprocessor macro.
611 .PP
612 Except as noted in section \*(``EXTENSIONS\*('' above,
613 X/Open Curses,
614 Issue 4 describes these functions.
615 It specifies no error conditions for them.
616 .PP
617 SVr4
618 .I curses
619 describes a successful return value only as
620 \*(``an integer value other than
621 .BR ERR \*(''.
622 .PP
623 .I \%ncurses
624 follows X/Open Curses
625 and the historical practice of System\ V
626 .IR curses ","
627 clearing the terminal driver's \*(``echo\*('' flag when initializing the
628 screen.
629 BSD
630 .I curses
631 did not,
632 but its
633 .I raw
634 function turned it off as a side effect.
635 .\" SGTTY's sg_flags had a "RAW" symbol; termio in SVr1 for the PDP-11
636 .\" did not.
637 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/include/curses.h
638 .\" https://github.com/ryanwoodsmall/oldsysv/blob/master/sysv-pdp11_man/a_man/man7/termio.7
639 For best portability,
640 call
641 .B echo
642 or
643 .B \%noecho
644 explicitly just after initialization,
645 even if your program remains in normal (\*(``cooked\*('') mode.
646 .PP
647 X/Open Curses is ambiguous regarding whether
648 .I raw
649 should disable the carriage return and line feed translation feature
650 controlled by
651 .I nl
652 and
653 .IR \%nonl "."
654 BSD
655 .I curses
656 did turn off these translations;
657 System\ V
658 .I curses
659 did not.
660 .I \%ncurses
661 does so,
662 on the assumption that a programmer requesting raw input wants a clean
663 (ideally,
664 8-bit clean)
665 connection that the operating system will not alter.
666 .PP
667 When
668 .B \%keypad
669 is first enabled,
670 .I \%ncurses
671 loads the key definitions for the current terminal description.
672 If the terminal description includes extended string capabilities,
673 for example,
674 by using the
675 .B \-x
676 option of \fB\%@TIC@\fP(1),
677 then
678 .I \%ncurses
679 also defines keys for the capabilities whose names begin with
680 \*(``k\*(''.
681 Corresponding key codes are generated and
682 (depending on previous loads of terminal descriptions)
683 may differ from one execution of a program to the next.
684 The generated key codes are recognized by \fB\%keyname\fP(3X),
685 which then returns a name beginning with \*(``k\*('' denoting the
686 .I \%term\%info
687 capability name rather than \*(``K\*('',
688 used for
689 .I curses
690 key names.
691 On the other hand,
692 an application can use \fB\%define_key\fP(3X) to bind
693 a specific key to a string of the programmer's choice.
694 This feature enables an application to check for its presence
695 with \fB\%tigetstr\fP(3X),
696 and reassign the key code to match its own needs.
697 .PP
698 Low-level applications can use \fB\%tigetstr\fP(3X) to obtain the
699 definition of any string capability.
700 .I curses
701 applications use the input character reading function
702 to obtain key codes from input
703 and rely upon the order in which the string capabilities are loaded.
704 Multiple key capability strings can have the same value,
705 but the input character reading function can report only one key code.
706 Most
707 .I curses
708 implementations
709 (including
710 .IR \%ncurses )
711 load key definitions in the order
712 they appear in the
713 .B \%strfnames
714 array of string capability names;
715 see \fB\%term_variables\fP(3X).
716 .\" ncurses/tinfo/parse_entry.c:lookup_fullname, I think --GBR
717 The last capability read using a particular definition determines the
718 key code to be reported.
719 In
720 .IR \%ncurses ,
721 extended capabilities can be interpreted as key definitions.
722 These are loaded after the predefined keys,
723 and if a capability's value is the same as a previously loaded
724 key definition,
725 the later definition is the one used.
726 .SH HISTORY
727 4BSD
728 .I curses
729 (1980)
730 introduced
731 .IR echo ","
732 .IR \%noecho ","
733 .IR nl ","
734 .IR \%nonl ","
735 .IR raw ","
736 and
737 .IR \%noraw "." \" also crmod and nocrmod, never standardized
738 .PP
739 SVr2 (1984) featured a new terminal driver,
740 extending the
741 .I curses
742 API to support it with
743 .IR \%cbreak ","
744 .IR \%nocbreak ","
745 .IR \%intrflush ","
746 .IR \%keypad ","
747 .IR \%meta ","
748 .IR \%nodelay ","
749 and
750 .IR \%typeahead "."
751 .PP
752 SVr3 (1987)
753 added
754 .IR \%halfdelay ","
755 .IR \%notimeout ","
756 and
757 .IR \%wtimeout "."
758 .I \%qiflush
759 and
760 .I \%noqiflush
761 appeared in SVr3.1 (1987),
762 at which point
763 .I \%intrflush
764 became a wrapper for either of these functions,
765 depending on the value of its Boolean argument.
766 SVr3.1 also added
767 .IR \%timeout "."
768 .PP
769 .I \%ncurses
770 6.5 (2024) introduced
771 .IR is_cbreak ","
772 .IR is_echo ","
773 .IR is_nl ","
774 and
775 .IR is_raw "."
776 .PP
777 Formerly,
778 .I \%ncurses
779 used
780 .I \%nl
781 and
782 .I \%nonl
783 to control the conversion of newlines to carriage return/line feed
784 on output as well as input.
785 X/Open Curses documents the use of these functions only for input.
786 This difference arose from converting the
787 .I \%pcurses
788 source (1986),
789 which used
790 \fI\%ioctl\fP(2) calls and the
791 .I \%sgttyb
792 structure,
793 to
794 .I \%termios
795 (the POSIX terminal API).
796 In the former,
797 both input and output were controlled via a single option
798 \*(``CRMOD\*('',
799 while the latter separates these features.
800 Because that conversion interferes with output optimization,
801 .I \%ncurses
802 6.2 (2020) amended
803 .I \%nl
804 and
805 .I \%nonl
806 to eliminate their effect on output.
807 .SH SEE ALSO
808 \fB\%curses\fP(3X),
809 \fB\%curs_getch\fP(3X),
810 \fB\%curs_initscr\fP(3X),
811 \fB\%curs_util\fP(3X),
812 \fB\%define_key\fP(3X),
813 \fB\%termios\fP(3),
814 \fB\%term_variables\fP(3X)