= TerminalUI
:page-section-summary-toc: 1

ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]

`TerminalUI` is a main implementation to drive ui execution logic.

== Create TerminalUI
You can build `TerminalUI` manually but recommended way is to use `TerminalUIBuilder`
build is autoconfigured for you and will set needed services.

[source, java, indent=0]
----
include::{snippets}/TerminalUiSnippets.java[tag=uibuilderautowire]
----

== Configuring Views
`TerminalUI` has a helper method _configure(View)_ which can be used to set
needed integrations into _eventloop_ and other services.

[source, java, indent=0]
----
include::{snippets}/TerminalUiSnippets.java[tag=configureview]
----

== Running UI Loop
Running `TerminalUI` execution loop is a blocking operation. You're going to need
a way to exit from a loop, for example <<Exiting App>>.

[source, java, indent=0]
----
include::{snippets}/TerminalUiSnippets.java[tag=uirun]
----

== Exiting App

If you want to exit from an app using normal _CTRL-Q_ key combination listen
events and request _interrupt_.

[source, java, indent=0]
----
include::{snippets}/TerminalUiSnippets.java[tag=exitingfromloop]
----

== Modal View

`TerminalUI` supports having one active modal view. Modal view is placed
on top of all other views and takes all input events.

[source, java, indent=0]
----
include::{snippets}/TerminalUiSnippets.java[tag=uimodal]
----

NOTE: As views should not directly know anything about `TerminalUi` and
interface `ViewService` exposes modal related functions.
