Wednesday 17 February 2021

Spring Shell: Customizing prompt name

By default, spring shell application gives the prompt name as ‘shell:>’. We can customize this name by implementing PromptProvider interface.

import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStyle;
import org.springframework.shell.jline.PromptProvider;
import org.springframework.stereotype.Component;

@Component
public class MyPromptProvider implements PromptProvider {

	@Override
	public AttributedString getPrompt() {
		return new AttributedString("CLI-DEMO-PROMPT:>", AttributedStyle.DEFAULT.foreground(AttributedStyle.BLUE));
	}

}

 

Once you ran above application, you will see the prompt name as ‘CLI-DEMO-PROMPT:>’.

 

You can download complete working application from this link.

https://github.com/harikrishna553/springboot/tree/master/shell/hello-world

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment