Component Render
您可以使用以下两种方式之一实现组件渲染:完全通过编程方式或使用 ANTLR Stringtemplate。严格来说,有一个简单的 Function
呈现器界面,它将 Context
作为输入,并输出 AttributedString
的列表。这允许您在模板化和代码之间进行选择。
You can implement component rendering in either of two ways: fully
programmatically or by using a ANTLR Stringtemplate.
Strictly speaking, there is a simple Function
renderer interface
that takes Context
as an input and outputs a list of AttributedString
.
This lets you choose between templating and code.
如果您不需要执行任何复杂操作,或者您只想稍微修改现有组件布局,那么模板化是一个不错的选择。然后通过代码渲染为您提供了所需的灵活性。
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.
通过编程方式进行渲染是创建 Function
:
The programmatic way to render is to create a Function
:
Unresolved include directive in modules/ROOT/pages/components/ui/render.adoc - include::../../test/java/org/springframework/shell/docs/UiComponentSnippets.java[]
然后,您可以将其连接到组件:
Then you can hook it to a component:
Unresolved include directive in modules/ROOT/pages/components/ui/render.adoc - include::../../test/java/org/springframework/shell/docs/UiComponentSnippets.java[]
组件有自己的上下文,但通常会从父组件类型共享一些功能。以下表格显示了这些上下文变量:
Components have their own context but usually share some functionality from a parent component types. The following tables show those context variables:
Key | Description |
---|---|
|
The value after a component renders its result. |
|
The name of a component — that is, its title. |
|
The possible message set for a component. |
|
The level of a message — one of |
|
Return |
|
Return |
|
Return |
|
The raw user input. |
Key | Description |
---|---|
|
The name of a component — that is, its title. |
|
The raw user input — mostly used for filtering. |
|
The full list of item states. |
|
The visible list of item states. |
|
Return |
|
The current cursor row in a selector. |
Key | Description |
---|---|
|
The width of terminal, type is Integer and defaults to NULL if not set. |