Skip to content

Commit fa267da

Browse files
matthijskooijmanfacchinm
authored andcommitted
EditorConsole: Set up System.out/err redirection in setCurrentEditorConsole
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.
1 parent 3e3f54c commit fa267da

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

app/src/processing/app/EditorConsole.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,15 @@ public class EditorConsole extends JScrollPane {
3838
private static ConsoleOutputStream out;
3939
private static ConsoleOutputStream err;
4040

41-
private static synchronized void init(SimpleAttributeSet outStyle, PrintStream outStream, SimpleAttributeSet errStyle, PrintStream errStream) {
42-
if (out != null) {
43-
return;
44-
}
45-
46-
out = new ConsoleOutputStream(outStyle, outStream);
47-
System.setOut(new PrintStream(out, true));
41+
public static synchronized void setCurrentEditorConsole(EditorConsole console) {
42+
if (out == null) {
43+
out = new ConsoleOutputStream(console.stdOutStyle, System.out);
44+
System.setOut(new PrintStream(out, true));
4845

49-
err = new ConsoleOutputStream(errStyle, errStream);
50-
System.setErr(new PrintStream(err, true));
51-
}
46+
err = new ConsoleOutputStream(console.stdErrStyle, System.err);
47+
System.setErr(new PrintStream(err, true));
48+
}
5249

53-
public static void setCurrentEditorConsole(EditorConsole console) {
5450
out.setCurrentEditorConsole(console);
5551
err.setCurrentEditorConsole(console);
5652
}
@@ -109,8 +105,6 @@ public EditorConsole(Base base) {
109105
setPreferredSize(new Dimension(100, (height * lines)));
110106
setMinimumSize(new Dimension(100, (height * lines)));
111107

112-
EditorConsole.init(stdOutStyle, System.out, stdErrStyle, System.err);
113-
114108
// Add font size adjustment listeners.
115109
if (base != null)
116110
base.addEditorFontResizeListeners(consoleTextPane);
@@ -131,8 +125,10 @@ public void applyPreferences() {
131125
// Re-insert console text with the new preferences if there were changes.
132126
// This assumes that the document has single-child paragraphs (default).
133127
if (!stdOutStyle.isEqual(stdOutStyleOld) || !stdErrStyle.isEqual(stdOutStyleOld)) {
134-
out.setAttibutes(stdOutStyle);
135-
err.setAttibutes(stdErrStyle);
128+
if (out != null)
129+
out.setAttibutes(stdOutStyle);
130+
if (err != null)
131+
err.setAttibutes(stdErrStyle);
136132

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

0 commit comments

Comments
 (0)