Demo8 use terminals now
authorKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 18 Aug 2019 23:30:38 +0000 (18:30 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 18 Aug 2019 23:30:38 +0000 (18:30 -0500)
src/jexer/TTerminalWidget.java
src/jexer/TWidget.java
src/jexer/demos/Demo8.java

index 6efa6490c6383e81564128fae4a96d4fc2899f73..36966a0cb80805adcfd1a68e9482a96739a5af3b 100644 (file)
@@ -447,6 +447,12 @@ public class TTerminalWidget extends TScrollableWidget
                     emulator.writeRemote("\033[8;" + getHeight() + ";" +
                         getWidth() + "t");
                 }
+
+                // Pass the correct text cell width/height to the emulator
+                if (getScreen() != null) {
+                    emulator.setTextWidth(getScreen().getTextWidth());
+                    emulator.setTextHeight(getScreen().getTextHeight());
+                }
             }
             return;
 
@@ -696,10 +702,6 @@ public class TTerminalWidget extends TScrollableWidget
         onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(),
                 getHeight()));
 
-        // Pass the correct text cell width/height to the emulator
-        emulator.setTextWidth(getScreen().getTextWidth());
-        emulator.setTextHeight(getScreen().getTextHeight());
-
         // Hide mouse when typing option
         if (System.getProperty("jexer.TTerminal.hideMouseWhenTyping",
                 "true").equals("false")) {
index bcf798ae36e9f40336d40fcd18d11e3a58b0de6c..bca2be02f21f03cc305985a56fbf82c5314ae75c 100644 (file)
@@ -619,6 +619,9 @@ public abstract class TWidget implements Comparable<TWidget> {
         List<TWidget> widgets = null;
         switch (menu.getId()) {
         case TMenu.MID_SPLIT_VERTICAL:
+            if (children.size() == 0) {
+                break;
+            }
             panel = new TPanel(null, x, y, width, height);
             pane = new TSplitPane(null, x, y, width, height, true);
             widgets = new ArrayList<TWidget>(children);
@@ -641,6 +644,9 @@ public abstract class TWidget implements Comparable<TWidget> {
             assert (panel.isActive() == true);
             return;
         case TMenu.MID_SPLIT_HORIZONTAL:
+            if (children.size() == 0) {
+                break;
+            }
             panel = new TPanel(null, x, y, width, height);
             pane = new TSplitPane(null, x, y, width, height, false);
             widgets = new ArrayList<TWidget>(children);
@@ -1161,19 +1167,25 @@ public abstract class TWidget implements Comparable<TWidget> {
     /**
      * Get this TWidget's parent TApplication.
      *
-     * @return the parent TApplication
+     * @return the parent TApplication, or null if not assigned
      */
     public TApplication getApplication() {
-        return window.getApplication();
+        if (window != null) {
+            return window.getApplication();
+        }
+        return null;
     }
 
     /**
      * Get the Screen.
      *
-     * @return the Screen
+     * @return the Screen, or null if not assigned
      */
     public Screen getScreen() {
-        return window.getScreen();
+        if (window != null) {
+            return window.getScreen();
+        }
+        return null;
     }
 
     /**
index d7b75013e08fad7516683a988611879385b6cc72..a74b7a9717f0c9dae0a0ac8c1818affea8b4a9b4 100644 (file)
@@ -33,6 +33,7 @@ import java.util.ResourceBundle;
 import jexer.TApplication;
 import jexer.TPanel;
 import jexer.TSplitPane;
+import jexer.TTerminalWidget;
 import jexer.TText;
 import jexer.TWindow;
 import jexer.layout.BoxLayoutManager;
@@ -112,8 +113,13 @@ public class Demo8 {
         TSplitPane pane = window.addSplitPane(0, 0, window.getWidth() - 2,
             window.getHeight() - 2, true);
 
-        pane.setLeft(new TText(null, TEXT, 0, 0, 10, 10));
-        pane.setRight(new TText(null, TEXT, 0, 0, 10, 10));
+        // pane.setLeft(new TText(null, TEXT, 0, 0, 10, 10));
+        // pane.setRight(new TText(null, TEXT, 0, 0, 10, 10));
+
+        // For this demo, let's require ptypipe
+        System.setProperty("jexer.TTerminal.ptypipe", "true");
+        pane.setLeft(new TTerminalWidget(null, 0, 0));
+        pane.setRight(new TTerminalWidget(null, 0, 0));
 
         app.run();
     }