diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/connectbot/TerminalView.java | 52 | ||||
-rw-r--r-- | src/org/connectbot/service/TerminalBridge.java | 73 |
2 files changed, 106 insertions, 19 deletions
diff --git a/src/org/connectbot/TerminalView.java b/src/org/connectbot/TerminalView.java index 067d54b..ad5009a 100644 --- a/src/org/connectbot/TerminalView.java +++ b/src/org/connectbot/TerminalView.java @@ -24,8 +24,10 @@ import org.connectbot.service.TerminalBridge; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.PixelXorXfermode; +import android.util.Log; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.Toast; @@ -43,6 +45,10 @@ public class TerminalView extends View { public final TerminalBridge bridge; private final Paint paint; private final Paint cursorPaint; + private final Paint cursorDecorationPaint; + + // Cursor paints to distinguish modes + private float[] ctrlLines, altLines, shiftLines; private Toast notification = null; private String lastNotification = null; @@ -62,10 +68,12 @@ public class TerminalView extends View { cursorPaint.setColor(bridge.color[TerminalBridge.COLOR_FG_STD]); cursorPaint.setXfermode(new PixelXorXfermode(bridge.color[TerminalBridge.COLOR_BG_STD])); + cursorDecorationPaint = new Paint(); + cursorDecorationPaint.setColor(Color.BLACK); + //cursorDecorationPaint.setXfermode(new PixelXorXfermode(bridge.color[TerminalBridge.COLOR_FG_STD])); + // connect our view up to the bridge setOnKeyListener(bridge); - - } public void destroy() { @@ -77,6 +85,27 @@ public class TerminalView extends View { protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); bridge.parentChanged(this); + + // Make a triangle shape pointing down on the top + shiftLines = new float[] { + 0.0f, 0.0f, bridge.charWidth / 2.0f, bridge.charHeight / 3.0f, + bridge.charWidth / 2.0f, bridge.charHeight / 3.0f, bridge.charWidth, 0.0f, + bridge.charWidth, 0.0f, 0.0f, 0.0f, + }; + + // Make a triangle shape pointing up on the bottom + altLines = new float[] { + 0.0f, bridge.charHeight, bridge.charWidth / 2.0f, (bridge.charHeight / 3.0f) * 2.0f, + bridge.charWidth / 2.0f, (bridge.charHeight / 3.0f) * 2.0f, bridge.charWidth, bridge.charHeight, + bridge.charWidth, bridge.charHeight, 0.0f, bridge.charHeight, + }; + + // Make a triangle shape pointing right in the middle + ctrlLines = new float[] { + 0.0f, bridge.charHeight / 4.0f, bridge.charWidth, bridge.charHeight / 2.0f, + bridge.charWidth, bridge.charHeight / 2.0f, 0.0f, (bridge.charHeight / 3.0f) * 2.0f, + 0.0f, (bridge.charHeight / 4.0f) * 3.0f, 0.0f, bridge.charHeight / 4.0f, + }; } @Override @@ -95,9 +124,24 @@ public class TerminalView extends View { + bridge.buffer.screenBase - bridge.buffer.windowBase) * bridge.charHeight; - canvas.drawRect(x, y, x + bridge.charWidth, - y + bridge.charHeight, cursorPaint); + // Save the current clip and translation + canvas.save(); + + canvas.translate(x, y); + canvas.clipRect(0, 0, bridge.charWidth, bridge.charHeight); + canvas.drawPaint(cursorPaint); + + int metaState = bridge.getMetaState(); + Log.d("cursor", "Meta state: " + metaState); + if ((metaState & TerminalBridge.META_SHIFT_ON) == TerminalBridge.META_SHIFT_ON) + canvas.drawLines(shiftLines, cursorPaint); + if ((metaState & TerminalBridge.META_ALT_ON) == TerminalBridge.META_ALT_ON) + canvas.drawLines(altLines, cursorPaint); + if ((metaState & TerminalBridge.META_CTRL_ON) == TerminalBridge.META_CTRL_ON) + canvas.drawLines(ctrlLines, cursorPaint); + // Restore previous clip region + canvas.restore(); } // draw any highlighted area diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java index 3c7d4d3..94b1647 100644 --- a/src/org/connectbot/service/TerminalBridge.java +++ b/src/org/connectbot/service/TerminalBridge.java @@ -138,6 +138,10 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal private boolean slashKeyPressed = false; private boolean tabKeyPressed = false; + public final static int META_CTRL_ON = 0x01; + public final static int META_ALT_ON = 0x02; + public final static int META_SHIFT_ON = 0x04; + private boolean pubkeysExhausted = false; private boolean authenticated = false; @@ -217,7 +221,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal case KnownHosts.HOSTKEY_HAS_CHANGED: outputLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); - outputLine("@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @"); + outputLine("@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @"); outputLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); outputLine("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!"); outputLine("Someone could be eavesdropping on you right now (man-in-the-middle attack)!"); @@ -515,7 +519,6 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal return responses; } - /** * Convenience method for writing a line into the underlying MUD buffer. * Should never be called once the session is established. @@ -864,11 +867,13 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal if (shiftPressed) { metaState |= KeyEvent.META_SHIFT_ON; shiftPressed = false; + redraw(); } if (altPressed) { metaState |= KeyEvent.META_ALT_ON; altPressed = false; + redraw(); } int key = keymap.get(keyCode, metaState); @@ -883,6 +888,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal else if (key == 0x20) key = 0x00; ctrlPressed = false; + redraw(); } // handle pressing f-keys @@ -909,17 +915,37 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal // try handling keymode shortcuts if("Use right-side keys".equals(keymode)) { switch(keyCode) { - case KeyEvent.KEYCODE_ALT_RIGHT: slashKeyPressed = true; return true; - case KeyEvent.KEYCODE_SHIFT_RIGHT: tabKeyPressed = true; return true; - case KeyEvent.KEYCODE_SHIFT_LEFT: shiftPressed = true; return true; - case KeyEvent.KEYCODE_ALT_LEFT: altPressed = true; return true; + case KeyEvent.KEYCODE_ALT_RIGHT: + slashKeyPressed = true; + return true; + case KeyEvent.KEYCODE_SHIFT_RIGHT: + tabKeyPressed = true; + return true; + case KeyEvent.KEYCODE_SHIFT_LEFT: + shiftPressed = true; + redraw(); + return true; + case KeyEvent.KEYCODE_ALT_LEFT: + altPressed = true; + redraw(); + return true; } } else if("Use left-side keys".equals(keymode)) { switch(keyCode) { - case KeyEvent.KEYCODE_ALT_LEFT: slashKeyPressed = true; return true; - case KeyEvent.KEYCODE_SHIFT_LEFT: tabKeyPressed = true; return true; - case KeyEvent.KEYCODE_SHIFT_RIGHT: shiftPressed = true; return true; - case KeyEvent.KEYCODE_ALT_RIGHT: altPressed = true; return true; + case KeyEvent.KEYCODE_ALT_LEFT: + slashKeyPressed = true; + return true; + case KeyEvent.KEYCODE_SHIFT_LEFT: + tabKeyPressed = true; + return true; + case KeyEvent.KEYCODE_SHIFT_RIGHT: + shiftPressed = true; + redraw(); + return true; + case KeyEvent.KEYCODE_ALT_RIGHT: + altPressed = true; + redraw(); + return true; } } @@ -1016,16 +1042,16 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal selectionArea.reset(); } } - - redraw(); } else { - // TODO: Add some visual indication of Ctrl state if (ctrlPressed) { ((vt320)buffer).keyTyped(vt320.KEY_ESCAPE, ' ', 0); ctrlPressed = false; } else ctrlPressed = true; } + + redraw(); + return true; } @@ -1046,6 +1072,16 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal return false; } + public int getMetaState() { + int state = 0; + + if (ctrlPressed) state |= META_CTRL_ON; + if (altPressed) state |= META_ALT_ON; + if (shiftPressed) state |= META_SHIFT_ON; + + return state; + } + public void setSelectingForCopy(boolean selectingForCopy) { this.selectingForCopy = selectingForCopy; } @@ -1130,7 +1166,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal // clear out any old buffer information defaultPaint.setColor(Color.BLACK); - canvas.drawRect(0, 0, width, height, defaultPaint); + canvas.drawPaint(defaultPaint); // Stroke the border of the terminal if the size is being forced; if (forcedSize) { @@ -1249,9 +1285,13 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal addr++; } + // Save the current clip region + canvas.save(Canvas.CLIP_SAVE_FLAG); + // clear this dirty area with background color defaultPaint.setColor(bg); - canvas.drawRect(c * charWidth, (l * charHeight) - 1, (c + addr) * charWidth, (l + 1) * charHeight, defaultPaint); + canvas.clipRect(c * charWidth, (l * charHeight) - 1, (c + addr) * charWidth, (l + 1) * charHeight); + canvas.drawPaint(defaultPaint); // write the text string starting at 'c' for 'addr' number of characters defaultPaint.setColor(fg); @@ -1260,6 +1300,9 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal addr, c * charWidth, ((l + 1) * charHeight) - charDescent - 2, defaultPaint); + // Restore the previous clip region + canvas.restore(); + // advance to the next text block with different characteristics c += addr - 1; } |