Skip to content

Commit ead34d6

Browse files
committed
Update modal docs
- Relates #825
1 parent b7ad099 commit ead34d6

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

spring-shell-core/src/main/java/org/springframework/shell/component/view/control/ViewService.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,25 @@
2424
*/
2525
public interface ViewService {
2626

27+
/**
28+
* Gets a current modal view.
29+
*
30+
* @return current modal view
31+
*/
32+
@Nullable
2733
View getModal();
2834

29-
void setModal(View view);
35+
/**
36+
* Sets a new modal view. Setting modal to {@code null} clears existing modal.
37+
*
38+
* @param view a view to use as modal
39+
*/
40+
void setModal(@Nullable View view);
3041

42+
/**
43+
* Sets a view to be focused. Setting focus to {@code null} clears focused view.
44+
*
45+
* @param view a view to be focused
46+
*/
3147
void setFocus(@Nullable View view);
3248
}

spring-shell-docs/modules/ROOT/pages/tui/intro/terminalui.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,16 @@ events and request _interrupt_.
4141
----
4242
include::{snippets}/TerminalUiSnippets.java[tag=exitingfromloop]
4343
----
44+
45+
== Modal View
46+
47+
`TerminalUI` supports having one active modal view. Modal view is placed
48+
on top of all other views and takes all input events.
49+
50+
[source, java, indent=0]
51+
----
52+
include::{snippets}/TerminalUiSnippets.java[tag=uimodal]
53+
----
54+
55+
NOTE: As views should not directly know anything about `TerminalUi` and
56+
interface `ViewService` exposes modal related functions.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.shell.component.view.TerminalUI;
2323
import org.springframework.shell.component.view.TerminalUIBuilder;
2424
import org.springframework.shell.component.view.control.BoxView;
25+
import org.springframework.shell.component.view.control.DialogView;
2526
import org.springframework.shell.component.view.event.EventLoop;
2627
import org.springframework.shell.component.view.event.KeyEvent.Key;
2728
import org.springframework.shell.geom.HorizontalAlign;
@@ -111,4 +112,19 @@ void sample() {
111112
// end::uirun[]
112113
}
113114

115+
class SampleUiModal {
116+
117+
// tag::uimodal[]
118+
TerminalUI ui;
119+
120+
void sample() {
121+
DialogView dialog = new DialogView();
122+
// set modal
123+
ui.setModal(dialog);
124+
// clear modal
125+
ui.setModal(null);
126+
}
127+
// end::uimodal[]
128+
}
129+
114130
}

0 commit comments

Comments
 (0)