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
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