This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.3.3! |
TerminalUI
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.
@Autowired
TerminalUIBuilder builder;
void sample() {
TerminalUI ui = builder.build();
// do something with ui
}
Configuring Views
TerminalUI
has a helper method configure(View) which can be used to set
needed integrations into eventloop and other services.
TerminalUI ui;
void sample() {
BoxView view = new BoxView();
ui.configure(view);
}
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.
TerminalUI ui;
void sample() {
ui.run();
}
Exiting App
If you want to exit from an app using normal CTRL-Q key combination listen events and request interrupt.
@Autowired
Terminal terminal;
void sample() {
TerminalUI ui = new TerminalUI(terminal);
BoxView view = new BoxView();
ui.configure(view);
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();
}
Modal View
TerminalUI
supports having one active modal view. Modal view is placed
on top of all other views and takes all input events.
TerminalUI ui;
void sample() {
DialogView dialog = new DialogView();
// set modal
ui.setModal(dialog);
// clear modal
ui.setModal(null);
}
As views should not directly know anything about TerminalUi and
interface ViewService exposes modal related functions.
|