Skip to content

Commit 2bc8a16

Browse files
committed
Fixes matyb#57
1 parent b42576f commit 2bc8a16

5 files changed

Lines changed: 60 additions & 38 deletions

File tree

‎koans/app/config/config.properties‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ exit_character=Q
44
enable_encouragement=false
55
path_xml_filename=PathToEnlightenment.xml
66
enable_expectation_result=true
7+
interactive=true

‎koans/app/lib/koans.jar‎

213 Bytes
Binary file not shown.

‎lib/src/main/java/com/sandwich/koan/ApplicationSettings.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public static boolean isExpectationResultVisible(){
2828
return isEqual(getConfigBundle().getString("enable_expectation_result"), true, true);
2929
}
3030

31+
public static boolean isInteractive(){
32+
return isEqual(getConfigBundle().getString("interactive"), true, true);
33+
}
34+
3135
public static char getExitChar(){
3236
return getConfigBundle().getString("exit_character").charAt(0);
3337
}

‎lib/src/main/java/com/sandwich/koan/runner/AppLauncher.java‎

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,55 @@
1717

1818
public class AppLauncher {
1919

20-
public static void main(final String... args) throws Throwable {
21-
Map<ArgumentType, CommandLineArgument> argsMap = new CommandLineArgumentBuilder(args);
22-
if(argsMap.containsKey(ArgumentType.RUN_KOANS)){
23-
new Thread(new Runnable(){
24-
public void run() {
25-
do{
26-
try {
27-
char c = (char)System.in.read();
28-
if(Character.toUpperCase(c) ==
29-
Character.toUpperCase(ApplicationSettings.getExitChar())){
30-
FileMonitorFactory.closeAll();
31-
System.exit(0);
32-
}
33-
} catch (IOException e) {
34-
throw new RuntimeException(e);
35-
}
36-
}while(true);
37-
}
38-
}).start();
39-
FileMonitor monitor = FileMonitorFactory.getInstance(
40-
new File(DirectoryManager.getProdMainDir()),
41-
new File(DirectoryManager.getDataFile()));
42-
if(ApplicationUtils.isFirstTimeAppHasBeenRun()){
43-
monitor.writeChanges();
44-
}
45-
monitor.addFileSavedListener(new KoanFileCompileAndRunListener(argsMap));
46-
}
47-
new CommandLineArgumentRunner(argsMap).run();
48-
if(ApplicationSettings.isDebug()){
49-
StringBuilder argsBuilder = new StringBuilder();
50-
int argNumber = 0;
51-
for(String arg : args){
52-
argsBuilder.append("Argument number "+String.valueOf(++argNumber)+": '"+arg+"'");
53-
}
54-
ApplicationUtils.getPresenter().displayMessage(argsBuilder.toString());
55-
}
56-
}
20+
public static void main(final String... args) throws Throwable {
21+
Map<ArgumentType, CommandLineArgument> argsMap = new CommandLineArgumentBuilder(
22+
args);
23+
if (argsMap.containsKey(ArgumentType.RUN_KOANS)) {
24+
if (ApplicationSettings.isInteractive()) {
25+
new Thread(new Runnable() {
26+
public void run() {
27+
do {
28+
try {
29+
char c = (char) System.in.read();
30+
char exitChar = ApplicationSettings.getExitChar();
31+
if (Character.toUpperCase(c) == Character.toUpperCase(exitChar)) {
32+
exit();
33+
}
34+
} catch (IOException e) {
35+
throw new RuntimeException(e);
36+
}
37+
} while (true);
38+
}
39+
40+
}).start();
41+
FileMonitor monitor = FileMonitorFactory.getInstance(new File(
42+
DirectoryManager.getProdMainDir()), new File(
43+
DirectoryManager.getDataFile()));
44+
if (ApplicationUtils.isFirstTimeAppHasBeenRun()) {
45+
monitor.writeChanges();
46+
}
47+
monitor.addFileSavedListener(new KoanFileCompileAndRunListener(argsMap));
48+
}
49+
}
50+
new CommandLineArgumentRunner(argsMap).run();
51+
if (ApplicationSettings.isDebug()) {
52+
StringBuilder argsBuilder = new StringBuilder();
53+
int argNumber = 0;
54+
for (String arg : args) {
55+
argsBuilder.append("Argument number "
56+
+ String.valueOf(++argNumber) + ": '" + arg + "'");
57+
}
58+
ApplicationUtils.getPresenter().displayMessage(
59+
argsBuilder.toString());
60+
}
61+
if (!ApplicationSettings.isInteractive()) {
62+
exit();
63+
}
64+
}
65+
66+
private static void exit() {
67+
FileMonitorFactory.closeAll();
68+
System.exit(0);
69+
}
70+
5771
}

‎lib/src/main/java/com/sandwich/koan/ui/ConsolePresenter.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ protected void displayPassingFailing(KoanSuiteResult result) {
3131
StringBuilder sb = new StringBuilder();
3232
appendLabeledClassesList(Strings.getMessage("passing_suites")+":", result.getPassingSuites(), sb);
3333
appendLabeledClassesList(Strings.getMessage("remaining_suites")+":", result.getRemainingSuites(), sb);
34-
sb.append(EOL).append("Edit & save a koan to reload or enter '"+ ApplicationSettings.getExitChar() +"' to exit");
34+
sb.append(EOL).append("Edit & save a koan").append(
35+
ApplicationSettings.isInteractive() ?
36+
" to test your progress, or enter '" + ApplicationSettings.getExitChar() +"' to exit." :
37+
", then rerun to test your progress");
3538
displayMessage(sb.toString());
3639
}
3740

0 commit comments

Comments
 (0)