Theming

当前终端实现中的功能非常丰富,通常可以呈现一些比纯文本更多的东西。例如,可以设置文本样式为 bold 或者使用不同的颜色。终端还可以从 unicode 表中显示各种字符(如表情符号),通常这些字符用于使 shell 输出更漂亮。

Current terminal implementations are rich in features and can usually show something else that just plain text. For example a text can be styled to be bold or have different colors. It’s also common for terminals to be able to show various characters from an unicode table like emoji’s which are usually used to make shell output more pretty.

Spring Shell 通过其主题框架支持这些功能,该框架包含两个部分,首先,styling 可用于更改文本类型,其次,figures 可用于更改某些字符的显示方式。然后,将这两部分组合在一起作为 theme

Spring Shell supports these via it’s theming framework which contains two parts, firstly styling can be used to change text type and secondly figures how some characters are shown. These two are then combined together as a theme.

有关 theming 内部机制的更多信息,请参见 Theming

More about theming internals, see Theming.

默认主题名为`default`,但可以使用属性`spring.shell.theme.name`进行更改。其他内置主题名为`dump`,它不使用任何颜色样式且尽量不用任何特殊样式。

Default theme is named default but can be change using property spring.shell.theme.name. Other built-in theme named dump uses no styling for colors and tries to not use any special figures.

通过覆盖设置修改现有样式。

Modify existing style by overriding settings.

Unresolved include directive in modules/ROOT/pages/customization/styling.adoc - include::../../../../src/test/java/org/springframework/shell/docs/ThemingSnippets.java[]

通过覆盖设置修改现有数字。

Modify existing figures by overriding settings.

Unresolved include directive in modules/ROOT/pages/customization/styling.adoc - include::../../../../src/test/java/org/springframework/shell/docs/ThemingSnippets.java[]

要创建一个新主题,创建一个 ThemeSettings,并提供你自己的 stylefigure 实现。

To create a new theme, create a ThemeSettings and provide your own style and figure implementations.

Unresolved include directive in modules/ROOT/pages/customization/styling.adoc - include::../../../../src/test/java/org/springframework/shell/docs/ThemingSnippets.java[]

注册一个新的 Bean Theme,你可以在其中返回你的自定义 ThemeSettingstheme 名称。

Register a new bean Theme where you can return your custom ThemeSettings and a theme name.

Unresolved include directive in modules/ROOT/pages/customization/styling.adoc - include::../../../../src/test/java/org/springframework/shell/docs/ThemingSnippets.java[]

你可以使用 ThemeResolver 来解析 styles,如果你想以编程方式创建 JLine 风格的字符串,或者 figures 如果你想对字符进行主题化处理以使其更美观。

You can use ThemeResolver to resolve styles if you want to create JLine-styled strings programmatically and figures if you want to theme characters for being more pretty.

Unresolved include directive in modules/ROOT/pages/customization/styling.adoc - include::../../../../src/test/java/org/springframework/shell/docs/ThemingSnippets.java[]