Fix lag in TTerminalWindow
[fanfix.git] / src / jexer / tterminal / ECMA48.java
index 96f4e4083cc0bba8085d2df1311492214142017d..3702b8bc5bc64d3c9e9e454dbdb8179e464aafc0 100644 (file)
@@ -567,9 +567,11 @@ public class ECMA48 implements Runnable {
      * @param height the new height
      */
     public final void setHeight(final int height) {
+        int delta = height - this.height;
         this.height = height;
-        if (scrollRegionBottom >= height) {
-            scrollRegionBottom = height - 1;
+        scrollRegionBottom += delta;
+        if (scrollRegionBottom < 0) {
+            scrollRegionBottom = height;
         }
         if (scrollRegionTop >= scrollRegionBottom) {
             scrollRegionTop = 0;
@@ -6081,16 +6083,16 @@ public class ECMA48 implements Runnable {
                     // This is EOF
                     done = true;
                 } else {
-                    for (int i = 0; i < rc; i++) {
-                        int ch = 0;
-                        if (utf8) {
-                            ch = readBufferUTF8[i];
-                        } else {
-                            ch = readBuffer[i];
-                        }
+                    // Don't step on UI events
+                    synchronized (this) {
+                        for (int i = 0; i < rc; i++) {
+                            int ch = 0;
+                            if (utf8) {
+                                ch = readBufferUTF8[i];
+                            } else {
+                                ch = readBuffer[i];
+                            }
 
-                        synchronized (this) {
-                            // Don't step on UI events
                             consume((char)ch);
                         }
                     }
@@ -6124,6 +6126,11 @@ public class ECMA48 implements Runnable {
             // SQUASH
         }
 
+        // Permit my enclosing UI to know that I updated.
+        if (displayListener != null) {
+            displayListener.displayChanged();
+        }
+
         // System.err.println("*** run() exiting..."); System.err.flush();
     }