File tree 3 files changed +35
-3
lines changed
main/java/de/cotto/bitbook/cli
test/java/de/cotto/bitbook/cli
cli-base/src/main/java/de/cotto/bitbook/cli 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change
1
+ package de .cotto .bitbook .cli ;
2
+
3
+ public interface PromptChangeListener {
4
+ void changePrompt (String newState );
5
+
6
+ void changePromptToDefault ();
7
+ }
Original file line number Diff line number Diff line change 6
6
import org .springframework .stereotype .Component ;
7
7
8
8
@ Component
9
- public class CustomPromptProvider implements PromptProvider {
9
+ public class CustomPromptProvider implements PromptProvider , PromptChangeListener {
10
+ private static final String DEFAULT_PROMPT = "BitBook$ " ;
11
+
12
+ private String prompt = DEFAULT_PROMPT ;
10
13
11
14
public CustomPromptProvider () {
12
15
// default constructor
13
16
}
14
17
15
18
@ Override
16
19
public AttributedString getPrompt () {
17
- return new AttributedString ("BitBook$ " , AttributedStyle .DEFAULT .foreground (AttributedStyle .YELLOW ));
20
+ return new AttributedString (prompt , AttributedStyle .DEFAULT .foreground (AttributedStyle .YELLOW ));
21
+ }
22
+
23
+ @ Override
24
+ public void changePrompt (String newPrompt ) {
25
+ prompt = newPrompt ;
18
26
}
19
27
28
+ @ Override
29
+ public void changePromptToDefault () {
30
+ changePrompt (DEFAULT_PROMPT );
31
+ }
20
32
}
Original file line number Diff line number Diff line change @@ -9,7 +9,20 @@ class CustomPromptProviderTest {
9
9
private final CustomPromptProvider customPromptProvider = new CustomPromptProvider ();
10
10
11
11
@ Test
12
- void customPrompt_text () {
12
+ void default_prompt () {
13
+ assertThat (customPromptProvider .getPrompt ()).hasToString ("BitBook$ " );
14
+ }
15
+
16
+ @ Test
17
+ void changePrompt () {
18
+ customPromptProvider .changePrompt ("foo" );
19
+ assertThat (customPromptProvider .getPrompt ()).hasToString ("foo" );
20
+ }
21
+
22
+ @ Test
23
+ void changePromptToDefault () {
24
+ customPromptProvider .changePrompt ("foo" );
25
+ customPromptProvider .changePromptToDefault ();
13
26
assertThat (customPromptProvider .getPrompt ()).hasToString ("BitBook$ " );
14
27
}
15
28
}
You can’t perform that action at this time.
0 commit comments