- display.asyncExec(new Runnable() {
- @Override
- public void run() {
- if(output.isDisposed()) return;
- String outputText;
- StyleRange[] styleRangeArray;
- synchronized(outputBuffer) {
- outputScheduled = false;
-
- outputText = outputBuffer.toString();
- outputBuffer = new StringBuilder();
-
- styleRangeArray = styleRanges.toArray(new StyleRange[styleRanges.size()]);
- styleRanges.clear();
+ display.asyncExec(() -> {
+ if(output.isDisposed()) return;
+ String outputText;
+ StyleRange[] styleRangeArray;
+ synchronized(outputBuffer) {
+ outputScheduled.set(false);
+
+ outputText = outputBuffer.toString();
+ outputBuffer = new StringBuilder();
+
+ styleRangeArray = styleRanges.toArray(new StyleRange[styleRanges.size()]);
+ styleRanges.clear();
+ }
+
+ int addedLength = outputText.length();
+ int currentLength = output.getCharCount();
+ int insertPos = currentLength;
+ int newLength = insertPos + addedLength;
+
+ if (limitConsoleOutput && newLength > highWatermark) {
+ // Test for corner case: buffer overflows and more text is incoming than fits low watermark
+ if (addedLength > lowWatermark) {
+ // Prune the new input text first if it is too large to fit in the buffer even on its own to be < lowWatermark
+ int removedCharacters = addedLength - lowWatermark;
+
+ outputText = outputText.substring(removedCharacters);
+ addedLength = outputText.length();
+ newLength = insertPos + addedLength;
+
+ // Prune new incoming style ranges also
+ int firstStyleRangeToCopy = 0;
+ for (int i = 0; i < styleRangeArray.length; ++i, ++firstStyleRangeToCopy) {
+ StyleRange sr = styleRangeArray[i];
+ if ((sr.start + sr.length) > removedCharacters) {
+ if (sr.start < removedCharacters)
+ sr.start = removedCharacters;
+ break;
+ }
+ }
+ styleRangeArray = Arrays.copyOfRange(styleRangeArray, firstStyleRangeToCopy, styleRangeArray.length);
+ for (StyleRange sr : styleRangeArray)
+ sr.start -= removedCharacters;