Skip to content

Commit

Permalink
Add forced-out and forcer-err to force the system console to use the …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
gnodet committed Oct 25, 2023
1 parent b8084cf commit d4bf37c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public final class TerminalBuilder {
public static final String PROP_OUTPUT_ERR = "err";
public static final String PROP_OUTPUT_OUT_ERR = "out-err";
public static final String PROP_OUTPUT_ERR_OUT = "err-out";
public static final String PROP_OUTPUT_FORCED_OUT = "forced-out";
public static final String PROP_OUTPUT_FORCED_ERR = "forced-err";

//
// Other system properties controlling various jline parts
Expand Down Expand Up @@ -106,7 +108,9 @@ public enum SystemOutput {
SysOut,
SysErr,
SysOutOrSysErr,
SysErrOrSysOut
SysErrOrSysOut,
ForcedSysOut,
ForcedSysErr
}

/**
Expand Down Expand Up @@ -560,6 +564,12 @@ public SystemOutput computeSystemOutput() {
case PROP_OUTPUT_ERR_OUT:
systemOutput = SystemOutput.SysErrOrSysOut;
break;
case PROP_OUTPUT_FORCED_OUT:
systemOutput = SystemOutput.ForcedSysOut;
break;
case PROP_OUTPUT_FORCED_ERR:
systemOutput = SystemOutput.ForcedSysErr;
break;
default:
Log.debug("Unsupported value for " + PROP_OUTPUT + ": " + str + ". Supported values are: "
+ String.join(
Expand Down Expand Up @@ -672,6 +682,10 @@ private SystemStream select(Map<SystemStream, Boolean> system, SystemOutput syst
return select(system, SystemStream.Output, SystemStream.Error);
case SysErrOrSysOut:
return select(system, SystemStream.Error, SystemStream.Output);
case ForcedSysOut:
return SystemStream.Output;
case ForcedSysErr:
return SystemStream.Error;
}
return null;
}
Expand Down

0 comments on commit d4bf37c

Please sign in to comment.