TSplitPane initial
[fanfix.git] / src / jexer / TTerminalWindow.java
index 5970b6c77aff4791a389d13a7aa9a1012dbf5147..2106cf0e8c1c48ca59d1efe39a6e155e911e059c 100644 (file)
@@ -143,6 +143,17 @@ public class TTerminalWindow extends TScrollableWindow
      */
     private long lastUpdateTime = 0;
 
+    /**
+     * If true, hide the mouse after typing a keystroke.
+     */
+    private boolean hideMouseWhenTyping = true;
+
+    /**
+     * If true, the mouse should not be displayed because a keystroke was
+     * typed.
+     */
+    private boolean typingHidMouse = false;
+
     // ------------------------------------------------------------------------
     // Constructors -----------------------------------------------------------
     // ------------------------------------------------------------------------
@@ -285,6 +296,15 @@ public class TTerminalWindow extends TScrollableWindow
 
         this.closeOnExit = closeOnExit;
 
+        if (System.getProperty("jexer.TTerminal.shell") != null) {
+            String shell = System.getProperty("jexer.TTerminal.shell");
+            if (shell.trim().startsWith("ptypipe")) {
+                ptypipe = true;
+            }
+            spawnShell(shell.split("\\s+"));
+            return;
+        }
+
         String cmdShellWindows = "cmd.exe";
 
         // You cannot run a login shell in a bare Process interactively, due
@@ -326,10 +346,9 @@ public class TTerminalWindow extends TScrollableWindow
      */
     @Override
     public void draw() {
-
         int width = getDisplayWidth();
         boolean syncEmulator = false;
-        if ((System.currentTimeMillis() - lastUpdateTime > 125)
+        if ((System.currentTimeMillis() - lastUpdateTime >25)
             && (dirty == true)
         ) {
             // Too much time has passed, draw it all.
@@ -410,8 +429,7 @@ public class TTerminalWindow extends TScrollableWindow
                     continue;
                 }
 
-                Cell newCell = new Cell();
-                newCell.setTo(ch);
+                Cell newCell = new Cell(ch);
                 boolean reverse = line.isReverseColor() ^ ch.isReverse();
                 newCell.setReverse(false);
                 if (reverse) {
@@ -523,6 +541,9 @@ public class TTerminalWindow extends TScrollableWindow
      */
     @Override
     public void onKeypress(final TKeypressEvent keypress) {
+        if (hideMouseWhenTyping) {
+            typingHidMouse = true;
+        }
 
         // Scrollback up/down
         if (keypress.equals(kbShiftPgUp)
@@ -547,8 +568,11 @@ public class TTerminalWindow extends TScrollableWindow
 
             // UGLY HACK TIME!  cmd.exe needs CRLF, not just CR, so if
             // this is kBEnter then also send kbCtrlJ.
-            if (System.getProperty("os.name").startsWith("Windows")) {
-                if (keypress.equals(kbEnter)) {
+            if (keypress.equals(kbEnter)) {
+                if (System.getProperty("os.name").startsWith("Windows")
+                    && (System.getProperty("jexer.TTerminal.cmdHack",
+                            "true").equals("true"))
+                ) {
                     emulator.addUserEvent(new TKeypressEvent(kbCtrlJ));
                 }
             }
@@ -574,6 +598,10 @@ public class TTerminalWindow extends TScrollableWindow
             return;
         }
 
+        if (hideMouseWhenTyping) {
+            typingHidMouse = false;
+        }
+
         // If the emulator is tracking mouse buttons, it needs to see wheel
         // events.
         if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) {
@@ -611,6 +639,10 @@ public class TTerminalWindow extends TScrollableWindow
             return;
         }
 
+        if (hideMouseWhenTyping) {
+            typingHidMouse = false;
+        }
+
         if (mouseOnEmulator(mouse)) {
             mouse.setX(mouse.getX() - 1);
             mouse.setY(mouse.getY() - 1);
@@ -636,6 +668,10 @@ public class TTerminalWindow extends TScrollableWindow
             return;
         }
 
+        if (hideMouseWhenTyping) {
+            typingHidMouse = false;
+        }
+
         if (mouseOnEmulator(mouse)) {
             mouse.setX(mouse.getX() - 1);
             mouse.setY(mouse.getY() - 1);
@@ -652,6 +688,18 @@ public class TTerminalWindow extends TScrollableWindow
     // TTerminalWindow --------------------------------------------------------
     // ------------------------------------------------------------------------
 
+    /**
+     * Returns true if this window does not want the application-wide mouse
+     * cursor drawn over it.
+     *
+     * @return true if this window does not want the application-wide mouse
+     * cursor drawn over it
+     */
+    @Override
+    public boolean hasHiddenMouse() {
+        return (super.hasHiddenMouse() || typingHidMouse);
+    }
+
     /**
      * Claim the keystrokes the emulator will need.
      */
@@ -787,6 +835,13 @@ public class TTerminalWindow extends TScrollableWindow
         // 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")) {
+
+            hideMouseWhenTyping = false;
+        }
     }
 
     /**
@@ -985,8 +1040,7 @@ public class TTerminalWindow extends TScrollableWindow
         BufferedImage image;
         if (line.getDoubleHeight() == 1) {
             // Double-height top half: don't draw the underline.
-            Cell newCell = new Cell();
-            newCell.setTo(cell);
+            Cell newCell = new Cell(cell);
             newCell.setUnderline(false);
             image = doubleFont.getImage(newCell, textWidth * 2, textHeight * 2,
                 cursorBlinkVisible);
@@ -997,10 +1051,8 @@ public class TTerminalWindow extends TScrollableWindow
 
         // Now that we have the double-wide glyph drawn, copy the right
         // pieces of it to the cells.
-        Cell left = new Cell();
-        Cell right = new Cell();
-        left.setTo(cell);
-        right.setTo(cell);
+        Cell left = new Cell(cell);
+        Cell right = new Cell(cell);
         right.setChar(' ');
         BufferedImage leftImage = null;
         BufferedImage rightImage = null;