# The GAP Shell User Interface

## 1. Shell UI commands

The shell user interface provides the user with the option to control threads by commands prefixed with an exclamation mark ("!"). Those commands are listed below.

For ease of use, users only need to type as many letters of each commands so that it can be unambiguously selected. Thus, the shell will recognize `!l` as an abbreviation for `!list`.

### 1.1 !shell [<name>]

Starts a new shell thread and switches to it. Optionally, a name for the thread can be provided.

### 1.2 !fork [<name>]

Starts a new background shell thread. Optionally, a name for the thread can be provided.

### 1.3 !list

List all current threads that are interacting with the user. This does not list threads created with `CreateThread()` that have not entered a break loop.

### 1.4 !name [<id>] <name>

Give the thread with the numerical identifier or name `<id>` the name name.

### 1.5 !info <id>

Provide information about the thread with the numerical identifier or name `<id>`.

### 1.6 !hide [<id>|*]

Hide output from the thread with the numerical identifier or name `<id>` when it is not the foreground thread. If no thread is specified, make this the default behavior for future threads.

### 1.7 !show [<id>|*]

Show output from the thread with the numerical identifier or name `<id>` even when it is not the foreground thread. If no thread is specified, make this the default behavior for future threads.

### 1.8 !keep [<id>] <num>

Keep `<num>` lines of output from the specified thread. If no thread was specified, make this the default.

### 1.9 !prompt (<id>|*) <string>

Set the prompt for the specified thread (or for all newly created threads if `*` was specified) to be `<string>`. If the string contains the pattern `%id%`, it is replaced with the numerical id of the thread; if it contains the pattern `%name%`, it is replaced with the name of the thread; if the thread has no name, the numerical id is displayed instead.

### 1.10 !prefix ([<id>]|*) <string>

Prefix the output from the specified thread (or for all newly created threads if `*` was specified) wiht `<string>`. The same substitution rules as for the `!prompt` command apply.

### 1.11 !select <id>

Make the specified thread the foreground thread.

### 1.12 !next

Make the next thread in numerical order the foreground thread.

### 1.13 !previous

Make the previous thread in numerical order the foreground thread.

### 1.14 !replay <num> [<id>]

Display the last `<num>` lines of output of the specified thread. If no thread was specified, display the last `<num>` lines of the current foreground thread.

### 1.15 !<id>

`!<id>` is a shortcut for `!select <id>`.

### 1.16 !source <file>

Read commands from file `<file>`.

### 1.17 !!<file>

`!!<file>` is shortcut for `!source <file>`.

### 1.18 !alias <shortcut> <expansion>

Create an alias. After defining the alias, `!<shortcut> <rest of line>` will be replaced with `!<expansion> <rest of line>`.

### 1.19 !unalias <shortcut>

Removes the specified alias.

### 1.20 !eval <gap code>

Evaluates `<gap code>` as a command.

### 1.21 !run <function> <string>

Calls the function with name `<function>`, passing it the single argument `<string>` as a GAP string.

## 2. GAP functions to access the Shell UI

Note: These functions currently aren't available due to some necessary internal reorganization.

There are several functions to access the basic functionality of the shell user interface. Other than `ShellUIRegisterCommand`, they can only be called from within a registered command.

Threads can be specified either by their numerical identifier or by their name (as a string). The empty string can be used to specify the current foreground thread.

### 2.1 ShellUIRegisterCommand(name, func)

Registers the command `!name` with the shell UI. It will call <func> with the rest of the command line passed as a string argument when typed.

### 2.2 ShellUIForegroundThread()

Returns the numerical identifier of the current foreground thread.

### 2.3 ShellUIForegroundThreadName()

Returns the name of the current foreground thread or `fail` if the current foreground thread has no name.

### 2.4 ShellUISelectThread(id)

Makes `id` the current foreground thread. Returns `true` or `false` to indicate success.

### 2.5 ShellUIOutputHistory(id, count)

Returns the last `count` lines of the thread specified by `id` (which can be a numerical identifier or a name). Returns `fail` if there is no such thread.

### 2.6 ShellUIOutputHistoryLength(id, length)

Retain `length` lines of output history from thread `id`.

### 2.7 ShellUIOutputHistoryDefaultLength(length)

By default, retain `length` lines of output history from each thread.

### 2.8 ShellUIAtomicRegion

`ShellUIAtomicRegion` is a global variable to be used for synchronization when one wishes to perform multiple operations on the shell UI as one atomic step, as in:

    atomic ShellUIAtomicRegion do
      ...
    od;

### 2.9 ShellUINewSession(foreground, name)

Creates a new shell thread. Here, `foreground` is a boolean variable specifying whether it should be made the new foreground thread and `name` is the name of the thread. The empty string can be used to leave the thread without a name.