Skip to content

Commit d4bf37c

Browse files
authored
Add forced-out and forcer-err to force the system console to use the output / error stream (fixes #856) (#884)
JLine tries to detect a valid output stream, but in cases where output is redirected using a tee command, the output stream is valid, even if not a real system stream. Using builder.setSystemOutput(SystemOutput.ForcedSysOut) or using `org.jline.terminal.output=forced-out` system property solves the problem.
1 parent b8084cf commit d4bf37c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

terminal/src/main/java/org/jline/terminal/TerminalBuilder.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public final class TerminalBuilder {
7070
public static final String PROP_OUTPUT_ERR = "err";
7171
public static final String PROP_OUTPUT_OUT_ERR = "out-err";
7272
public static final String PROP_OUTPUT_ERR_OUT = "err-out";
73+
public static final String PROP_OUTPUT_FORCED_OUT = "forced-out";
74+
public static final String PROP_OUTPUT_FORCED_ERR = "forced-err";
7375

7476
//
7577
// Other system properties controlling various jline parts
@@ -106,7 +108,9 @@ public enum SystemOutput {
106108
SysOut,
107109
SysErr,
108110
SysOutOrSysErr,
109-
SysErrOrSysOut
111+
SysErrOrSysOut,
112+
ForcedSysOut,
113+
ForcedSysErr
110114
}
111115

112116
/**
@@ -560,6 +564,12 @@ public SystemOutput computeSystemOutput() {
560564
case PROP_OUTPUT_ERR_OUT:
561565
systemOutput = SystemOutput.SysErrOrSysOut;
562566
break;
567+
case PROP_OUTPUT_FORCED_OUT:
568+
systemOutput = SystemOutput.ForcedSysOut;
569+
break;
570+
case PROP_OUTPUT_FORCED_ERR:
571+
systemOutput = SystemOutput.ForcedSysErr;
572+
break;
563573
default:
564574
Log.debug("Unsupported value for " + PROP_OUTPUT + ": " + str + ". Supported values are: "
565575
+ String.join(
@@ -672,6 +682,10 @@ private SystemStream select(Map<SystemStream, Boolean> system, SystemOutput syst
672682
return select(system, SystemStream.Output, SystemStream.Error);
673683
case SysErrOrSysOut:
674684
return select(system, SystemStream.Error, SystemStream.Output);
685+
case ForcedSysOut:
686+
return SystemStream.Output;
687+
case ForcedSysErr:
688+
return SystemStream.Error;
675689
}
676690
return null;
677691
}

0 commit comments

Comments
 (0)