From c7a75ad30c309a84077cc29baace48a001af0fec Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sun, 18 Aug 2019 18:30:38 -0500 Subject: [PATCH] Demo8 use terminals now --- src/jexer/TTerminalWidget.java | 10 ++++++---- src/jexer/TWidget.java | 20 ++++++++++++++++---- src/jexer/demos/Demo8.java | 10 ++++++++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/jexer/TTerminalWidget.java b/src/jexer/TTerminalWidget.java index 6efa6490..36966a0c 100644 --- a/src/jexer/TTerminalWidget.java +++ b/src/jexer/TTerminalWidget.java @@ -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")) { diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index bcf798ae..bca2be02 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -619,6 +619,9 @@ public abstract class TWidget implements Comparable { List 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(children); @@ -641,6 +644,9 @@ public abstract class TWidget implements Comparable { 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(children); @@ -1161,19 +1167,25 @@ public abstract class TWidget implements Comparable { /** * 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; } /** diff --git a/src/jexer/demos/Demo8.java b/src/jexer/demos/Demo8.java index d7b75013..a74b7a97 100644 --- a/src/jexer/demos/Demo8.java +++ b/src/jexer/demos/Demo8.java @@ -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(); } -- 2.27.0