Davidge
Davidge

Reputation: 63

Change the prompt in spring shell at runtime

is it possible to change the prompt in a spring shell application? For default it seems that the prompt is:

shell:>

Is is possible to change this text at runtime?

THX

Upvotes: 2

Views: 1487

Answers (3)

MaduKan
MaduKan

Reputation: 670

What worked for me:

import org.springframework.context.annotation.Configuration;
import org.springframework.shell.jline.PromptProvider;
import org.jline.utils.AttributedString;

@Configuration
public class SpringShellConfiguration implements PromptProvider {
    @Override
    public final AttributedString getPrompt() {
        return new AttributedString("myapp:> ");
    }

}

Reference: https://docs.spring.io/spring-shell/docs/current/api/org/springframework/shell/jline/PromptProvider.html

Upvotes: 0

Davidge
Davidge

Reputation: 63

Thank you for the answer! I've overlooked this feature. I created this class, put it into my configuration-package and it works good for me:

package de.myapp.spring.configuration;

@Configuration
@ComponentScan("de.myapp.spring.shell")
public class ShellApplicationConfiguration implements PromptProvider {

    @Override
    public final AttributedString getPrompt() {

        return new AttributedString("myapp:>");

    }

}

Upvotes: 4

void
void

Reputation: 144

You can define a PromptProvider, see in the Docs: https://docs.spring.io/spring-shell/docs/current-SNAPSHOT/reference/htmlsingle/#_promptprovider

Upvotes: 1

Related Questions