Next: , Previous: , Up: Initialization   [Contents][Index]

4.4.1 Initialization Functions raw! and cbreak!

Normally the terminal driver buffers the characters a user types until a newline or carriage return is encountered. But most programs require that the characters be available as soon as the user types them. The functions cbreak! and raw! are used to disable line buffering. The difference between these two functions is in the way control characters like suspend (Ctrl-Z), interrupt and quit (Ctrl-C) are passed to the program. In the raw! mode, these characters are directly passed to the program without generating a signal. In the cbreak! mode, these control characters are interpreted as any other character by the terminal driver, allowing Ctrl-C and Ctrl-Z to quit and suspend the program. echo! and noecho!

These functions control the echoing of characters typed by the user to the terminal. noecho! switches off echoing. With echoing off, when a user presses a character, it is not displayed on the screen. keypad!

This function enables the reading of function keys like F1, F2, arrow keys, etc. Almost every interactive program enables this, as arrow keys are a major part of any user interface. Do (keypad! stdscr #t) to enable this feature for the regular screen stdscr (assuming that stdscr is the variable you used to hold the output of initscr.) halfdelay!

This function is useful when you want to ask the user for input, and if he doesn’t respond within a certain time, do something else. One possible example would be a timeout at a password prompt. halfdelay! enables half-delay mode, which is similar to cbreak! mode in that characters types are immediately available to the program. However, after a period of time if there is no input, it returns #f.

Next: , Previous: , Up: Initialization   [Contents][Index]