Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spring-shell-docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* xref:index.adoc[Overview]
* xref:getting-started.adoc[]
* xref:ide.adoc[Developing with an IDE]
* xref:upgrading.adoc[]
* xref:basics/index.adoc[]
** xref:basics/reading.adoc[]
Expand Down Expand Up @@ -67,4 +68,4 @@
** xref:appendices/debugging/index.adoc[]
** xref:appendices/tui/index.adoc[]
*** xref:appendices/tui/viewdev.adoc[]
* xref:api:attachment$index.html[Javadoc,role=link-external,window=_blank].
* xref:api:attachment$index.html[Javadoc,role=link-external,window=_blank].
20 changes: 20 additions & 0 deletions spring-shell-docs/modules/ROOT/pages/components/ui/render.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ Templating is a good choice if you do not need to do anything complex or
you just want to slightly modify existing component layouts. Rendering
through code then gives you flexibility to do whatever you need.

== Customizing a component template

Built-in component templates are loaded from the
`org/springframework/shell/component` classpath location. To customize one, add a template with
the same name to your application's resources. For example, a custom String Input template can be
created at `src/main/resources/org/springframework/shell/component/string-input-default.stg`:

[source, antlrv4]
----
main(model) ::= <<
<model.name; format="style-title">: <model.input; format="style-value">
>>
----

The template receives the component context as `model`. The available attributes depend on the
component; for example, `StringInputContext` provides `name`, `input`, `resultValue`,
`defaultValue`, `maskedInput`, and `maskedResultValue`. See the component-specific page for its
complete context table. Keep the original template's `main` entry point when replacing a built-in
template.

The programmatic way to render is to create a `Function`:

[source, java, indent=0]
Expand Down
13 changes: 13 additions & 0 deletions spring-shell-docs/modules/ROOT/pages/getting-started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ Exiting the shell

Congratulations, you have created and run your first Spring Shell application!

[[creating-a-component]]
== Creating a component

For interactive prompts, use one of the built-in components such as `StringInput` or
`SingleItemSelector`. Components can be composed in a `ComponentFlow`, rendered with a custom
`Function`, or customized with a StringTemplate resource. See xref:components/ui/index.adoc[Flow
Components] and xref:components/ui/render.adoc[Component Render] for examples and context
variables.

When developing a component-based shell in an IDE, run the application with the same classpath and
working directory as the Maven command. IDE launchers that omit `src/main/resources` will not find
component templates, and launching without a terminal may prevent interactive key handling.

[[next-steps]]
== Next Steps

Expand Down
20 changes: 20 additions & 0 deletions spring-shell-docs/modules/ROOT/pages/ide.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[ide-support]]
= Developing with an IDE

Spring Shell applications can be started from an IDE, but interactive components need a real
terminal and the application's runtime resources must be on the classpath.

== Checklist

When an application behaves differently from `./mvnw spring-boot:run`, check the following:

* Use the same Java version and active profile as the command-line launch.
* Set the working directory to the application project directory.
* Include `src/main/resources` so component templates and configuration files are available.
* Run the application in a terminal-capable console when using interactive components or key
bindings.
* Stop any previously running shell before starting a second instance on the same port.

The IDE does not change Spring Shell's component APIs. If a prompt cannot read keys, first compare
the IDE's console and environment settings with a command-line run before changing the component
implementation.