Update docs
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
*** xref:components/ui/multiselect.adoc[]
|
||||
* xref:tui/index.adoc[]
|
||||
** xref:tui/intro/index.adoc[]
|
||||
*** xref:tui/intro/terminalui.adoc[]
|
||||
** xref:tui/views/index.adoc[]
|
||||
*** xref:tui/views/box.adoc[]
|
||||
*** xref:tui/views/button.adoc[]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
= 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.
|
||||
Running `TerminalUI` execution loop is a blocking operation.
|
||||
|
||||
== 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=snippet3]
|
||||
----
|
||||
@@ -20,8 +20,11 @@ import org.jline.terminal.Terminal;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.shell.component.view.TerminalUI;
|
||||
import org.springframework.shell.component.view.control.BoxView;
|
||||
import org.springframework.shell.component.view.event.EventLoop;
|
||||
import org.springframework.shell.component.view.event.KeyEvent.Key;
|
||||
import org.springframework.shell.component.view.geom.HorizontalAlign;
|
||||
import org.springframework.shell.component.view.geom.VerticalAlign;
|
||||
import org.springframework.shell.component.view.message.ShellMessageBuilder;
|
||||
|
||||
class TerminalUiSnippets {
|
||||
|
||||
@@ -67,4 +70,26 @@ class TerminalUiSnippets {
|
||||
// end::snippet2[]
|
||||
}
|
||||
|
||||
class Sample3 {
|
||||
|
||||
// tag::snippet3[]
|
||||
@Autowired
|
||||
Terminal terminal;
|
||||
|
||||
void sample() {
|
||||
TerminalUI ui = new TerminalUI(terminal);
|
||||
BoxView view = new BoxView();
|
||||
ui.setRoot(view, true);
|
||||
EventLoop eventLoop = ui.getEventLoop();
|
||||
eventLoop.keyEvents()
|
||||
.subscribe(event -> {
|
||||
if (event.getPlainKey() == Key.q && event.hasCtrl()) {
|
||||
eventLoop.dispatch(ShellMessageBuilder.ofInterrupt());
|
||||
}
|
||||
});
|
||||
ui.run();
|
||||
}
|
||||
// end::snippet3[]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user