# Console

Import: `import com.install4j.api.screens.Console;`

```java
interface Console extends ProgressInterface
```

A `Console` object allows you to display information to the user and request input when the installer or uninstaller is running in console mode.
Installers or uninstallers must be started with the "-c" argument to run in console mode.
A console object is passed to the `handleConsole` methods of screens and form components.


**See also:**

- [Screen.handleConsole](Screen.md#handleconsole-console)
- [FormComponent.handleConsole](../formcomponents/FormComponent.md#handleconsole-console)

## Inherited from

- [ProgressInterface](../context/ProgressInterface.md) — 13 methods, 7 fields

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`print(Object)`](#print-object) | `void` | Print an object to the console by invoking its `toString()` method. |
| [`println(Object)`](#println-object) | `void` | Print an object to the console by invoking its `toString()` method and append a line feed. |
| [`println(Object, MessageStatus)`](#println-object-messagestatus) | `void` | Print an object to the console with a status indicator and append a line feed. |
| [`println()`](#println) | `void` | Print a line feed to the console. |
| [`isRichConsole()`](#isrichconsole) | `boolean` | Returns whether this is a rich console that supports interactive prompts and styled output. |
| [`more(String)`](#more-string) | `void` | Print a long text to the console and partition it into pages. |
| [`more(String, boolean)`](#more-string-boolean) | `void` | Print a long text to the console and partition it into pages. |
| [`readLine()`](#readline) | `String` | Read input from the console. |
| [`askYesNo(String)`](#askyesno-string) | `boolean` | Ask the user a question that has to be answered with "Yes" or "No". |
| [`askYesNo(String, boolean)`](#askyesno-string-boolean) | `boolean` | Ask the user a question that has to be answered with "Yes" or "No". |
| [`askOkCancel(String)`](#askokcancel-string) | `boolean` | Ask the user a question that has to be answered with "OK" or "Cancel". |
| [`askOkCancel(String, boolean)`](#askokcancel-string-boolean) | `boolean` | Ask the user a question that has to be answered with "OK" or "Cancel". |
| [`askProceedCancel(String)`](#askproceedcancel-string) | `boolean` | Ask the user a question that has to be answered with "Proceed" or "Cancel". |
| [`askProceedCancel(String, boolean)`](#askproceedcancel-string-boolean) | `boolean` | Ask the user a question that has to be answered with "Proceed" or "Cancel". |
| [`askOption(String, String[], String[])`](#askoption-string-string-string) | `int` | Ask the user a question with a fixed set of answers. |
| [`askOption(String, String[], String[], int)`](#askoption-string-string-string-int) | `int` | Ask the user a question with a fixed set of answers. |
| [`askOption(String, String[], String[], int, boolean, boolean)`](#askoption-string-string-string-int-boolean-boolean) | `int` | Ask the user a question with a fixed set of answers. |
| [`askOption(String, String[], String[], String[], int, boolean, boolean)`](#askoption-string-string-string-string-int-boolean-boolean) | `int` | Ask the user a question with a fixed set of answers. |
| [`askMultipleSelection(String, String[], String[], int[], boolean)`](#askmultipleselection-string-string-string-int-boolean) | `int[]` | Ask the user to select multiple elements from a list of options. |
| [`askString(String, String)`](#askstring-string-string) | `String` | Ask the user to enter a string with a default string that can be accepted by the user. |
| [`askFile(String, String)`](#askfile-string-string) | `String` | Ask the user for a file path. |
| [`askDirectory(String, String)`](#askdirectory-string-string) | `String` | Ask the user for a directory path. |
| [`askPassword(String, String)`](#askpassword-string-string) | `String` | Ask the user to enter a password. |
| [`waitForEnter()`](#waitforenter) | `void` | Print [Enter] to the console and wait for the user to hit the Enter key. |
| [`printHeader(String)`](#printheader-string) | `void` | Print the header for a new screen. |

### print(Object)

```java
void print(Object val)
```

Print an object to the console by invoking its `toString()` method.


**Parameters:**

- `val` — the object to be printed

### println(Object)

```java
void println(Object val)
```

Print an object to the console by invoking its `toString()` method and append a line feed.


**Parameters:**

- `val` — the object to be printed

### println(Object, MessageStatus)

```java
void println(Object val, MessageStatus status)
```

Print an object to the console with a status indicator and append a line feed.


**Parameters:**

- `val` — the object to be printed
- `status` — the status of the message

### println()

```java
void println()
```

Print a line feed to the console.

### isRichConsole()

```java
default boolean isRichConsole()
```

Returns whether this is a rich console that supports interactive prompts and styled output.


**Returns:** `true` if this is a rich console

### more(String)

```java
void more(String text) throws UserCanceledException
```

Print a long text to the console and partition it into pages.
Line breaks are introduced after 75 characters, and a "more" notice is printed
every 25 lines.


**Parameters:**

- `text` — the text

**Throws:**

- `UserCanceledException` — if the user cancels the "more" notice, typically with CTRL-C

### more(String, boolean)

```java
default void more(String text, boolean mustReachEnd) throws UserCanceledException
```

Print a long text to the console and partition it into pages.
If `mustReachEnd` is `true`, the user must page through the entire text
before being allowed to dismiss it.


**Parameters:**

- `text` — the text
- `mustReachEnd` — whether the user must reach the end of the text before being allowed to quit

**Throws:**

- `UserCanceledException` — if the user cancels the "more" notice, typically with CTRL-C

### readLine()

```java
String readLine() throws UserCanceledException
```

Read input from the console.


**Returns:** the string that was entered by the user.

**Throws:**

- `UserCanceledException` — if the user cancels the prompt, typically with CTRL-C

### askYesNo(String)

```java
boolean askYesNo(String message) throws UserCanceledException
```

Ask the user a question that has to be answered with "Yes" or "No".
There is no default value.


**Parameters:**

- `message` — the question

**Returns:** whether the user answered "Yes"

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C

### askYesNo(String, boolean)

```java
boolean askYesNo(String message, boolean defaultValue) throws UserCanceledException
```

Ask the user a question that has to be answered with "Yes" or "No".
The default value is configurable.


**Parameters:**

- `message` — the question
- `defaultValue` — whether "Yes" is the default value

**Returns:** whether the user answered "Yes"

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C

### askOkCancel(String)

```java
boolean askOkCancel(String message) throws UserCanceledException
```

Ask the user a question that has to be answered with "OK" or "Cancel".
There is no default value.


**Parameters:**

- `message` — the question

**Returns:** whether the user answered "OK"

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.
Note that this is different from a "Cancel" answer.

### askOkCancel(String, boolean)

```java
boolean askOkCancel(String message, boolean defaultValue) throws UserCanceledException
```

Ask the user a question that has to be answered with "OK" or "Cancel".
The default value is configurable.


**Parameters:**

- `message` — the question
- `defaultValue` — whether "OK" is the default value

**Returns:** whether the user answered "OK"

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.
Note that this is different from a "Cancel" answer.

### askProceedCancel(String)

```java
default boolean askProceedCancel(String message) throws UserCanceledException
```

Ask the user a question that has to be answered with "Proceed" or "Cancel".
There is no default value.


**Parameters:**

- `message` — the question

**Returns:** whether the user answered "Proceed"

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.
Note that this is different from a "Cancel" answer.

### askProceedCancel(String, boolean)

```java
default boolean askProceedCancel(String message, boolean defaultValue) throws UserCanceledException
```

Ask the user a question that has to be answered with "Proceed" or "Cancel".
The default value is configurable.


**Parameters:**

- `message` — the question
- `defaultValue` — whether "Proceed" is the default value

**Returns:** whether the user answered "Proceed"

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.
Note that this is different from a "Cancel" answer.

### askOption(String, String[], String[])

```java
int askOption(String message, String[] descriptions, String[] keys) throws UserCanceledException
```

Ask the user a question with a fixed set of answers.
There is no default value.


**Parameters:**

- `message` — the question
- `descriptions` — an array with a textual description for each option
- `keys` — an array with a short key for each option. Keys are what the user enters to select the desired option.

**Returns:** the selected index of the option

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### askOption(String, String[], String[], int)

```java
int askOption(String message, String[] descriptions, String[] keys, int defaultValue) throws UserCanceledException
```

Ask the user a question with a fixed set of answers.
The default value is configurable.


**Parameters:**

- `message` — the question
- `descriptions` — an array with a textual description for each option
- `keys` — an array with a short key for each option. Keys are what the user enters to select the desired option.
- `defaultValue` — the index of the default option

**Returns:** the selected index of the option

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### askOption(String, String[], String[], int, boolean, boolean)

```java
int askOption(String message, String[] descriptions, String[] keys, int defaultValue, boolean allowNoSelection, boolean oneLinePerOption) throws UserCanceledException
```

Ask the user a question with a fixed set of answers.
The default value, the no-selection policy as well as the presentation of the options are configurable.


**Parameters:**

- `message` — the question
- `descriptions` — an array with a textual description for each option
- `keys` — an array with a short key for each option. Keys are what the user enters to select the desired option.
- `defaultValue` — the index of the default option
- `allowNoSelection` — if the question should allow an empty answer, the return value is -1 in that case.
- `oneLinePerOption` — if the options should be presented on option per line. By default, all options are presented on the same line.

**Returns:** the index of the selected option or -1 if no answer is given.

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### askOption(String, String[], String[], String[], int, boolean, boolean)

```java
int askOption(String message, String[] descriptions, String[] keys, String[] helpTexts, int defaultValue, boolean allowNoSelection, boolean oneLinePerOption) throws UserCanceledException
```

Ask the user a question with a fixed set of answers.
The default value, the help texts, the no-selection policy as well as the presentation of the options are configurable.


**Parameters:**

- `message` — the question
- `descriptions` — an array with a textual description for each option
- `keys` — an array with a short key for each option. Keys are what the user enters to select the desired option.
- `helpTexts` — an array with help texts that can be shown by the user, array elements can be null for no help
- `defaultValue` — the index of the default option
- `allowNoSelection` — if the question should allow an empty answer, the return value is -1 in that case.
- `oneLinePerOption` — if the options should be presented on option per line. By default, all options are presented on the same line.

**Returns:** the index of the selected option or -1 if no answer is given.

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### askMultipleSelection(String, String[], String[], int[], boolean)

```java
int[] askMultipleSelection(String message, String[] descriptions, String[] keys, int[] defaultValues, boolean oneLinePerOption) throws UserCanceledException
```

Ask the user to select multiple elements from a list of options.
The default selection and the presentation of the options are configurable.


**Parameters:**

- `message` — the question
- `descriptions` — an array with a textual description for each option
- `keys` — an array with a short key for each option. Keys are what the user enters to select the desired options.
- `defaultValues` — an array with the indices of the options that are selected by default
- `oneLinePerOption` — if the options should be presented on option per line. By default, all options are presented on the same line.

**Returns:** an array with the indices of the selected options. The length of the array can be zero if no options were selected.

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### askString(String, String)

```java
String askString(String message, String defaultValue) throws UserCanceledException
```

Ask the user to enter a string with a default string that can be accepted by the user.


**Parameters:**

- `message` — the prompt before the input
- `defaultValue` — the default string

**Returns:** the string entered by the user or the default value if the user hits the Enter key.

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### askFile(String, String)

```java
String askFile(String message, String defaultValue) throws UserCanceledException
```

Ask the user for a file path. In rich console mode, tab completion offers files and directories.


**Parameters:**

- `message` — the prompt message
- `defaultValue` — the default value, or `null`

**Returns:** the path entered by the user, or the default value if no input was given

**Throws:**

- `UserCanceledException` — if the user cancels the prompt, typically with CTRL-C

### askDirectory(String, String)

```java
String askDirectory(String message, String defaultValue) throws UserCanceledException
```

Ask the user for a directory path. In rich console mode, tab completion offers directories only.


**Parameters:**

- `message` — the prompt message
- `defaultValue` — the default value, or `null`

**Returns:** the path entered by the user, or the default value if no input was given

**Throws:**

- `UserCanceledException` — if the user cancels the prompt, typically with CTRL-C

### askPassword(String, String)

```java
String askPassword(String message, String defaultValue) throws UserCanceledException
```

Ask the user to enter a password.


**Parameters:**

- `message` — the prompt before the input
- `defaultValue` — the default string

**Returns:** the string entered by the user or the default value if the user hits the Enter key.

**Throws:**

- `UserCanceledException` — if the user cancels the question, typically with CTRL-C.

### waitForEnter()

```java
void waitForEnter() throws UserCanceledException
```

Print [Enter] to the console and wait for the user to hit the Enter key.


**Throws:**

- `UserCanceledException` — if the user cancels the notice, typically with CTRL-C.

### printHeader(String)

```java
void printHeader(String title) throws UserCanceledException
```

Print the header for a new screen. This invokes the "Console screen change handler"
that is set for the application node on the Screens & Actions tab.
If that script is not configured, nothing will be printed.


**Parameters:**

- `title` — the title

**Throws:**

- `UserCanceledException` — if the user cancels the notice, typically with CTRL-C.

