Erlang -- tty - A Command-Line Interface

# 9 tty - A Command-Line Interface

tty is a simple command-line interface program where keystrokes are collected and interpreted. Completed lines are sent to the shell for interpretation. A simple history mechanism saves previous lines, which can be edited before sending them to the shell. tty is started when Erlang is started with the following command:

    erl

tty operates in several different modes:

- Normal mode, in which text lines can be edited and sent to the shell.

- Search mode, in which the user can search for previous commands in the history buffer.

- Shell break mode, which allows the user to kill the current shell, start multiple shells, and so on.

###
9.1 Normal Mode

In normal mode keystrokes from the user are collected and interpreted by tty. Most of the Emacs line-editing commands are supported. The following is a complete list of the supported line-editing commands.

Typographic conventions:

- C-a means pressing the Ctrl key and the letter a simultaneously.
- C-S-a means pressing the Ctrl key, the Shift key, and the letter a simultaneously.
- M-f means pressing the Esc key and the letter f in sequence or pressing the Alt key and the letter f simultaneously.
- Home and End represent the keys with the same name on the keyboard.
- Left, Right, Up and Down represent the corresponding arrow keys.
- When a function has multiple possible key sequences they are listed on individual lines in the Key Sequence column.

Key Sequence | Function
Home | Beginning of line
C-a | Beginning of line
C-b | Backward character
C-Left M-Left | Backward word
M-b | Backward word
C-d | Delete character
M-d | Delete word
End | End of line
C-e | End of line
C-f | Forward character
C-Right M-Right | Forward word
M-f | Forward word
C-g | Enter shell break mode
C-k | Kill line
C-u | Backward kill line
C-l | Clears the screen
M-c | Clears the current expression
M-l | Redraw line
C-n | Fetch next line from the history buffer
C-o M-o | Edit the current line using the editor specified in the environment variable VISUAL or EDITOR. The environment variables can contain arguments to the editor if needed, for example VISUAL="emacs -nw". On Windows the editor cannot be a console based editor.
C-p | Fetch previous line from the history buffer
C-r | Enter search mode and then search backward in the shell history
C-s | In search mode, search forward in the shell history
C-t | Transpose characters
C-w | Backward kill word
C-y | Insert previously killed text
C-] | Insert matching closing bracket
C-Up M-Up | Navigate one row up when editing multiple lines
C-Down M-Down | Navigate one row down when editing multiple lines
M-Enter | Insert a new line at cursor
M-< M-S-Up | Navigate to the start of the current expression
M-> M-S-Down | Navigate to the end of the current expression
Tab C-i | Autocomplete current expression, or show completion suggestions
M-c | Clear current expression

Table 9.1: tty Text Editing

###
9.2 Shell Break Mode

In this mode the following can be done:

- Kill or suspend the current shell
- Connect to a suspended shell
- Start a new shell