Skip to content

Commit db3f677

Browse files
committed
Update docs
1 parent 82df453 commit db3f677

File tree

7 files changed

+160
-38
lines changed

7 files changed

+160
-38
lines changed

spring-shell-docs/modules/ROOT/pages/tui/events/key.adoc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44

55
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]
66

7-
tbd
7+
Views have their own default bindings which can be changed.
8+
9+
You can subscribe into all key events:
10+
11+
[source, java, indent=0]
12+
----
13+
include::{snippets}/KeyHandlingSnippets.java[tag=sample]
14+
----
15+
16+
`KeyEvent` is a record containing info about a binding coming out
17+
from a terminal.

spring-shell-docs/modules/ROOT/pages/tui/events/mouse.adoc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44

55
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]
66

7-
tbd
7+
You can subscribe into all mouse events:
8+
9+
[source, java, indent=0]
10+
----
11+
include::{snippets}/MouseHandlingSnippets.java[tag=sample]
12+
----
13+
14+
`MouseEvent` is a record wrapping _x_ and _Y_ coordinates and
15+
`org.jline.terminal.MouseEvent` from JLine library.

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/she
77
Lets start with a simple app which prints "hello world" in a view.
88
[source, java, indent=0]
99
----
10-
include::{snippets}/TerminalUiSnippets.java[tag=snippet1]
10+
include::{snippets}/TerminalUiSnippets.java[tag=introsample]
1111
----
1212

1313
There is not much to see here other than `TerminalUI` is a class handling
1414
all logic aroung views and uses `View` as it's root view.
15-
16-
[source, java, indent=0]
17-
----
18-
include::{snippets}/TerminalUiSnippets.java[tag=snippet2]
19-
----

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,33 @@
44
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]
55

66
`TerminalUI` is a main implementation to drive ui execution logic.
7-
Running `TerminalUI` execution loop is a blocking operation.
7+
8+
== Create TerminalUI
9+
You can build `TerminalUI` manually but recommended way is to use `TerminalUIBuilder`
10+
build is autoconfigured for you and will set needed services.
11+
12+
[source, java, indent=0]
13+
----
14+
include::{snippets}/TerminalUiSnippets.java[tag=uibuilderautowire]
15+
----
16+
17+
== Configuring Views
18+
`TerminalUI` has a helper method _configure(View)_ which can be used to set
19+
needed integrations into _eventloop_ and other services.
20+
21+
[source, java, indent=0]
22+
----
23+
include::{snippets}/TerminalUiSnippets.java[tag=configureview]
24+
----
25+
26+
== Running UI Loop
27+
Running `TerminalUI` execution loop is a blocking operation. You're going to need
28+
a way to exit from a loop, for example <<Exiting App>>.
29+
30+
[source, java, indent=0]
31+
----
32+
include::{snippets}/TerminalUiSnippets.java[tag=uirun]
33+
----
834

935
== Exiting App
1036

@@ -13,5 +39,5 @@ events and request _interrupt_.
1339

1440
[source, java, indent=0]
1541
----
16-
include::{snippets}/TerminalUiSnippets.java[tag=snippet3]
42+
include::{snippets}/TerminalUiSnippets.java[tag=exitingfromloop]
1743
----
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.shell.docs;
17+
18+
import org.springframework.shell.component.view.event.EventLoop;
19+
import org.springframework.shell.component.view.event.KeyEvent;
20+
21+
class KeyHandlingSnippets {
22+
23+
EventLoop eventLoop;
24+
25+
void dump1() {
26+
// tag::sample[]
27+
eventLoop.keyEvents().subscribe((KeyEvent event) -> {
28+
// do something with key event
29+
});
30+
// end::sample[]
31+
}
32+
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.shell.docs;
17+
18+
import org.springframework.shell.component.view.event.EventLoop;
19+
import org.springframework.shell.component.view.event.MouseEvent;
20+
21+
class MouseHandlingSnippets {
22+
23+
EventLoop eventLoop;
24+
25+
void dump1() {
26+
// tag::sample[]
27+
eventLoop.mouseEvents().subscribe((MouseEvent event) -> {
28+
// do something with mouse event
29+
});
30+
// end::sample[]
31+
}
32+
33+
}

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

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.springframework.beans.factory.annotation.Autowired;
2121
import org.springframework.shell.component.message.ShellMessageBuilder;
2222
import org.springframework.shell.component.view.TerminalUI;
23+
import org.springframework.shell.component.view.TerminalUIBuilder;
2324
import org.springframework.shell.component.view.control.BoxView;
2425
import org.springframework.shell.component.view.event.EventLoop;
2526
import org.springframework.shell.component.view.event.KeyEvent.Key;
@@ -28,14 +29,14 @@
2829

2930
class TerminalUiSnippets {
3031

31-
class Sample1 {
32+
class SampleIntro {
3233

33-
// tag::snippet1[]
34+
// tag::introsample[]
3435
@Autowired
35-
Terminal terminal;
36+
TerminalUIBuilder builder;
3637

3738
void sample() {
38-
TerminalUI ui = new TerminalUI(terminal);
39+
TerminalUI ui = builder.build();
3940
BoxView view = new BoxView();
4041
view.setDrawFunction((screen, rect) -> {
4142
screen.writerBuilder()
@@ -46,33 +47,12 @@ void sample() {
4647
ui.setRoot(view, true);
4748
ui.run();
4849
}
49-
// end::snippet1[]
50-
}
51-
52-
class Sample2 {
53-
54-
// tag::snippet2[]
55-
@Autowired
56-
Terminal terminal;
57-
58-
void sample() {
59-
TerminalUI ui = new TerminalUI(terminal);
60-
BoxView view = new BoxView();
61-
view.setDrawFunction((screen, rect) -> {
62-
screen.writerBuilder()
63-
.build()
64-
.text("Hello World", rect, HorizontalAlign.CENTER, VerticalAlign.CENTER);
65-
return rect;
66-
});
67-
ui.setRoot(view, false);
68-
ui.run();
69-
}
70-
// end::snippet2[]
50+
// end::introsample[]
7151
}
7252

7353
class Sample3 {
7454

75-
// tag::snippet3[]
55+
// tag::exitingfromloop[]
7656
@Autowired
7757
Terminal terminal;
7858

@@ -89,7 +69,44 @@ void sample() {
8969
});
9070
ui.run();
9171
}
92-
// end::snippet3[]
72+
// end::exitingfromloop[]
73+
}
74+
75+
@SuppressWarnings("unused")
76+
class SampleUiAutowire {
77+
78+
// tag::uibuilderautowire[]
79+
@Autowired
80+
TerminalUIBuilder builder;
81+
82+
void sample() {
83+
TerminalUI ui = builder.build();
84+
// do something with ui
85+
}
86+
// end::uibuilderautowire[]
87+
}
88+
89+
class SampleConfigureView {
90+
91+
// tag::configureview[]
92+
TerminalUI ui;
93+
94+
void sample() {
95+
BoxView view = new BoxView();
96+
ui.configure(view);
97+
}
98+
// end::configureview[]
99+
}
100+
101+
class SampleUiLoop {
102+
103+
// tag::uirun[]
104+
TerminalUI ui;
105+
106+
void sample() {
107+
ui.run();
108+
}
109+
// end::uirun[]
93110
}
94111

95112
}

0 commit comments

Comments
 (0)