#62 handle failed shell spawn
authorKevin Lamonte <Kevin.Lamonte@honeywell.com>
Sat, 14 Sep 2019 00:57:53 +0000 (19:57 -0500)
committerKevin Lamonte <Kevin.Lamonte@honeywell.com>
Sat, 14 Sep 2019 00:57:53 +0000 (19:57 -0500)
src/jexer/TTerminalWidget.java
src/jexer/TTerminalWindow.java

index fb4b68bb68e0648c16a5e8daaed4a8c6132fc386..a2696092ce82ee7ed0550a0019b6b8fc0c9c785d 100644 (file)
@@ -358,6 +358,10 @@ public class TTerminalWidget extends TScrollableWidget
         // Let TWidget set my size.
         super.onResize(resize);
 
+        if (emulator == null) {
+            return;
+        }
+
         // Synchronize against the emulator so we don't stomp on its reader
         // thread.
         synchronized (emulator) {
@@ -418,7 +422,7 @@ public class TTerminalWidget extends TScrollableWidget
             return;
         }
 
-        if (emulator.isReading()) {
+        if ((emulator != null) && (emulator.isReading())) {
             // Get out of scrollback
             setVerticalValue(0);
             emulator.addUserEvent(keypress);
@@ -453,25 +457,27 @@ public class TTerminalWidget extends TScrollableWidget
             typingHidMouse = false;
         }
 
-        // If the emulator is tracking mouse buttons, it needs to see wheel
-        // events.
-        if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) {
-            if (mouse.isMouseWheelUp()) {
-                verticalDecrement();
-                dirty = true;
-                return;
+        if (emulator != null) {
+            // If the emulator is tracking mouse buttons, it needs to see
+            // wheel events.
+            if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) {
+                if (mouse.isMouseWheelUp()) {
+                    verticalDecrement();
+                    dirty = true;
+                    return;
+                }
+                if (mouse.isMouseWheelDown()) {
+                    verticalIncrement();
+                    dirty = true;
+                    return;
+                }
             }
-            if (mouse.isMouseWheelDown()) {
-                verticalIncrement();
-                dirty = true;
+            if (mouseOnEmulator(mouse)) {
+                emulator.addUserEvent(mouse);
+                readEmulatorState();
                 return;
             }
         }
-        if (mouseOnEmulator(mouse)) {
-            emulator.addUserEvent(mouse);
-            readEmulatorState();
-            return;
-        }
 
         // Emulator didn't consume it, pass it on
         super.onMouseDown(mouse);
@@ -488,7 +494,7 @@ public class TTerminalWidget extends TScrollableWidget
             typingHidMouse = false;
         }
 
-        if (mouseOnEmulator(mouse)) {
+        if ((emulator != null) && (mouseOnEmulator(mouse))) {
             emulator.addUserEvent(mouse);
             readEmulatorState();
             return;
@@ -509,7 +515,7 @@ public class TTerminalWidget extends TScrollableWidget
             typingHidMouse = false;
         }
 
-        if (mouseOnEmulator(mouse)) {
+        if ((emulator != null) && (mouseOnEmulator(mouse))) {
             emulator.addUserEvent(mouse);
             readEmulatorState();
             return;
@@ -528,6 +534,10 @@ public class TTerminalWidget extends TScrollableWidget
      */
     @Override
     public void draw() {
+        if (emulator == null) {
+            return;
+        }
+
         int width = getDisplayWidth();
 
         boolean syncEmulator = false;
@@ -682,7 +692,9 @@ public class TTerminalWidget extends TScrollableWidget
      */
     @Override
     public void close() {
-        emulator.close();
+        if (emulator != null) {
+            emulator.close();
+        }
         if (shell != null) {
             terminateShellChildProcess();
             shell.destroy();
@@ -695,6 +707,9 @@ public class TTerminalWidget extends TScrollableWidget
      */
     @Override
     public void reflowData() {
+        if (emulator == null) {
+            return;
+        }
 
         // Synchronize against the emulator so we don't stomp on its reader
         // thread.
@@ -733,6 +748,9 @@ public class TTerminalWidget extends TScrollableWidget
      * cursor drawn over it
      */
     public boolean hasHiddenMouse() {
+        if (emulator == null) {
+            return false;
+        }
         return (emulator.hasHiddenMousePointer() || typingHidMouse);
     }
 
@@ -743,6 +761,9 @@ public class TTerminalWidget extends TScrollableWidget
      * side
      */
     public boolean isReading() {
+        if (emulator == null) {
+            return false;
+        }
         return emulator.isReading();
     }
 
@@ -875,6 +896,10 @@ public class TTerminalWidget extends TScrollableWidget
      * screen.
      */
     private void readEmulatorState() {
+        if (emulator == null) {
+            return;
+        }
+
         // Synchronize against the emulator so we don't stomp on its reader
         // thread.
         synchronized (emulator) {
@@ -940,6 +965,9 @@ public class TTerminalWidget extends TScrollableWidget
      * @return whether or not the mouse is on the emulator
      */
     private boolean mouseOnEmulator(final TMouseEvent mouse) {
+        if (emulator == null) {
+            return false;
+        }
 
         if (!emulator.isReading()) {
             return false;
index 0b653554e0bf8aaee31932f2f6ff84645664e39f..e96c50c9921d99603da342e80802c27d0da02e86 100644 (file)
@@ -234,7 +234,9 @@ public class TTerminalWindow extends TScrollableWindow {
      */
     @Override
     public void draw() {
-        setTitle(terminal.getTitle());
+        if (terminal != null) {
+            setTitle(terminal.getTitle());
+        }
         reflowData();
         super.draw();
     }
@@ -247,8 +249,10 @@ public class TTerminalWindow extends TScrollableWindow {
     @Override
     public void onResize(final TResizeEvent resize) {
         if (resize.getType() == TResizeEvent.Type.WIDGET) {
-            terminal.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
-                    getWidth() - 2, getHeight() - 2));
+            if (terminal != null) {
+                terminal.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET,
+                        getWidth() - 2, getHeight() - 2));
+            }
 
             // Resize the scroll bars
             reflowData();
@@ -263,11 +267,13 @@ public class TTerminalWindow extends TScrollableWindow {
     @Override
     public void reflowData() {
         // Vertical scrollbar
-        terminal.reflowData();
-        setTopValue(terminal.getTopValue());
-        setBottomValue(terminal.getBottomValue());
-        setVerticalBigChange(terminal.getVerticalBigChange());
-        setVerticalValue(terminal.getVerticalValue());
+        if (terminal != null) {
+            terminal.reflowData();
+            setTopValue(terminal.getTopValue());
+            setBottomValue(terminal.getBottomValue());
+            setVerticalBigChange(terminal.getVerticalBigChange());
+            setVerticalValue(terminal.getVerticalValue());
+        }
     }
 
     /**
@@ -277,7 +283,7 @@ public class TTerminalWindow extends TScrollableWindow {
      */
     @Override
     public void onKeypress(final TKeypressEvent keypress) {
-        if (terminal.isReading()) {
+        if ((terminal != null) && (terminal.isReading())) {
             terminal.onKeypress(keypress);
         } else {
             super.onKeypress(keypress);
@@ -317,7 +323,9 @@ public class TTerminalWindow extends TScrollableWindow {
 
         if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) {
             // Clicked on vertical scrollbar
-            terminal.setVerticalValue(getVerticalValue());
+            if (terminal != null) {
+                terminal.setVerticalValue(getVerticalValue());
+            }
         }
     }
 
@@ -338,7 +346,9 @@ public class TTerminalWindow extends TScrollableWindow {
 
         if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) {
             // Clicked/dragged on vertical scrollbar
-            terminal.setVerticalValue(getVerticalValue());
+            if (terminal != null) {
+                terminal.setVerticalValue(getVerticalValue());
+            }
         }
     }
 
@@ -355,7 +365,10 @@ public class TTerminalWindow extends TScrollableWindow {
      */
     @Override
     public boolean hasHiddenMouse() {
-        return terminal.hasHiddenMouse();
+        if (terminal != null) {
+            return terminal.hasHiddenMouse();
+        }
+        return false;
     }
 
     /**