Exemplo n.º 1
0
  /**
   * Create new terminal bridge with following parameters. We will immediately launch thread to
   * start SSH connection and handle any hostkey verification and password authentication.
   */
  public TerminalBridge(final TerminalManager manager, final HostBean host) throws IOException {
    Typeface type;

    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
    defaultPaint = new Paint();
    defaultPaint.setAntiAlias(true);
    type = Typeface.createFromAsset(this.manager.res.getAssets(), "UbuntuMono-R.ttf");
    defaultPaint.setTypeface(type);
    defaultPaint.setFakeBoldText(true); // more readable?

    localOutput = new LinkedList<String>();

    fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>();

    int hostFontSize = host.getFontSize();
    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) 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) 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) {}

          @Override
          public void beep() {
            if (parent.isShown()) manager.playBeep();
            else manager.sendActivityNotification(host);
          }
        };

    // 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();

    keyListener = new TerminalKeyListener(manager, this, buffer, host.getEncoding());
  }