Theming

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

More about theming internals, see Theming.

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.

static class MyStyleSettings extends StyleSettings {

	@Override
	public String highlight() {
		return super.highlight();
	}
}

Modify existing figures by overriding settings.

static class MyFigureSettings extends FigureSettings {

	@Override
	public String error() {
		return super.error();
	}
}

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

static class MyThemeSettings extends ThemeSettings {

	@Override
	public StyleSettings styles() {
		return new MyStyleSettings();
	}

	@Override
	public FigureSettings figures() {
		return new MyFigureSettings();
	}
}

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

@Configuration
static class CustomThemeConfig {

	@Bean
	Theme myTheme() {
		return new Theme() {
			@Override
			public String getName() {
				return "mytheme";
			}

			@Override
			public ThemeSettings getSettings() {
				return new MyThemeSettings();
			}
		};
	}
}

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.

@Autowired
private ThemeResolver resolver;

void resolve() {
	String resolvedStyle = resolver.resolveStyleTag(StyleSettings.TAG_TITLE);
	// bold,fg:bright-white

	AttributedStyle style = resolver.resolveStyle(resolvedStyle);
	// jline attributed style from expression above

	String resolvedFigure = resolver.resolveFigureTag(FigureSettings.TAG_ERROR);
	// character i.e. U+2716 Heavy Multiplication X Emoji, cross
}