Skip to content

Commit 50691a8

Browse files
committed
feat: adding documentation
Signed-off-by: Nicola Di Falco <[email protected]>
1 parent 6a5139f commit 50691a8

File tree

6 files changed

+123
-3
lines changed

6 files changed

+123
-3
lines changed

spring-shell-core/src/test/resources/org/springframework/shell/component/number-input-default.stg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ info(model) ::= <%
1414
<if(model.input)>
1515
<model.input>
1616
<else>
17-
<if(model.required)>
18-
<("[Required]"); format="style-value">
19-
<endif>
2017
<("[Number Type: "); format="style-value"><model.defaultClass; format="style-value"><("]"); format="style-value">
2118
<if(model.defaultValue)>
2219
<("[Default "); format="style-value"><model.defaultValue; format="style-value"><("]"); format="style-value">
20+
<elseif(model.required)>
21+
<("[Required]"); format="style-value">
2322
<endif>
2423
<endif>
2524
%>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{"version":2,"width":120,"height":9,"timestamp":1691400709,"env":{"TERM":"ms-terminal","SHELL":"powershell.exe"}}
2+
[1.1047019958496094,"o","\u001b[25l\u001b[m\u001b[93m\u001b[jjava\u001b[m \u001b[90m-jar\u001b[m spring-shell-samples/target/spring-shell-samples-2.1.13-SNAPSHOT.jar\u001b[?25h"]
3+
[1.7505860328674316,"o","\r\n"]
4+
[4.510409593582153,"o","\u001b[?2004h\u001b[33mmy-shell:>"]
5+
[4.519921541213989,"o","\u001b[m"]
6+
[5.577335357666016,"o","\u001b[31mc"]
7+
[5.591983318328857,"o","\u001b[m"]
8+
[5.846746921539307,"o","\u001b[31mo"]
9+
[5.857876777648926,"o","\u001b[m"]
10+
[5.96783971786499,"o","\u001b[31mm"]
11+
[5.98032808303833,"o","\u001b[m"]
12+
[6.270904302597046,"o","\u001b[31mp"]
13+
[6.293165922164917,"o","\u001b[m"]
14+
[6.335582733154297,"o","\u001b[31mo"]
15+
[6.355441093444824,"o","\u001b[m"]
16+
[6.671180009841919,"o","\u001b[31mn"]
17+
[6.684344053268433,"o","\u001b[m"]
18+
[6.855102300643921,"o","\u001b[31me"]
19+
[6.872071743011475,"o","\u001b[m"]
20+
[6.998976230621338,"o","\u001b[31mn"]
21+
[7.0131447315216064,"o","\u001b[m"]
22+
[7.159230947494507,"o","\u001b[31mt"]
23+
[7.1707377433776855,"o","\u001b[m"]
24+
[7.230209112167358,"o","\u001b[31m "]
25+
[7.248788356781006,"o","\u001b[m"]
26+
[7.406573534011841,"o","\u001b[31mn"]
27+
[7.420743227005005,"o","\u001b[m"]
28+
[7.679130554199219,"o","\u001b[31mu"]
29+
[7.699283123016357,"o","\u001b[m"]
30+
[8.135498523712158,"o","\u001b[31mm"]
31+
[8.153958559036255,"o","\u001b[m"]
32+
[8.374905347824097,"o","\u001b[31mb"]
33+
[8.38698434829712,"o","\u001b[m"]
34+
[8.527199268341064,"o","\u001b[31me"]
35+
[8.543792724609375,"o","\u001b[m"]
36+
[8.719360589981079,"o","\u001b[25l\u001b[2;11H\u001b[?25h"]
37+
[8.731481313705444,"o","\u001b[1m\u001b[97mcomponent number\u001b[m\u001b[K"]
38+
[8.814936637878418,"o"," "]
39+
[8.982696294784546,"o","d"]
40+
[9.087361097335815,"o","o"]
41+
[9.151376247406006,"o","u"]
42+
[9.383987665176392,"o","b"]
43+
[9.574780225753784,"o","l"]
44+
[9.70450234413147,"o","\u001b[25l\u001b[2;27H\u001b[?25h"]
45+
[9.718122243881226,"o","\u001b[1m\u001b[97m double\u001b[m\u001b[K"]
46+
[9.928346157073975,"o","\r"]
47+
[9.95093560218811,"o","\u001b[?2004l\r\n"]
48+
[10.007387638092041,"o","\u001b[?25l"]
49+
[10.075207471847534,"o","\u001b[1m\u001b[92m?\u001b[m \u001b[1m\u001b[97mEnter value\u001b[m \u001b[34m[Number Type: Double][Default \u001b[m99.9\u001b[34m]"]
50+
[10.091434478759766,"o","\u001b[m"]
51+
[12.732241153717041,"o","\u001b[3;15H5\u001b[70X\u001b[70C\u001b[K\u001b[35C"]
52+
[13.092545509338379,"o","\u001b[3;16H.\u001b[70X\u001b[70C\u001b[K\u001b[34C"]
53+
[13.577228307723999,"o","\u001b[3;17H5\u001b[70X\u001b[70C\u001b[K\u001b[33C"]
54+
[14.40083646774292,"o","\u001b[?2004h\u001b[1m\u001b[92m\r?\u001b[m \u001b[1m\u001b[97mEnter value\u001b[m \u001b[34m5.5\u001b[m\u001b[K\r\nGot value 5.5\u001b[K\u001b[33m\r\nmy-shell:>\u001b[m\u001b[K\u001b[?25h"]
55+
[15.966568946838379,"o","\u001b[31m"]

spring-shell-docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
** xref:components/ui/index.adoc[]
4949
*** xref:components/ui/render.adoc[]
5050
*** xref:components/ui/stringinput.adoc[]
51+
*** xref:components/ui/numberinput.adoc[]
5152
*** xref:components/ui/pathinput.adoc[]
5253
*** xref:components/ui/pathsearch.adoc[]
5354
*** xref:components/ui/confirmation.adoc[]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[[using-shell-components-ui-numberinput]]
2+
= Number Input
3+
4+
ifndef::snippets[:snippets: ../../../../../src/test/java/org/springframework/shell/docs]
5+
6+
The number input component asks a user for simple number input. It can be configured to use any implementation of Number.class. The following listing shows an example:
7+
8+
[source, java, indent=0]
9+
----
10+
include::{snippets}/UiComponentSnippets.java[tag=snippet10]
11+
----
12+
13+
The following image shows typical output from a number input component:
14+
15+
[asciinema,rows=6]
16+
----
17+
include::example$component-number-input-1.cast[]
18+
----
19+
20+
The context object is `NumberInputContext`. The following table lists its context variables:
21+
22+
[[numberinputcontext-template-variables]]
23+
.NumberInputContext Template Variables
24+
|===
25+
|Key |Description
26+
27+
|`defaultValue`
28+
|The default value, if set. Otherwise, null.
29+
30+
|`defaultClass`
31+
|The default number class to use, if set. Otherwise, Integer.class.
32+
33+
|`required`
34+
|`true` if the input is required. Otherwise, false.
35+
36+
|`model`
37+
|The parent context variables (see xref:components/ui/render.adoc#textcomponentcontext-template-variables[TextComponentContext Template Variables]).
38+
|===

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public void runFlow() {
4646
.withStringInput("field2")
4747
.name("Field2")
4848
.and()
49+
.withNumberInput("number1")
50+
.name("Number1")
51+
.and()
52+
.withNumberInput("number2")
53+
.name("Number2")
54+
.defaultValue(20.5)
55+
.numberClass(Double.class)
56+
.and()
4957
.withConfirmationInput("confirmation1")
5058
.name("Confirmation1")
5159
.and()

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.springframework.shell.core.commands.AbstractCommand;
3030
import org.springframework.shell.core.tui.component.ConfirmationInput;
3131
import org.springframework.shell.core.tui.component.MultiItemSelector;
32+
import org.springframework.shell.core.tui.component.NumberInput;
33+
import org.springframework.shell.core.tui.component.NumberInput.NumberInputContext;
3234
import org.springframework.shell.core.tui.component.PathInput;
3335
import org.springframework.shell.core.tui.component.PathSearch;
3436
import org.springframework.shell.core.tui.component.SingleItemSelector;
@@ -264,4 +266,21 @@ public String pathSearch() {
264266

265267
}
266268

269+
class Dump9 {
270+
@Command
271+
public class ComponentCommands extends AbstractCommand {
272+
273+
@Command(command = "component number", description = "Number input", group = "Components")
274+
public String numberInput() {
275+
// tag::snippet10[]
276+
NumberInput component = new NumberInput(getTerminal(), "Enter value", 99.9, Double.class);
277+
component.setResourceLoader(getResourceLoader());
278+
component.setTemplateExecutor(getTemplateExecutor());
279+
280+
NumberInputContext context = component.run(NumberInputContext.empty());
281+
return "Got value " + context.getResultValue();
282+
// end::snippet10[]
283+
}
284+
}
285+
}
267286
}

0 commit comments

Comments
 (0)