Skip to content

Commit

Permalink
EditorConsole: Set up System.out/err redirection in setCurrentEditorC…
Browse files Browse the repository at this point in the history
…onsole

Previously, the redirection would be triggered in the EditorConsole
constructor. However, this was problematic for unittests, which do not
need this redirection.

Since the redirection really is not useful intul there is a current
EditorConsole anyway, it can just be delayed a bit until
setCurrentEditorConsole is called.
  • Loading branch information
matthijskooijman authored and facchinm committed May 12, 2020
1 parent 3e3f54c commit fa267da
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions app/src/processing/app/EditorConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ public class EditorConsole extends JScrollPane {
private static ConsoleOutputStream out;
private static ConsoleOutputStream err;

private static synchronized void init(SimpleAttributeSet outStyle, PrintStream outStream, SimpleAttributeSet errStyle, PrintStream errStream) {
if (out != null) {
return;
}

out = new ConsoleOutputStream(outStyle, outStream);
System.setOut(new PrintStream(out, true));
public static synchronized void setCurrentEditorConsole(EditorConsole console) {
if (out == null) {
out = new ConsoleOutputStream(console.stdOutStyle, System.out);
System.setOut(new PrintStream(out, true));

err = new ConsoleOutputStream(errStyle, errStream);
System.setErr(new PrintStream(err, true));
}
err = new ConsoleOutputStream(console.stdErrStyle, System.err);
System.setErr(new PrintStream(err, true));
}

public static void setCurrentEditorConsole(EditorConsole console) {
out.setCurrentEditorConsole(console);
err.setCurrentEditorConsole(console);
}
Expand Down Expand Up @@ -109,8 +105,6 @@ public EditorConsole(Base base) {
setPreferredSize(new Dimension(100, (height * lines)));
setMinimumSize(new Dimension(100, (height * lines)));

EditorConsole.init(stdOutStyle, System.out, stdErrStyle, System.err);

// Add font size adjustment listeners.
if (base != null)
base.addEditorFontResizeListeners(consoleTextPane);
Expand All @@ -131,8 +125,10 @@ public void applyPreferences() {
// Re-insert console text with the new preferences if there were changes.
// This assumes that the document has single-child paragraphs (default).
if (!stdOutStyle.isEqual(stdOutStyleOld) || !stdErrStyle.isEqual(stdOutStyleOld)) {
out.setAttibutes(stdOutStyle);
err.setAttibutes(stdErrStyle);
if (out != null)
out.setAttibutes(stdOutStyle);
if (err != null)
err.setAttibutes(stdErrStyle);

int start;
for (int end = document.getLength() - 1; end >= 0; end = start - 1) {
Expand Down

0 comments on commit fa267da

Please sign in to comment.