#51 complete
authorKevin Lamonte <kevin.lamonte@gmail.com>
Thu, 22 Aug 2019 11:22:24 +0000 (06:22 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Thu, 22 Aug 2019 11:22:24 +0000 (06:22 -0500)
src/jexer/TSplitPane.java
src/jexer/TTerminalWidget.java
src/jexer/TWidget.java
src/jexer/tterminal/ECMA48.java

index a9d6cdb3f52760ac60c70dc1606a12b6d4f1eb6f..7c85278f88d0d6df3ff34f01064e2be57d25481d 100644 (file)
@@ -124,8 +124,6 @@ public class TSplitPane extends TWidget {
             // Resize me
             super.onResize(event);
 
-            // System.err.println("onResize(): " + toString());
-
             if (vertical && (split >= getWidth() - 2)) {
                 center();
             } else if (!vertical && (split >= getHeight() - 2)) {
@@ -172,9 +170,6 @@ public class TSplitPane extends TWidget {
         this.mouse = mouse;
 
         if (inSplitMove && mouse.isMouse1()) {
-            // DEBUG
-            // System.err.println(toPrettyString());
-
             // Stop moving split
             inSplitMove = false;
             return;
@@ -501,36 +496,29 @@ public class TSplitPane extends TWidget {
      * Layout the two child widgets.
      */
     private void layoutChildren() {
-
-        // System.err.println("layoutChildren(): " + toString());
-
         if (vertical) {
             if (left != null) {
                 left.setDimensions(0, 0, split, getHeight());
                 left.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
                         left.getWidth(), left.getHeight()));
-                // System.err.println("   move/size left: " + left.toString());
             }
             if (right != null) {
                 right.setDimensions(split + 1, 0, getWidth() - split - 1,
                     getHeight());
                 right.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
                         right.getWidth(), right.getHeight()));
-                // System.err.println("   move/size right: " + right.toString());
             }
         } else {
             if (top != null) {
                 top.setDimensions(0, 0, getWidth(), split);
                 top.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
                         top.getWidth(), top.getHeight()));
-                // System.err.println("   move/size top: " + top.toString());
             }
             if (bottom != null) {
                 bottom.setDimensions(0, split + 1, getWidth(),
                     getHeight() - split - 1);
                 bottom.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
                         bottom.getWidth(), bottom.getHeight()));
-                // System.err.println("   move/size bottom: " + bottom.toString());
             }
         }
     }
@@ -607,8 +595,6 @@ public class TSplitPane extends TWidget {
             keep.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(),
                     getHeight()));
         }
-
-        // System.err.println("\nAfter removeSplit():\n" + myParent.toPrettyString());
         
         return keep;
     }
index 39d761c64a1b2ae06fe2df6a5cbd1a143a8b4b5e..b1ff8b9b0d8e90995229d94fb3c80242f09f4d5c 100644 (file)
@@ -119,12 +119,7 @@ public class TTerminalWidget extends TScrollableWidget
     private boolean haveTimer = false;
 
     /**
-     * The last seen scrollback lines.
-     */
-    private List<DisplayLine> scrollback;
-
-    /**
-     * The last seen display lines.
+     * The last seen visible display.
      */
     private List<DisplayLine> display;
 
@@ -361,7 +356,7 @@ public class TTerminalWidget extends TScrollableWidget
         int width = getDisplayWidth();
 
         boolean syncEmulator = false;
-        if ((System.currentTimeMillis() - lastUpdateTime >= 25)
+        if ((System.currentTimeMillis() - lastUpdateTime >= 20)
             && (dirty == true)
         ) {
             // Too much time has passed, draw it all.
@@ -375,7 +370,6 @@ public class TTerminalWidget extends TScrollableWidget
         }
 
         if ((syncEmulator == true)
-            || (scrollback == null)
             || (display == null)
         ) {
             // We want to minimize the amount of time we have the emulator
@@ -392,46 +386,19 @@ public class TTerminalWidget extends TScrollableWidget
                     return;
                 }
 
-                if ((scrollback == null) || emulator.isReading()) {
-                    scrollback = copyBuffer(emulator.getScrollbackBuffer());
-                    display = copyBuffer(emulator.getDisplayBuffer());
+                if ((display == null) || emulator.isReading()) {
+                    display = emulator.getVisibleDisplay(getHeight(),
+                        -getVerticalValue());
+                    assert (display.size() == getHeight());
                 }
                 width = emulator.getWidth();
             }
             dirty = false;
         }
 
-        // Put together the visible rows
-        int visibleHeight = getHeight();
-        int visibleBottom = scrollback.size() + display.size()
-                + getVerticalValue();
-        assert (visibleBottom >= 0);
-
-        List<DisplayLine> preceedingBlankLines = new ArrayList<DisplayLine>();
-        int visibleTop = visibleBottom - visibleHeight;
-        if (visibleTop < 0) {
-            for (int i = visibleTop; i < 0; i++) {
-                preceedingBlankLines.add(emulator.getBlankDisplayLine());
-            }
-            visibleTop = 0;
-        }
-        assert (visibleTop >= 0);
-
-        List<DisplayLine> displayLines = new ArrayList<DisplayLine>();
-        displayLines.addAll(scrollback);
-        displayLines.addAll(display);
-
-        List<DisplayLine> visibleLines = new ArrayList<DisplayLine>();
-        visibleLines.addAll(preceedingBlankLines);
-        visibleLines.addAll(displayLines.subList(visibleTop,
-                visibleBottom));
-
-        visibleHeight -= visibleLines.size();
-        assert (visibleHeight >= 0);
-
         // Now draw the emulator screen
         int row = 0;
-        for (DisplayLine line: visibleLines) {
+        for (DisplayLine line: display) {
             int widthMax = width;
             if (line.isDoubleWidth()) {
                 widthMax /= 2;
@@ -471,17 +438,7 @@ public class TTerminalWidget extends TScrollableWidget
                 }
             }
             row++;
-            if (row == getHeight()) {
-                // Don't overwrite the box edge
-                break;
-            }
-        }
-        CellAttributes background = new CellAttributes();
-        // Fill in the blank lines on bottom
-        for (int i = 0; i < visibleHeight; i++) {
-            hLineXY(0, i + row, getWidth(), ' ', background);
         }
-
     }
 
     /**
@@ -577,6 +534,7 @@ public class TTerminalWidget extends TScrollableWidget
             || keypress.equals(kbAltPgUp)
         ) {
             bigVerticalDecrement();
+            dirty = true;
             return;
         }
         if (keypress.equals(kbShiftPgDn)
@@ -584,6 +542,7 @@ public class TTerminalWidget extends TScrollableWidget
             || keypress.equals(kbAltPgDn)
         ) {
             bigVerticalIncrement();
+            dirty = true;
             return;
         }
 
@@ -627,10 +586,12 @@ public class TTerminalWidget extends TScrollableWidget
         if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) {
             if (mouse.isMouseWheelUp()) {
                 verticalDecrement();
+                dirty = true;
                 return;
             }
             if (mouse.isMouseWheelDown()) {
                 verticalIncrement();
+                dirty = true;
                 return;
             }
         }
@@ -929,20 +890,6 @@ public class TTerminalWidget extends TScrollableWidget
         return false;
     }
 
-    /**
-     * Copy a display buffer.
-     *
-     * @param buffer the buffer to copy
-     * @return a deep copy of the buffer's data
-     */
-    private List<DisplayLine> copyBuffer(final List<DisplayLine> buffer) {
-        ArrayList<DisplayLine> result = new ArrayList<DisplayLine>(buffer.size());
-        for (DisplayLine line: buffer) {
-            result.add(new DisplayLine(line));
-        }
-        return result;
-    }
-
     /**
      * Draw glyphs for a double-width or double-height VT100 cell to two
      * screen cells.
index ba18989bfc43d38ea0549e42f5f20dfb8358e1ab..60bc3e4a618c0cce09d84cbdbedfdc200da39906 100644 (file)
@@ -1475,6 +1475,19 @@ public abstract class TWidget implements Comparable<TWidget> {
         }
     }
 
+    /**
+     * Make this widget, all of its parents, the active child.
+     */
+    public final void activateAll() {
+        activate();
+        if (parent == this) {
+            return;
+        }
+        if (parent != null) {
+            parent.activateAll();
+        }
+    }
+
     /**
      * Switch the active widget with the next in the tab order.
      *
@@ -1605,11 +1618,10 @@ public abstract class TWidget implements Comparable<TWidget> {
             splitPane.setLeft(this);
             splitPane.setRight(newWidget);
         }
-        splitPane.activate();
         if (newWidget != null) {
-            newWidget.activate();
+            newWidget.activateAll();
         } else {
-            activate();
+            activateAll();
         }
 
         assert (parent != null);
@@ -1657,11 +1669,10 @@ public abstract class TWidget implements Comparable<TWidget> {
             splitPane.setTop(this);
             splitPane.setBottom(newWidget);
         }
-        splitPane.activate();
         if (newWidget != null) {
-            newWidget.activate();
+            newWidget.activateAll();
         } else {
-            activate();
+            activateAll();
         }
 
         assert (parent != null);
index c277795d69450b2db44f79d77a1caa8062c11275..e3e7c929397a9b417324933a1057b057638ac57f 100644 (file)
@@ -1078,6 +1078,64 @@ public class ECMA48 implements Runnable {
         return display;
     }
 
+    /**
+     * Get the visible display + scrollback buffer, offset by a specified
+     * number of rows from the bottom.
+     *
+     * @param visibleHeight the total height of the display to show
+     * @param scrollBottom the number of rows from the bottom to scroll back
+     * @return a copy of the display + scrollback buffers
+     */
+    public final List<DisplayLine> getVisibleDisplay(final int visibleHeight,
+        final int scrollBottom) {
+
+        assert (visibleHeight >= 0);
+        assert (scrollBottom >= 0);
+
+        int visibleBottom = scrollback.size() + display.size() - scrollBottom;
+
+        List<DisplayLine> preceedingBlankLines = new ArrayList<DisplayLine>();
+        int visibleTop = visibleBottom - visibleHeight;
+        if (visibleTop < 0) {
+            for (int i = visibleTop; i < 0; i++) {
+                preceedingBlankLines.add(getBlankDisplayLine());
+            }
+            visibleTop = 0;
+        }
+        assert (visibleTop >= 0);
+
+        List<DisplayLine> displayLines = new ArrayList<DisplayLine>();
+        displayLines.addAll(scrollback);
+        displayLines.addAll(display);
+
+        List<DisplayLine> visibleLines = new ArrayList<DisplayLine>();
+        visibleLines.addAll(preceedingBlankLines);
+        visibleLines.addAll(displayLines.subList(visibleTop, visibleBottom));
+
+        // Fill in the blank lines on bottom
+        int bottomBlankLines = visibleHeight - visibleLines.size();
+        assert (bottomBlankLines >= 0);
+        for (int i = 0; i < bottomBlankLines; i++) {
+            visibleLines.add(getBlankDisplayLine());
+        }
+
+        return copyBuffer(visibleLines);
+    }
+
+    /**
+     * Copy a display buffer.
+     *
+     * @param buffer the buffer to copy
+     * @return a deep copy of the buffer's data
+     */
+    private List<DisplayLine> copyBuffer(final List<DisplayLine> buffer) {
+        ArrayList<DisplayLine> result = new ArrayList<DisplayLine>(buffer.size());
+        for (DisplayLine line: buffer) {
+            result.add(new DisplayLine(line));
+        }
+        return result;
+    }
+
     /**
      * Get the display width.
      *