カスタムプロンプト

Spring Shell は、シェルのプロンプトと出力の外観をカスタマイズするさまざまな方法を提供します。

JLine ベースのシェルを Spring Boot で使用する場合、PromptProvider インターフェースを実装することでシェルプロンプトをカスタマイズできます。これにより、独自のプロンプト形式を定義できます。

Spring Boot アプリケーションでカスタムプロンプトを作成する方法の例を次に示します。

@SpringBootApplication
static class SpringShellApplication {

	@Command
	public void hi() {
		System.out.println("Hello world!");
	}

	@Bean
	public PromptProvider myPromptProvider() {
		return () -> new AttributedString("myprompt:>", AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW));
	}

}

Adding the above PromptProvider bean will change the shell prompt to "myprompt:>" displayed in yellow color.