Example #1
0
  public Dimension requestResize(
      final Dimension newSize,
      final RequestOrigin origin,
      int cursorY,
      JediTerminal.ResizeHandler resizeHandler) {
    if (!newSize.equals(myTermSize)) {
      myTerminalTextBuffer.lock();
      try {
        myTerminalTextBuffer.resize(newSize, origin, cursorY, resizeHandler, mySelection);
        myTermSize = (Dimension) newSize.clone();

        final Dimension pixelDimension = new Dimension(getPixelWidth(), getPixelHeight());

        setPreferredSize(pixelDimension);
        if (myTerminalPanelListener != null) {
          myTerminalPanelListener.onPanelResize(pixelDimension, origin);
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                updateScrolling();
              }
            });
      } finally {
        myTerminalTextBuffer.unlock();
      }
    }

    return new Dimension(getPixelWidth(), getPixelHeight());
  }
Example #2
0
  public void testMidnightCommanderOnXTerm() throws IOException {
    TerminalTextBuffer terminalTextBuffer = doTest();

    assertColor(
        terminalTextBuffer.getStyleAt(8, 2),
        ColorPalette.getIndexedColor(3),
        ColorPalette.getIndexedColor(4));
    assertColor(
        terminalTextBuffer.getStyleAt(23, 4),
        ColorPalette.getIndexedColor(7),
        ColorPalette.getIndexedColor(4));
    assertColor(
        terminalTextBuffer.getStyleAt(2, 0),
        ColorPalette.getIndexedColor(0),
        ColorPalette.getIndexedColor(6));
  }
Example #3
0
  private void clearBuffer() {
    if (!myTerminalTextBuffer.isUsingAlternateBuffer()) {
      myTerminalTextBuffer.clearHistory();

      if (myCoordsAccessor != null && myCoordsAccessor.getY() > 0) {
        TerminalLine line = myTerminalTextBuffer.getLine(myCoordsAccessor.getY() - 1);

        myTerminalTextBuffer.clearAll();

        myCoordsAccessor.setY(0);
        myCursor.setY(1);
        myTerminalTextBuffer.addLine(line);
      }

      updateScrolling();

      myClientScrollOrigin = myBoundedRangeModel.getValue();
    }
  }
Example #4
0
 private void updateScrolling() {
   if (myScrollingEnabled) {
     myBoundedRangeModel.setRangeProperties(
         0,
         myTermSize.height,
         -myTerminalTextBuffer.getHistoryBuffer().getLineCount(),
         myTermSize.height,
         false);
   } else {
     myBoundedRangeModel.setRangeProperties(0, myTermSize.height, 0, myTermSize.height, false);
   }
 }
Example #5
0
  public TerminalPanel(
      @NotNull SettingsProvider settingsProvider,
      @NotNull TerminalTextBuffer terminalTextBuffer,
      @NotNull StyleState styleState) {
    mySettingsProvider = settingsProvider;
    myTerminalTextBuffer = terminalTextBuffer;
    myStyleState = styleState;
    myTermSize.width = terminalTextBuffer.getWidth();
    myTermSize.height = terminalTextBuffer.getHeight();
    myMaxFPS = mySettingsProvider.maxRefreshRate();

    updateScrolling();

    enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.INPUT_METHOD_EVENT_MASK);
    enableInputMethods(true);

    terminalTextBuffer.addModelListener(
        new TerminalModelListener() {
          @Override
          public void modelChanged() {
            repaint();
          }
        });
  }
Example #6
0
  @Override
  public void paintComponent(final Graphics g) {
    final Graphics2D gfx = (Graphics2D) g;

    setupAntialiasing(gfx);

    gfx.setColor(getBackground());

    gfx.fillRect(0, 0, getWidth(), getHeight());

    myTerminalTextBuffer.processHistoryAndScreenLines(
        myClientScrollOrigin,
        new StyledTextConsumer() {
          final int columnCount = getColumnCount();

          @Override
          public void consume(
              int x,
              int y,
              @NotNull TextStyle style,
              @NotNull CharBuffer characters,
              int startRow) {
            int row = y - startRow;
            drawCharacters(x, row, style, characters, gfx);
            if (mySelection != null) {
              Pair<Integer, Integer> interval =
                  mySelection.intersect(x, row + myClientScrollOrigin, characters.length());
              if (interval != null) {
                TextStyle selectionStyle = getSelectionStyle(style);
                CharBuffer selectionChars =
                    characters.subBuffer(interval.first - x, interval.second);

                drawCharacters(interval.first, row, selectionStyle, selectionChars, gfx);
              }
            }
          }

          @Override
          public void consumeNul(
              int x, int y, int nulIndex, TextStyle style, CharBuffer characters, int startRow) {
            int row = y - startRow;
            if (mySelection != null) {
              // compute intersection with all NUL areas, non-breaking
              Pair<Integer, Integer> interval =
                  mySelection.intersect(
                      nulIndex, row + myClientScrollOrigin, columnCount - nulIndex);
              if (interval != null) {
                TextStyle selectionStyle = getSelectionStyle(style);
                drawCharacters(x, row, selectionStyle, characters, gfx);
                return;
              }
            }
            drawCharacters(x, row, style, characters, gfx);
          }

          @Override
          public void consumeQueue(int x, int y, int nulIndex, int startRow) {
            if (x < columnCount) {
              consumeNul(
                  x,
                  y,
                  nulIndex,
                  TextStyle.EMPTY,
                  new CharBuffer(CharUtils.EMPTY_CHAR, columnCount - x),
                  startRow);
            }
          }
        });

    int cursorY = myCursor.getCoordY();
    if (myClientScrollOrigin + getRowCount() > cursorY) {
      int cursorX = myCursor.getCoordX();
      Pair<Character, TextStyle> sc = myTerminalTextBuffer.getStyledCharAt(cursorX, cursorY);
      TextStyle normalStyle = sc.second != null ? sc.second : myStyleState.getCurrent();
      TextStyle selectionStyle = getSelectionStyle(normalStyle);
      boolean inSelection = inSelection(cursorX, cursorY);
      myCursor.drawCursor(sc.first, gfx, inSelection ? selectionStyle : normalStyle);
    }

    drawInputMethodUncommitedChars(gfx);

    drawMargins(gfx, getWidth(), getHeight());
  }
Example #7
0
 public LinesBuffer getScrollBuffer() {
   return myTerminalTextBuffer.getHistoryBuffer();
 }