1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-01 21:52:12 +01:00

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.
This commit is contained in:
Matthijs Kooijman 2020-05-06 13:31:34 +02:00 committed by Martino Facchin
parent 3e3f54c3ca
commit fa267da74b

View File

@ -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;
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(console.stdErrStyle, System.err);
System.setErr(new PrintStream(err, true));
}
out = new ConsoleOutputStream(outStyle, outStream);
System.setOut(new PrintStream(out, true));
err = new ConsoleOutputStream(errStyle, errStream);
System.setErr(new PrintStream(err, true));
}
public static void setCurrentEditorConsole(EditorConsole console) {
out.setCurrentEditorConsole(console);
err.setCurrentEditorConsole(console);
}
@ -109,8 +105,6 @@ public class EditorConsole extends JScrollPane {
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);
@ -131,8 +125,10 @@ public class EditorConsole extends JScrollPane {
// 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) {