From: Kevin Lamonte Date: Sat, 14 Sep 2019 00:57:53 +0000 (-0500) Subject: #62 handle failed shell spawn X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=1104f8d721d6fe7d6ec577389ddcee6ed1470385;p=nikiroo-utils.git #62 handle failed shell spawn --- diff --git a/src/jexer/TTerminalWidget.java b/src/jexer/TTerminalWidget.java index fb4b68b..a269609 100644 --- a/src/jexer/TTerminalWidget.java +++ b/src/jexer/TTerminalWidget.java @@ -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; diff --git a/src/jexer/TTerminalWindow.java b/src/jexer/TTerminalWindow.java index 0b65355..e96c50c 100644 --- a/src/jexer/TTerminalWindow.java +++ b/src/jexer/TTerminalWindow.java @@ -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; } /**