@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); }
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(); } }
@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(); } }
@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); }
@Override public void cursorDown(final int dY) { myTerminalTextBuffer.lock(); try { myCursorY += dY; myCursorY = Math.min(myCursorY, scrollingRegionBottom()); myDisplay.setCursor(myCursorX, myCursorY); } finally { myTerminalTextBuffer.unlock(); } }
@Override public void cursorUp(final int countY) { myTerminalTextBuffer.lock(); try { myCursorY -= countY; myCursorY = Math.max(myCursorY, scrollingRegionTop()); myDisplay.setCursor(myCursorX, myCursorY); } finally { myTerminalTextBuffer.unlock(); } }
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; } }
@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(); } }
@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); }
@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)); }
@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); }
@Override public void cursorBackward(final int dX) { myCursorX -= dX; myCursorX = Math.max(myCursorX, 0); myDisplay.setCursor(myCursorX, myCursorY); }
@Override public void cursorForward(final int dX) { myCursorX += dX; myCursorX = Math.min(myCursorX, myTerminalWidth - 1); myDisplay.setCursor(myCursorX, myCursorY); }