@@ -54,18 +54,20 @@ public class ConsoleOutputStream extends ByteArrayOutputStream {
54
54
55
55
private final SimpleAttributeSet attributes ;
56
56
private final PrintStream printStream ;
57
- private final StringBuilder buffer ;
58
57
private final Timer timer ;
58
+
59
59
private volatile EditorConsole editorConsole ;
60
+ private volatile boolean newLinePrinted ;
60
61
61
62
public ConsoleOutputStream (SimpleAttributeSet attributes , PrintStream printStream ) {
62
63
this .attributes = attributes ;
63
64
this .printStream = printStream ;
64
- this .buffer = new StringBuilder () ;
65
+ this .newLinePrinted = false ;
65
66
66
- this .timer = new Timer (100 , (e ) -> {
67
- if (editorConsole != null ) {
67
+ this .timer = new Timer (500 , (e ) -> {
68
+ if (editorConsole != null && newLinePrinted ) {
68
69
editorConsole .scrollDown ();
70
+ newLinePrinted = false ;
69
71
}
70
72
});
71
73
timer .setRepeats (false );
@@ -76,41 +78,24 @@ public void setCurrentEditorConsole(EditorConsole console) {
76
78
}
77
79
78
80
public synchronized void flush () {
79
- String message = toString ();
81
+ String text = toString ();
80
82
81
- if (message .length () == 0 ) {
83
+ if (text .length () == 0 ) {
82
84
return ;
83
85
}
84
86
85
- handleAppend (message );
87
+ printStream .print (text );
88
+ printInConsole (text );
86
89
87
90
reset ();
88
91
}
89
92
90
- private void handleAppend (String message ) {
91
- resetBufferIfDocumentEmpty ();
92
-
93
- buffer .append (message );
94
-
95
- clearBuffer ();
96
- }
97
-
98
- private void resetBufferIfDocumentEmpty () {
99
- if (editorConsole != null && editorConsole .isEmpty ()) {
100
- buffer .setLength (0 );
101
- }
102
- }
103
-
104
- private void clearBuffer () {
105
- String line = buffer .toString ();
106
- buffer .setLength (0 );
107
-
108
- printStream .print (line );
109
-
93
+ private void printInConsole (String text ) {
94
+ newLinePrinted = newLinePrinted || text .contains ("\n " );
110
95
if (editorConsole != null ) {
111
96
SwingUtilities .invokeLater (() -> {
112
97
try {
113
- editorConsole .insertString (line , attributes );
98
+ editorConsole .insertString (text , attributes );
114
99
} catch (BadLocationException ble ) {
115
100
//ignore
116
101
}
0 commit comments