Theming

主题中的样式由 JLine 中的 AttributedString 的用法提供。遗憾的是,JLine 中的样式几乎没有文档说明,不过我们尝试在这里研究一下其部分功能。

Styling in a theming is provided by a use of a AttributedString from JLine. Unfortunately styling in JLine is mostly undocumented but we try to go through some of its features here.

JLine 中,样式规范是一个具有特殊格式的字符串。如果用逗号分隔,规范可以给出多次。规范将为前景色、背景色或其模式定义颜色。如果由于某种原因前者无效,特殊格式 <spec>:=<spec> 允许在后一个规范中定义默认值。

In JLine a style spec is a string having a special format. Spec can be given multiple times if separated by a comma. A spec will either define a color for foreground, background or its mode. Special format <spec>:=<spec> allows to define a default within latter spec if former for some reason is invalid.

如果规范包含冒号,则其前部分表示前景色或背景色,可能的值包括 foregroundfgfbackgroundbgbforeground-rgbfg-rgbf-rgbbackground-rgbbg-rgbb-rgb。如果没有 rgb,颜色值则从允许的颜色 blackredgreenyellowbluemagentacyanwhite 中进行命名。颜色有简写格式 krgybmcw。如果颜色前缀为 !bright-,则自动应用亮模式。使用 ~ 作为前缀将从 JLine 的内部 bsd 颜色表中解析。

If spec contains a colon its former part indicates either foreground or background and possible values are foreground, fg, f, background, bg, b, foreground-rgb, fg-rgb, f-rgb, background-rgb, bg-rgb or b-rgb. Without rbg a color value is name from an allowable colors black, red, green, yellow, blue, magenta, cyan or white. Colors have their short formats k, r, g, y, b, m, c and w respectively. If color is prefixed with either ! or bright-, bright mode is automatically applied. Prefixing with ~ will resolve from JLine internal bsd color table.

如果预计 rgb 格式且前缀为 x#,则使用正常的十六进制格式。

If rgb format is expected and prefixed with either x or # a normal hex format is used.

fg-red
fg-r
fg-rgb:red
fg-rgb:xff3333
fg-rgb:#ff3333

如果规范包含特殊名称 defaultboldfaintitalicunderlineblinkinverseinverse-neginversenegconcealcrossed-outcrossedouthidden,则样式会相应地更改为现有颜色。

If spec contains special names default, bold, faint, italic, underline, blink, inverse, inverse-neg, inverseneg, conceal, crossed-out, crossedout or hidden a style is changed accordingly with an existing color.

bold
bold,fg:red

如果规范是数字或以分号分隔的数字,则格式是 ansiascii 代码中的普通部分。

If spec is a number or numbers separated with semicolon, format is a plain part of an ansi ascii codes.

31
31;1

JLine 特殊映射格式无法解析以点开头的规范,因为我们尚未将其映射到 Spring Shell 样式名称中。

JLine special mapping format which would resolve spec starting with dot can’t be used as we don’t yet map those into Spring Shell styling names.