Example #1
0
  @Override
  public void setScrollingRegion(int top, int bottom) {
    if (top > bottom) {
      LOG.error("Top margin of scroll region can't be greater then bottom: " + top + ">" + bottom);
    }
    myScrollRegionTop = Math.max(1, top);
    myScrollRegionBottom = Math.min(myTerminalHeight, bottom);

    // DECSTBM moves the cursor to column 1, line 1 of the page
    cursorPosition(1, 1);
  }
Example #2
0
 public void eraseInLine(int arg) {
   myTerminalTextBuffer.lock();
   try {
     switch (arg) {
       case 0:
         if (myCursorX < myTerminalWidth) {
           myTerminalTextBuffer.eraseCharacters(myCursorX, myTerminalWidth, myCursorY - 1);
         }
         // delete to the end of line : line is no more wrapped
         myTerminalTextBuffer.getLine(myCursorY - 1).setWrapped(false);
         break;
       case 1:
         final int extent = Math.min(myCursorX + 1, myTerminalWidth);
         myTerminalTextBuffer.eraseCharacters(0, extent, myCursorY - 1);
         break;
       case 2:
         myTerminalTextBuffer.eraseCharacters(0, myTerminalWidth, myCursorY - 1);
         break;
       default:
         LOG.error("Unsupported erase in line mode:" + arg);
         break;
     }
   } finally {
     myTerminalTextBuffer.unlock();
   }
 }
Example #3
0
 @Override
 public void insertBlankCharacters(int count) {
   myTerminalTextBuffer.lock();
   try {
     final int extent = Math.min(count, myTerminalWidth - myCursorX);
     myTerminalTextBuffer.insertBlankCharacters(myCursorX, myCursorY - 1, extent);
   } finally {
     myTerminalTextBuffer.unlock();
   }
 }
Example #4
0
  @Override
  public void cursorPosition(int x, int y) {
    if (isOriginMode()) {
      myCursorY = y + scrollingRegionTop() - 1;
    } else {
      myCursorY = y;
    }

    if (myCursorY > scrollingRegionBottom()) {
      myCursorY = scrollingRegionBottom();
    }

    // avoid issue due to malformed sequence
    myCursorX = Math.max(0, x - 1);
    myCursorX = Math.min(myCursorX, myTerminalWidth - 1);

    myCursorY = Math.max(0, myCursorY);

    myDisplay.setCursor(myCursorX, myCursorY);
  }
Example #5
0
 @Override
 public void cursorDown(final int dY) {
   myTerminalTextBuffer.lock();
   try {
     myCursorY += dY;
     myCursorY = Math.min(myCursorY, scrollingRegionBottom());
     myDisplay.setCursor(myCursorX, myCursorY);
   } finally {
     myTerminalTextBuffer.unlock();
   }
 }
Example #6
0
 @Override
 public void cursorUp(final int countY) {
   myTerminalTextBuffer.lock();
   try {
     myCursorY -= countY;
     myCursorY = Math.max(myCursorY, scrollingRegionTop());
     myDisplay.setCursor(myCursorX, myCursorY);
   } finally {
     myTerminalTextBuffer.unlock();
   }
 }
Example #7
0
 public void writeUnwrappedString(String string) {
   int length = string.length();
   int off = 0;
   while (off < length) {
     int amountInLine = Math.min(distanceToLineEnd(), length - off);
     writeString(string.substring(off, off + amountInLine));
     wrapLines();
     scrollY();
     off += amountInLine;
   }
 }
Example #8
0
 @Override
 public void eraseCharacters(int count) {
   // Clear the next n characters on the cursor's line, including the cursor's
   // position.
   myTerminalTextBuffer.lock();
   try {
     final int extent = Math.min(count, myTerminalWidth - myCursorX);
     myTerminalTextBuffer.eraseCharacters(myCursorX, myCursorX + extent, myCursorY - 1);
   } finally {
     myTerminalTextBuffer.unlock();
   }
 }
Example #9
0
    @Override
    public int previousTab(int position) {
      int tabStop = 0;

      // Search for the first tab stop before the given position...
      SortedSet<Integer> headSet = myTabStops.headSet(Integer.valueOf(position));
      if (!headSet.isEmpty()) {
        tabStop = headSet.last();
      }

      // Don't go beyond the start of the line...
      return Math.max(0, tabStop);
    }
Example #10
0
    @Override
    public int nextTab(int position) {
      int tabStop = Integer.MAX_VALUE;

      // Search for the first tab stop after the given position...
      SortedSet<Integer> tailSet = myTabStops.tailSet(position + 1);
      if (!tailSet.isEmpty()) {
        tabStop = tailSet.first();
      }

      // Don't go beyond the end of the line...
      return Math.min(tabStop, (myWidth - 1));
    }
Example #11
0
 @Override
 public void horizontalTab() {
   if (myCursorX >= myTerminalWidth) {
     return;
   }
   int length = myTerminalTextBuffer.getLine(myCursorY - 1).getText().length();
   int stop = myTabulator.nextTab(myCursorX);
   myCursorX = Math.max(myCursorX, length);
   if (myCursorX < stop) {
     char[] chars = new char[stop - myCursorX];
     Arrays.fill(chars, CharUtils.EMPTY_CHAR);
     doWriteString(new String(chars));
   } else {
     myCursorX = stop;
   }
   myDisplay.setCursor(myCursorX, myCursorY);
 }
Example #12
0
 @Override
 public void cursorBackward(final int dX) {
   myCursorX -= dX;
   myCursorX = Math.max(myCursorX, 0);
   myDisplay.setCursor(myCursorX, myCursorY);
 }
Example #13
0
 @Override
 public void cursorForward(final int dX) {
   myCursorX += dX;
   myCursorX = Math.min(myCursorX, myTerminalWidth - 1);
   myDisplay.setCursor(myCursorX, myCursorY);
 }