⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terminalwin.java

📁 一个非常好的ssh客户端实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	    int iic;	    if((iic = interpreter.interpretChar(c)) != TerminalInterpreter.IGNORE) {		char ic;		if (translator == null) {		    ic = (char)iic;		} else {		    ic = translator.translate((char)iic);		}		checkWrap();		if(termOptions[OPT_INSERTMODE]) {		    insertChars(1);		}		// Keep track of the spanning update area		//		updateDirtyArea(curRow, curCol, curRow + 1, curCol + 1);		int idxRow = visTop + curRow;		attributes[idxRow][curCol] = curAttr;		screen[idxRow][curCol++]   = ic;	    }	    repaint();	}    }    public final void write(char[] c, int off, int len) {	synchronized(writeLock) {	    waitForMore    = (len > 64);	    repaintPending = true; // To inhibit repaint() until after for-loop	    int end = off + len;	    for(int i = off; i < end; i++) {		write(c[i]);	    }	    repaintPending = false;	    repaint();	}    }    public final void write(byte[] c, int off, int len) {	synchronized(writeLock) {	    waitForMore    = (len > 64);	    repaintPending = true; // To inhibit repaint() until after for-loop	    int end = off + len;	    for(int i = off; i < end; i++) {		write(byte2char[(int)(c[i] & 0xff)]);	    }	    repaintPending = false;	    repaint();	}    }    public final void write(String s) {	char[] carr = s.toCharArray();	write(carr, 0, carr.length);    }    public void writeLineDrawChar(char c) {	checkWrap();	// Keep track of the spanning update area	//	updateDirtyArea(curRow, curCol, curRow + 1, curCol + 1);	int idxRow = visTop + curRow;	attributes[idxRow][curCol] = (curAttr | ATTR_LINEDRAW);	screen[idxRow][curCol++]   = c;    }    private final void checkWrap() {	if(curCol == cols) {	    if(termOptions[OPT_AUTO_WRAP]) {		autowraps[visTop + curRow] = true;		curRow += 1;		curCol = 0;		if(curRow == windowBottom) {		    scrollUp(1);		    curRow = windowBottom - 1;		}	    } else		curCol--;	}    }    public void addInputListener(TerminalInputListener inListener) {	if(inListeners == null) {	    inListeners = new Vector();	}	inListeners.removeElement(inListener);	inListeners.addElement(inListener);    }    public void removeInputListener(TerminalInputListener inListener) {	if(inListeners != null) {	    inListeners.removeElement(inListener);	    if(inListeners.size() == 0) {		inListeners = null;	    }	}    }    public void addOutputListener(TerminalOutputListener outListener) {	if(outListeners == null) {	    outListeners = new Vector();	}	outListeners.removeElement(outListener);	outListeners.addElement(outListener);    }    public void removeOutputListener(TerminalOutputListener outListener) {	if(outListeners != null) {	    outListeners.removeElement(outListener);	    if(outListeners.size() == 0) {		outListeners = null;	    }	}    }    public void attachPrinter(TerminalPrinter printer) {	this.printer = printer;    }    public void detachPrinter() {	this.printer = null;    }    public void setClipboard(TerminalClipboardHandler clipboard) {	this.clipboard = clipboard;	if(hasSelection) {	    clipboard.setSelection(getSelection());	} else {	    clipboard.clearSelection();	}    }    public TerminalClipboardHandler getClipboard() {	return clipboard;    }    public void typedChar(char c) {	if(DEBUG) System.out.println("typedChar: " + c + "(" + (int)c + ")");	if(inListeners != null) {	    int n = inListeners.size();	    for(int i = 0; i < n; i++) {		TerminalInputListener inListener = (TerminalInputListener)		    inListeners.elementAt(i);		if(inListener != null) {		    inListener.typedChar(c);		}	    }	}    }    public final void sendBytes(byte[] b) {	if(DEBUG) System.out.println("Sending " + b.length + " bytes");	if(inListeners != null) {	    int n = inListeners.size();	    for(int i = 0; i < n; i++) {		TerminalInputListener inListener = (TerminalInputListener)		    inListeners.elementAt(i);		if(inListener != null) {		    inListener.sendBytes(b);		}	    }	}    }    public void signalWindowChanged(int rows, int cols, int vpixels, int hpixels) {	if(DEBUG) System.out.println("SIGWINCH: " + rows + ", " + cols);	if(inListeners != null) {	    int n = inListeners.size();	    for(int i = 0; i < n; i++) {		TerminalInputListener inListener = (TerminalInputListener)		    inListeners.elementAt(i);		if(inListener != null) {		    inListener.signalWindowChanged(rows, cols, vpixels, hpixels);		}	    }	}    }    public void doBell() {	if(termOptions[OPT_VIS_BELL]) {	    setOption(OPT_REV_VIDEO, !termOptions[OPT_REV_VIDEO]);	    try { Thread.sleep(25); } catch (InterruptedException e) { }	    setOption(OPT_REV_VIDEO, !termOptions[OPT_REV_VIDEO]);	} else {	    Toolkit toolkit = Toolkit.getDefaultToolkit();	    if(toolkit != null) {		try {		    toolkit.beep();		} catch (Exception e) {		    // !!! Could not beep, we are probably an unpriviliged applet		    // Automatically enable visual-bell now and "sound" it instead		    //		    setOption(OPT_VIS_BELL, true);		    doBell();		}	    }	}    }    public void doBS() {	if(DEBUG) System.out.println("doBS");	cursorBackward(1);    }    public void doTab() {	int i;	if(curCol < windowRight) {	    for(i = curCol + 1; i < windowRight; i++)		if(tabStops[i])		    break;	    curCol = (i < windowRight ? i : windowRight - 1);	}	if(DEBUG) System.out.println("doTab");    }    public void doTabs(int n) {	while(n-- > 0)	    doTab();    }    public void doBackTabs(int n) {	if(DEBUG) System.out.println("doBackTabs: " + n);	int i;	if(curCol > 0 && n >= 0) {	    for(i = curCol - 1; i >= 0; i--) {		if(tabStops[i]) {		    if(--n == 0)			break;		}	    }	    curCol = (i < 0 ? 0 : i);	}    }    public void setTab(int col) {	tabStops[col] = true;    }    public void clearTab(int col) {	tabStops[col] = false;    }    public void resetTabs() {	for(int i = 0; i < MAX_COLS; i++) {	    if((i % 8) == 0)		tabStops[i] = true;	    else		tabStops[i] = false;	}    }    public void clearAllTabs() {	for(int i = 0; i < MAX_COLS; i++)	    tabStops[i] = false;    }    public void doCR() {	curCol = windowLeft;	if(DEBUG) System.out.println("doCR");    }    public void doLF() {	curRow += 1;	if(curRow == windowBottom) {	    scrollUp(1);	    curRow = windowBottom - 1;	}	if(termOptions[OPT_AUTO_LF]) {	    doCR();	}	if(DEBUG) System.out.println("doLF");    }    public void resetInterpreter() {	interpreter.vtReset();	makeAllDirty(true);    }    public void resetWindow() {	windowTop     = 0;	windowBottom  = rows;	windowLeft    = 0;	windowRight   = cols;	complexScroll = false;    }    public void setWindow(int top, int bottom) {	setWindow(top, 0, bottom, cols);    }    public void setWindow(int top, int left, int bottom, int right) {	windowTop    = top;	windowLeft   = left;	windowBottom = bottom;	windowRight  = right;	if(DEBUG) System.out.println("setWindow: " + top + ", " + bottom + ", " + left + ", " + right);	// Ensure that the selected area is totally outside the scrolling	// region OR that the scrolling region starts at the top of the	// screen and the selection is completely above the scrolling	// regions bottom. This makes things alot easier and is not that much	// of problem.	//	if(hasSelection) {	    int selRowAnch = selectRowAnchor - visTop;	    int selRowLast = selectRowLast - visTop;	    if(top != 0 && (selRowAnch >= 0 || selRowLast >= 0)) {		if(!(selRowAnch < top && selRowLast < top ||		     selRowAnch >= bottom && selRowLast >= bottom)) {		    clearSelection();		}	    } else {		if(!(selRowAnch < bottom && selRowLast < bottom)) {		    clearSelection();		}	    }	}	if(windowLeft != 0 || windowRight != cols)	    complexScroll = true;	else	    complexScroll = false;    }    public int  getWindowTop() {	return windowTop;    }    public int  getWindowBottom() {	return windowBottom;    }    public int  getWindowLeft() {	return windowLeft;    }    public int  getWindowRight() {	return windowRight;    }    public int getCursorV() {	return curRow;    }    public int getCursorH() {	return curCol;    }    public void cursorSetPos(int v, int h, boolean relative) {	if(DEBUG) System.out.println("cursorSetPos: " + v + ", " + h + "(" + relative + ")");	int maxV = rows - 1;	int maxH = cols - 1;	int minV = 0;	int minH = 0;	if(relative) {	    v += windowTop;	    maxV = windowBottom - 1;	    minV = windowTop;	    h += windowLeft;	    maxH = windowRight - 1;	    minH = windowLeft;	}	if(v < minV)	    v = minV;	if(h < minH)	    h = minH;	if(v > maxV)	    v = maxV;	if(h > maxH)	    h = maxH;	curRow = v;	curCol = h;    }    public void cursorUp(int n) {	if(DEBUG) System.out.println("cursorUp: " + n);	int min = (curRow < windowTop ? 0 : windowTop);	curRow -= n;	if(curRow < min)	    curRow = min;    }    public void cursorDown(int n) {	if(DEBUG) System.out.println("cursorDown: " + n);	int max = (curRow > windowBottom - 1 ? rows - 1: windowBottom - 1);	curRow += n;	if(curRow > max)	    curRow = max;    }    public void cursorForward(int n) {	if(DEBUG) System.out.println("cursorFwd: " + n);	curCol += n;	if(curCol > windowRight)	    curCol = windowRight;    }    public void cursorBackward(int n) {	if(DEBUG) System.out.println("cursorBack: " + n);	curCol -= n;	if(curCol < windowLeft) {	    if(termOptions[OPT_REV_WRAP]) {		curCol = windowRight - (windowLeft - curCol);		cursorUp(1);	    } else {		curCol = windowLeft;	    }	}    }    public void cursorIndex(int n) {	if(DEBUG) System.out.println("cursorIndex: " + n);	if(curRow > windowBottom || curRow + n < windowBottom)	    cursorDown(n);	else {	    int m = windowBottom - curRow;	    cursorDown(m);	    scrollUp((n - m) + 1);	}    }    public void cursorIndexRev(int n) {	if(DEBUG) System.out.println("cursorIndexRev: " + n);	if(curRow < windowTop || curRow - n >= windowTop)	    cursorUp(n);	else {	    int m = curRow - windowTop;	    scrollDown(n - m);	    cursorUp(m);	}    }    public void cursorSave() {	curRowSave  = curRow;	curColSave  = curCol;	curAttrSave = curAttr;    }    public void cursorRestore() {	curRow  = curRowSave;	curCol  = curColSave;	curAttr = curAttrSave;    }    public synchronized void scrollUp(int n) {	int windowHeight = windowBottom - windowTop;	int i, j = windowTop;	if(DEBUG) System.out.println("scrollUp: " + n);	if(complexScroll) {	    // !!! TODO: This is untested...	    if(n < windowHeight) {		j = (windowHeight - n) + windowTop;		for(i = windowTop; i < j; i++) {		    System.arraycopy(screen[visTop + i + n], windowLeft, screen[visTop + i],				     windowLeft, windowRight - windowLeft);		    System.arraycopy(attributes[visTop + i + n], windowLeft,				     attributes[visTop + i], windowLeft, (windowRight - windowLeft));		}	    }	    for(i = j; i < windowBottom; i++) {		System.arraycopy(spacerow, 0, screen[visTop + i], windowLeft, windowRight - windowLeft);		System.arraycopy(zerorow, 0, attributes[visTop + i], windowLeft, (windowRight - windowLeft));	    }	} else {	    if(windowTop == 0 && (windowBottom == rows) && saveLines > 0) {		int sl = (n < windowHeight ? n : windowHeight);		int ll;		if((visTop + sl) > saveLines) {		    if(hasSelection) {			if(!(((selectRowAnchor - n) < 0) || ((selectRowLast   - n) < 0))) {			    selectRowAnchor -= n;			    selectRowLast -= n;			} else {			    clearSelection();			}		    }		    ll = windowHeight - sl;		    System.arraycopy(screen, sl, screen, 0, saveLines + ll);		    System.arraycopy(attributes, sl, attributes, 0, saveLines + ll);		    System.arraycopy(autowraps, sl, autowraps, 0, saveLines + ll);		    for(i = windowHeight - sl; i < windowHeight; i++) {			screen[saveLines + i]     = new char[cols];			attributes[saveLines + i] = new int[cols];			autowraps[saveLines + i] = false;		    }		} else {		    visTop    += sl;		    saveVisTop = visTop;		    updateScrollbarValues();		}	    } else {		if(n < windowHeight) {		    j = (windowHeight - n) + windowTop;		    System.arraycopy(screen, visTop + windowTop + n, screen, visTop + windowTop,				     (windowHeight - n));		    System.arraycopy(attributes, visTop + windowTop + n, attributes,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -