Mercurial > 510Connectbot
diff src/com/five_ten_sg/connectbot/service/TerminalBridge.java @ 42:7ac846a07ed4 tn5250
start tn5250 integration
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 11 Jun 2014 09:14:31 -0700 |
parents | ecdbff49182c |
children | 80dcebe51af2 |
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalBridge.java Tue Jun 10 17:40:09 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/service/TerminalBridge.java Wed Jun 11 09:14:31 2014 -0700 @@ -96,7 +96,6 @@ private Relay relay; private final String emulation; - private final int scrollback; public Bitmap bitmap = null; public vt320 buffer = null; @@ -120,11 +119,10 @@ // TODO add support for the new clipboard API private ClipboardManager clipboard; - public int charWidth = -1; - public int charHeight = -1; - private int charTop = -1; - - private float fontSize = -1; + public int charWidth = -1; + public int charHeight = -1; + private int charTop = -1; + private float fontSize = -1; private final List<FontSizeChangedListener> fontSizeChangedListeners; @@ -160,7 +158,6 @@ manager = null; defaultPaint = new Paint(); selectionArea = new SelectionArea(); - scrollback = 1; localOutput = new LinkedList<String>(); fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>(); transport = null; @@ -169,16 +166,13 @@ } /** - * Create new terminal bridge with following parameters. We will immediately - * launch thread to start SSH connection and handle any hostkey verification - * and password authentication. + * Create new terminal bridge with following parameters. */ public TerminalBridge(final TerminalManager manager, final HostBean host) throws IOException { float hostFontSize; this.manager = manager; this.host = host; emulation = manager.getEmulation(); - scrollback = manager.getScrollback(); // create prompt helper to relay password and hostkey requests up to gui promptHelper = new PromptHelper(this); // create our default paint @@ -191,121 +185,19 @@ Integer defaultFontSize = Integer.parseInt(manager.prefs.getString(PreferenceConstants.DEFAULT_FONT_SIZE, "-1")); Log.i(TAG, "fontSize: " + this.fontSize + ", defaultFontSize: " + defaultFontSize); - if (this.fontSize == -1) { + if (fontSize == -1) { if (defaultFontSize > 0 && host.getFontSize() == -1) hostFontSize = defaultFontSize; else hostFontSize = host.getFontSize(); } else - hostFontSize = this.fontSize; + hostFontSize = fontSize; - if (hostFontSize <= 0) - hostFontSize = DEFAULT_FONT_SIZE; + if (hostFontSize <= 0) hostFontSize = DEFAULT_FONT_SIZE; setFontSize(hostFontSize); - // create terminal buffer and handle outgoing data - // this is probably status reply information - buffer = new vt320() { - @Override - public void debug(String s) { - Log.d(TAG, s); - } - @Override - public void write(byte[] b) { - try { - if (b != null && transport != null) - if (monitor != null) monitor.hostData(b); - - transport.write(b); - } - catch (IOException e) { - Log.e(TAG, "Problem writing outgoing data in vt320() thread", e); - } - } - @Override - public void write(int b) { - try { - if (transport != null) - if (monitor != null) monitor.hostData(b); - - transport.write(b); - } - catch (IOException e) { - Log.e(TAG, "Problem writing outgoing data in vt320() thread", e); - } - } - // We don't use telnet sequences. - @Override - public void sendTelnetCommand(byte cmd) { - } - // We don't want remote to resize our window. - @Override - public void setWindowSize(int c, int r) { - } - // test for changed screen contents - @Override - public void testChanged() { - if (monitor != null) monitor.testChanged(); - } - // play beep noise - @Override - public void beep() { - if (parent.isShown()) - manager.playBeep(); - else - manager.sendActivityNotification(host); - } - // monitor placement of new characters - @Override - public void putChar(int c, int l, char ch, int attributes) { - if (monitor != null) monitor.screenChanged(l, c); - - super.putChar(c, l, ch, attributes); - } - @Override - public void insertChar(int c, int l, char ch, int attributes) { - if (monitor != null) monitor.screenChanged(l, l, c, width - 1); - - super.insertChar(c, l, ch, attributes); - } - @Override - public void insertLine(int l, int n, boolean scrollDown) { - if (monitor != null) { - if (scrollDown) monitor.screenChanged(l, height - 1, 0, width - 1); - else monitor.screenChanged(0, l, 0, width - 1); - } - - super.insertLine(l, n, scrollDown); - } - @Override - public void deleteLine(int l) { - if (monitor != null) monitor.screenChanged(l, height - 1, 0, width - 1); - - super.deleteLine(l); - } - @Override - public void deleteChar(int c, int l) { - if (monitor != null) monitor.screenChanged(l, l, c, width - 1); - - super.deleteChar(c, l); - } - @Override - public void setCursorPosition(int c, int l) { - if (monitor != null) monitor.cursorMove(l, c); - - super.setCursorPosition(c, l); - } - }; - - // Don't keep any scrollback if a session is not being opened. - if (host.getWantSession()) - buffer.setBufferSize(scrollback); - else - buffer.setBufferSize(0); - resetColors(); - buffer.setDisplay(this); selectionArea = new SelectionArea(); } @@ -318,8 +210,8 @@ */ protected void startConnection() { transport = TransportFactory.getTransport(host.getProtocol()); - transport.setLinks(manager, this, host, buffer, emulation); - + transport.setLinks(manager, this, host, emulation); + buffer = transport.getTransportBuffer(); keyListener = transport.getTerminalKeyListener(); String monitor_init = host.getMonitor(); @@ -365,7 +257,8 @@ * @return charset in use by bridge */ public Charset getCharset() { - return relay.getCharset(); + if (relay != null) return relay.getCharset(); + } /** @@ -374,8 +267,7 @@ * @param encoding the canonical name of the character encoding */ public void setCharset(String encoding) { - if (relay != null) - relay.setCharset(encoding); + if (relay != null) relay.setCharset(encoding); keyListener.setCharset(encoding); } @@ -427,9 +319,8 @@ public void onConnected() { disconnected = false; buffer.reset(); - // We no longer need our local output. - localOutput.clear(); buffer.setAnswerBack(emulation); + localOutput.clear(); // We no longer need our local output. if (HostDatabase.DELKEY_BACKSPACE.equals(host.getDelKey())) buffer.setBackspace(vt320.DELETE_IS_BACKSPACE); @@ -664,8 +555,10 @@ try { // request a terminal pty resize - synchronized (buffer) { - buffer.setScreenSize(columns, rows, true); + if (buffer != null) { + synchronized (buffer) { + buffer.setScreenSize(columns, rows, true); + } } if (transport != null)