Exemplo n.º 1
0
  /**
   * Something changed in our parent {@link TerminalView}, maybe it's a new parent, or maybe it's an
   * updated font size. We should recalculate terminal size information and request a PTY resize.
   */
  public final synchronized void parentChanged(TerminalView parent) {
    if (manager != null && !manager.isResizeAllowed()) {
      Log.d(TAG, "Resize is not allowed now");
      return;
    }

    this.parent = parent;
    final int width = parent.getWidth();
    final int height = parent.getHeight();

    // Something has gone wrong with our layout; we're 0 width or height!
    if (width <= 0 || height <= 0) return;

    clipboard = (ClipboardManager) parent.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    keyListener.setClipboardManager(clipboard);

    if (!forcedSize) {
      // recalculate buffer size
      int newColumns, newRows;

      newColumns = width / charWidth;
      newRows = height / charHeight;

      // If nothing has changed in the terminal dimensions and not an intial
      // draw then don't blow away scroll regions and such.
      if (newColumns == columns && newRows == rows) return;

      columns = newColumns;
      rows = newRows;
    }

    // reallocate new bitmap if needed
    boolean newBitmap = (bitmap == null);
    if (bitmap != null) newBitmap = (bitmap.getWidth() != width || bitmap.getHeight() != height);

    if (newBitmap) {
      discardBitmap();
      bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
      canvas.setBitmap(bitmap);
    }

    // clear out any old buffer information
    defaultPaint.setColor(Color.BLACK);
    canvas.drawPaint(defaultPaint);

    // Stroke the border of the terminal if the size is being forced;
    if (forcedSize) {
      int borderX = (columns * charWidth) + 1;
      int borderY = (rows * charHeight) + 1;

      defaultPaint.setColor(Color.GRAY);
      defaultPaint.setStrokeWidth(0.0f);
      if (width >= borderX) canvas.drawLine(borderX, 0, borderX, borderY + 1, defaultPaint);
      if (height >= borderY) canvas.drawLine(0, borderY, borderX + 1, borderY, defaultPaint);
    }

    try {
      // request a terminal pty resize
      synchronized (buffer) {
        buffer.setScreenSize(columns, rows, true);
      }

      if (transport != null) transport.setDimensions(columns, rows, width, height);
    } catch (Exception e) {
      Log.e(TAG, "Problem while trying to resize screen or PTY", e);
    }

    // redraw local output if we don't have a sesson to receive our resize request
    if (transport == null) {
      synchronized (localOutput) {
        ((vt320) buffer).reset();

        for (String line : localOutput) ((vt320) buffer).putString(line);
      }
    }

    // force full redraw with new buffer size
    fullRedraw = true;
    redraw();

    parent.notifyUser(String.format("%d x %d", columns, rows));

    Log.i(TAG, String.format("parentChanged() now width=%d, height=%d", columns, rows));
  }
Exemplo n.º 2
0
 public void resetScrollPosition() {
   // if we're in scrollback, scroll to bottom of window on input
   if (buffer.windowBase != buffer.screenBase) buffer.setWindowBase(buffer.screenBase);
 }
Exemplo n.º 3
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());
  }