AbstractCommandConsole.this.layout(true);
}
+ private StringBuilder outputBuffer = new StringBuilder();
+ private ArrayList<StyleRange> styleRanges = new ArrayList<StyleRange>();
+ private volatile boolean outputScheduled = false;
+
public void appendOutput(final String text, final Color foreground, final Color background) {
- final Display display = Display.getDefault();
- if(display.isDisposed()) return;
- display.asyncExec(new Runnable() {
- @Override
- public void run() {
- if(output.isDisposed()) return;
- int pos = output.getCharCount();
- outputModiLock = true;
- output.replaceTextRange(pos, 0, text);
- outputModiLock = false;
- output.setStyleRange(new StyleRange(pos, text.length(),
- foreground, background));
- output.setCaretOffset(output.getCharCount());
- output.showSelection();
- }
+ synchronized (outputBuffer) {
+ styleRanges.add(new StyleRange(outputBuffer.length(), text.length(), foreground, background));
+ outputBuffer.append(text);
+ }
+ if(!outputScheduled) {
+ outputScheduled = true;
+ final Display display = Display.getDefault();
+ if(display.isDisposed()) return;
+ 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();
+ }
+ int pos = output.getCharCount();
- });
+ outputModiLock = true;
+ output.replaceTextRange(pos, 0, outputText);
+ outputModiLock = false;
+
+ for(StyleRange styleRange : styleRangeArray) {
+ styleRange.start += pos;
+ output.setStyleRange(styleRange);
+ }
+
+ output.setCaretOffset(output.getCharCount());
+ output.showSelection();
+ }
+ });
+ }
}
private void execute() {