Skip to content

Commit 42727a2

Browse files
committed
Add system properties for JLineConsole's input thread waiting strategy.
The default is blocking on Windows and 10ms of sleep on other OSes. Add a system property to override OS detection for the purpose of determining how our thread should wait for input. Also add a property to override the waiting strategy directly.
1 parent 2fec581 commit 42727a2

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/main/java/com/flowpowered/commons/console/JLineConsole.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@
4949
public class JLineConsole {
5050
public static final int INPUT_THREAD_YIELD = -1;
5151
public static final int INPUT_THREAD_BLOCK = -2;
52-
public static final int INPUT_THREAD_DEFAULT = SystemUtils.IS_OS_WINDOWS ? INPUT_THREAD_BLOCK : 10;
52+
public static final int INPUT_THREAD_DEFAULT = Integer.getInteger("com.flowpowered.commons.console.inThreadSleepTime", isWindows() ? INPUT_THREAD_BLOCK : 10);
53+
54+
protected static boolean isWindows() {
55+
String prop = System.getProperty("com.flowpowered.commons.console.forceOs");
56+
if (prop != null) {
57+
prop = prop.toLowerCase();
58+
if (prop.contains("windows")) {
59+
return true;
60+
}
61+
if (prop.contains("unix")) {
62+
return false;
63+
}
64+
}
65+
return SystemUtils.IS_OS_WINDOWS;
66+
}
5367

5468
private final ConsoleReader reader;
5569
private final AtomicBoolean closed = new AtomicBoolean(false);
@@ -72,7 +86,7 @@ public JLineConsole(CommandCallback callback, Completer completer, Logger logger
7286
public JLineConsole(CommandCallback callback, Completer completer, Logger logger, OutputStream out, InputStream in) {
7387
this(callback, completer, logger, INPUT_THREAD_DEFAULT, out, in);
7488
}
75-
89+
7690
public JLineConsole(CommandCallback callback, Completer completer, Logger logger, int inThreadSleepTime, OutputStream out, InputStream in) {
7791
this.callback = callback;
7892
if (logger == null) {
@@ -86,7 +100,7 @@ public JLineConsole(CommandCallback callback, Completer completer, Logger logger
86100
if (in == null) {
87101
in = new FileInputStream(FileDescriptor.in);
88102
}
89-
103+
90104
if (inThreadSleepTime != INPUT_THREAD_BLOCK) {
91105
in = new InterruptableInputStream(in, inThreadSleepTime);
92106
}

0 commit comments

Comments
 (0)