Next: , Previous: , Up: Input/Output   [Contents][Index]


14.8 Terminal Mode

A port that reads from or writes to a terminal has a terminal mode; this is either cooked or raw. This mode is independent of the blocking mode: each can be changed independently of the other. Furthermore, a terminal I/O port has independent terminal modes both for input and for output.

A terminal port in cooked mode provides some standard processing to make the terminal easy to communicate with. For example, under unix, cooked mode on input reads from the terminal a line at a time and provides editing within the line, while cooked mode on output might translate linefeeds to carriage-return/linefeed pairs. In general, the precise meaning of cooked mode is operating-system dependent, and furthermore might be customizable by means of operating-system utilities. The basic idea is that cooked mode does whatever is necessary to make the terminal handle all of the usual user-interface conventions for the operating system, while keeping the program’s interaction with the port as normal as possible.

A terminal port in raw mode disables all of that processing. In raw mode, characters are directly read from and written to the device without any translation or interpretation by the operating system. On input, characters are available as soon as they are typed, and are not echoed on the terminal by the operating system. In general, programs that put ports in raw mode have to know the details of interacting with the terminal. In particular, raw mode is used for writing programs such as text editors.

Terminal ports are initially in cooked mode; this can be changed at any time with the procedures defined in this section.

These procedures represent cooked mode by the symbol cooked, and raw mode by the symbol raw. An argument called mode must be one of these symbols. A port argument to any of these procedures may be any port, even if that port does not support terminal mode; in that case, the port is not modified in any way.

procedure: input-port-terminal-mode input-port
procedure: output-port-terminal-mode output-port

Returns the terminal mode of input-port or output-port. Returns #f if the given port is not a terminal port.

procedure: set-input-port-terminal-mode! input-port mode
procedure: set-output-port-terminal-mode! output-port mode

Changes the terminal mode of input-port or output-port to be mode and returns an unspecified value.

procedure: with-input-port-terminal-mode input-port mode thunk
procedure: with-output-port-terminal-mode output-port mode thunk

Thunk must be a procedure of no arguments.

Binds the terminal mode of input-port or output-port to be mode, and calls thunk. When thunk returns, the original terminal mode is restored and the values yielded by thunk are returned.

obsolete procedure: port/input-terminal-mode input-port
obsolete procedure: port/set-input-terminal-mode input-port mode
obsolete procedure: port/with-input-terminal-mode input-port mode thunk
obsolete procedure: port/output-terminal-mode output-port
obsolete procedure: port/set-output-terminal-mode output-port mode
obsolete procedure: port/with-output-terminal-mode output-port mode thunk

These procedures are deprecated; instead use the corresponding procedures above.


Next: Format, Previous: Blocking Mode, Up: Input/Output   [Contents][Index]