public Dimension resize(final Dimension pendingResize, final RequestOrigin origin) { final int oldHeight = myTerminalHeight; if (pendingResize.width <= MIN_WIDTH) { pendingResize.setSize(MIN_WIDTH, pendingResize.height); } final Dimension pixelSize = myDisplay.requestResize( pendingResize, origin, myCursorY, new ResizeHandler() { @Override public void sizeUpdated(int termWidth, int termHeight, int cursorY) { myTerminalWidth = termWidth; myTerminalHeight = termHeight; myCursorY = cursorY; myCursorX = Math.min(myCursorX, myTerminalWidth - 1); myTabulator.resize(myTerminalWidth); } }); myScrollRegionBottom += myTerminalHeight - oldHeight; return pixelSize; }
@Override public void backspace() { myCursorX -= 1; if (myCursorX < 0) { myCursorY -= 1; myCursorX = myTerminalWidth - 1; } 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(); } }
public JediTerminal( final TerminalDisplay display, final TerminalTextBuffer buf, final StyleState initialStyleState) { myDisplay = display; myTerminalTextBuffer = buf; myStyleState = initialStyleState; myTerminalWidth = display.getColumnCount(); myTerminalHeight = display.getRowCount(); myScrollRegionTop = 1; myScrollRegionBottom = myTerminalHeight; myTabulator = new DefaultTabulator(myTerminalWidth); myGraphicSetState = new GraphicSetState(); reset(); }
@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 void newLine() { myCursorY += 1; scrollY(); if (isAutoNewLine()) { carriageReturn(); } myDisplay.setCursor(myCursorX, myCursorY); }
@Override public void nextLine() { myTerminalTextBuffer.lock(); try { myCursorX = 0; if (myCursorY == myScrollRegionBottom) { scrollArea(myScrollRegionTop, scrollingRegionSize(), -1); } else { myCursorY += 1; } myDisplay.setCursor(myCursorX, myCursorY); } finally { myTerminalTextBuffer.unlock(); } }
public void scrollY() { myTerminalTextBuffer.lock(); try { if (myCursorY > myScrollRegionBottom) { final int dy = myScrollRegionBottom - myCursorY; myCursorY = myScrollRegionBottom; scrollArea(myScrollRegionTop, scrollingRegionSize(), dy); myDisplay.setCursor(myCursorX, myCursorY); } if (myCursorY < myScrollRegionTop) { myCursorY = myScrollRegionTop; } } finally { myTerminalTextBuffer.unlock(); } }
@Override public void reset() { myGraphicSetState.resetState(); myStyleState.reset(); myTerminalTextBuffer.clearAll(); myDisplay.setScrollingEnabled(true); initModes(); initMouseModes(); cursorPosition(1, 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 index() { // Moves the cursor down one line in the // same column. If the cursor is at the // bottom margin, the page scrolls up myTerminalTextBuffer.lock(); try { if (myCursorY == myScrollRegionBottom) { scrollArea(myScrollRegionTop, scrollingRegionSize(), -1); } else { myCursorY += 1; myDisplay.setCursor(myCursorX, myCursorY); } } finally { myTerminalTextBuffer.unlock(); } }
@Override public void reverseIndex() { // Moves the cursor up one line in the same // column. If the cursor is at the top margin, // the page scrolls down. myTerminalTextBuffer.lock(); try { if (myCursorY == myScrollRegionTop) { scrollArea(myScrollRegionTop, scrollingRegionSize(), 1); } else { myCursorY -= 1; myDisplay.setCursor(myCursorX, myCursorY); } } finally { myTerminalTextBuffer.unlock(); } }
@Override public void restoreCursor() { if (myStoredCursor != null) { restoreCursor(myStoredCursor); } else { // If nothing was saved by DECSC setModeEnabled(TerminalMode.OriginMode, false); // Resets origin mode (DECOM) cursorPosition(1, 1); // Moves the cursor to the home position (upper left of screen). myStyleState.reset(); // Turns all character attributes off (normal setting). myGraphicSetState.resetState(); // myGraphicSetState.designateGraphicSet(0, CharacterSet.ASCII);//Maps the ASCII character set // into GL // mapCharsetToGL(0); // myGraphicSetState.designateGraphicSet(1, CharacterSet.DEC_SUPPLEMENTAL); // mapCharsetToGR(1); //and the DEC Supplemental Graphic set into GR } myDisplay.setCursor(myCursorX, myCursorY); }
@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 disconnected() { myDisplay.setCursorVisible(false); }
@Override public void setWindowTitle(String name) { myDisplay.setWindowTitle(name); }
@Override public void beep() { myDisplay.beep(); }
@Override public void setCurrentPath(String path) { myDisplay.setCurrentPath(path); }
@Override public void linePositionAbsolute(int y) { myCursorY = y; 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); }
@Override public void carriageReturn() { myCursorX = 0; myDisplay.setCursor(myCursorX, myCursorY); }
@Override public void setCursorVisible(boolean visible) { myDisplay.setCursorVisible(visible); }
@Override public void setMouseMode(@NotNull MouseMode mode) { myMouseMode = mode; myDisplay.terminalMouseModeSet(mode); }
@Override public void useAlternateBuffer(boolean enabled) { myTerminalTextBuffer.useAlternateBuffer(enabled); myDisplay.setScrollingEnabled(!enabled); }
@Override public void setBlinkingCursor(boolean enabled) { myDisplay.setBlinkingCursor(enabled); }
private void scrollArea(int scrollRegionTop, int scrollRegionSize, int dy) { myDisplay.scrollArea(scrollRegionTop, scrollRegionSize, dy); myTerminalTextBuffer.scrollArea(scrollRegionTop, dy, scrollRegionTop + scrollRegionSize - 1); }
private void finishText() { myDisplay.setCursor(myCursorX, myCursorY); scrollY(); }