@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); }
@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 cursorUp(final int countY) { myTerminalTextBuffer.lock(); try { myCursorY -= countY; myCursorY = Math.max(myCursorY, scrollingRegionTop()); myDisplay.setCursor(myCursorX, myCursorY); } 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 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); }
protected Point panelToCharCoords(final Point p) { int x = Math.min(p.x / myCharSize.width, getColumnCount() - 1); x = Math.max(0, x); int y = Math.min(p.y / myCharSize.height, getRowCount() - 1) + myClientScrollOrigin; return new Point(x, y); }
@Override public void cursorBackward(final int dX) { myCursorX -= dX; myCursorX = Math.max(myCursorX, 0); myDisplay.setCursor(myCursorX, myCursorY); }