Skip to content

Commit 923498b

Browse files
committed
Update docs
1 parent 8716774 commit 923498b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

spring-shell-docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
*** xref:components/ui/multiselect.adoc[]
5555
* xref:tui/index.adoc[]
5656
** xref:tui/intro/index.adoc[]
57+
*** xref:tui/intro/terminalui.adoc[]
5758
** xref:tui/views/index.adoc[]
5859
*** xref:tui/views/box.adoc[]
5960
*** xref:tui/views/button.adoc[]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
= TerminalUI
2+
:page-section-summary-toc: 1
3+
4+
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]
5+
6+
`TerminalUI` is a main implementation to drive ui execution logic.
7+
Running `TerminalUI` execution loop is a blocking operation.
8+
9+
== Exiting App
10+
11+
If you want to exit from an app using normal _CTRL-Q_ key combination listen
12+
events and request _interrupt_.
13+
14+
[source, java, indent=0]
15+
----
16+
include::{snippets}/TerminalUiSnippets.java[tag=snippet3]
17+
----

spring-shell-docs/src/test/java/org/springframework/shell/docs/TerminalUiSnippets.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import org.springframework.beans.factory.annotation.Autowired;
2121
import org.springframework.shell.component.view.TerminalUI;
2222
import org.springframework.shell.component.view.control.BoxView;
23+
import org.springframework.shell.component.view.event.EventLoop;
24+
import org.springframework.shell.component.view.event.KeyEvent.Key;
2325
import org.springframework.shell.component.view.geom.HorizontalAlign;
2426
import org.springframework.shell.component.view.geom.VerticalAlign;
27+
import org.springframework.shell.component.view.message.ShellMessageBuilder;
2528

2629
class TerminalUiSnippets {
2730

@@ -67,4 +70,26 @@ void sample() {
6770
// end::snippet2[]
6871
}
6972

73+
class Sample3 {
74+
75+
// tag::snippet3[]
76+
@Autowired
77+
Terminal terminal;
78+
79+
void sample() {
80+
TerminalUI ui = new TerminalUI(terminal);
81+
BoxView view = new BoxView();
82+
ui.setRoot(view, true);
83+
EventLoop eventLoop = ui.getEventLoop();
84+
eventLoop.keyEvents()
85+
.subscribe(event -> {
86+
if (event.getPlainKey() == Key.q && event.hasCtrl()) {
87+
eventLoop.dispatch(ShellMessageBuilder.ofInterrupt());
88+
}
89+
});
90+
ui.run();
91+
}
92+
// end::snippet3[]
93+
}
94+
7095
}

0 commit comments

Comments
 (0)