X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTTerminalWindow.java;h=bb3e14a9722c909c8af2c3fc21d6bac1a018cab6;hb=0580bf2c756853c189f2abbe9c500a8ae2d46e23;hp=a5d92aca58bff5a8daa0aa006f9756492bd50847;hpb=4d2c61b46c1e769f2fe69493623446a1ac0e26f0;p=fanfix.git diff --git a/src/jexer/TTerminalWindow.java b/src/jexer/TTerminalWindow.java index a5d92ac..bb3e14a 100644 --- a/src/jexer/TTerminalWindow.java +++ b/src/jexer/TTerminalWindow.java @@ -153,6 +153,9 @@ public class TTerminalWindow extends TScrollableWindow { super(application, i18n.getString("windowTitle"), x, y, 80 + 2, 24 + 2, flags); + // Require at least one line for the display. + setMinimumWindowHeight(3); + this.closeOnExit = closeOnExit; vScroller = new TVScroller(this, getWidth() - 2, 0, getHeight() - 2); @@ -163,7 +166,11 @@ public class TTerminalWindow extends TScrollableWindow { newStatusBar(i18n.getString("statusBarRunning")); // Spin it up - terminal = new TTerminalWidget(this, 0, 0); + terminal = new TTerminalWidget(this, 0, 0, command, new TAction() { + public void DO() { + onShellExit(); + } + }); } /** @@ -198,6 +205,9 @@ public class TTerminalWindow extends TScrollableWindow { super(application, i18n.getString("windowTitle"), x, y, 80 + 2, 24 + 2, flags); + // Require at least one line for the display. + setMinimumWindowHeight(3); + this.closeOnExit = closeOnExit; vScroller = new TVScroller(this, getWidth() - 2, 0, getHeight() - 2); @@ -208,7 +218,11 @@ public class TTerminalWindow extends TScrollableWindow { newStatusBar(i18n.getString("statusBarRunning")); // Spin it up - terminal = new TTerminalWidget(this, 0, 0); + terminal = new TTerminalWidget(this, 0, 0, new TAction() { + public void DO() { + onShellExit(); + } + }); } // ------------------------------------------------------------------------ @@ -220,7 +234,9 @@ public class TTerminalWindow extends TScrollableWindow { */ @Override public void draw() { - setTitle(terminal.getTitle()); + if (terminal != null) { + setTitle(terminal.getTitle()); + } reflowData(); super.draw(); } @@ -233,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(); @@ -249,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()); + } } /** @@ -263,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); @@ -300,6 +320,13 @@ public class TTerminalWindow extends TScrollableWindow { } super.onMouseUp(mouse); + + if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) { + // Clicked on vertical scrollbar + if (terminal != null) { + terminal.setVerticalValue(getVerticalValue()); + } + } } /** @@ -316,6 +343,13 @@ public class TTerminalWindow extends TScrollableWindow { } super.onMouseMotion(mouse); + + if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) { + // Clicked/dragged on vertical scrollbar + if (terminal != null) { + terminal.setVerticalValue(getVerticalValue()); + } + } } // ------------------------------------------------------------------------ @@ -331,7 +365,10 @@ public class TTerminalWindow extends TScrollableWindow { */ @Override public boolean hasHiddenMouse() { - return terminal.hasHiddenMouse(); + if (terminal != null) { + return terminal.hasHiddenMouse(); + } + return false; } /** @@ -415,4 +452,17 @@ public class TTerminalWindow extends TScrollableWindow { getApplication().postEvent(new TMenuEvent(TMenu.MID_REPAINT)); } + /** + * Wait for a period of time to get output from the launched process. + * + * @param millis millis to wait for, or 0 to wait forever + * @return true if the launched process has emitted something + */ + public boolean waitForOutput(final int millis) { + if (terminal == null) { + return false; + } + return terminal.waitForOutput(millis); + } + }