File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
src/test/java/org/springframework/shell/docs Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 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[]
Original file line number Diff line number Diff line change 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+ ----
Original file line number Diff line number Diff line change 2020import org .springframework .beans .factory .annotation .Autowired ;
2121import org .springframework .shell .component .view .TerminalUI ;
2222import 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 ;
2325import org .springframework .shell .component .view .geom .HorizontalAlign ;
2426import org .springframework .shell .component .view .geom .VerticalAlign ;
27+ import org .springframework .shell .component .view .message .ShellMessageBuilder ;
2528
2629class 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}
You can’t perform that action at this time.
0 commit comments