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

📄 terminalxterm.java

📁 一个非常好的ssh客户端实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************** * * Copyright (c) 1999-2003 AppGate Network Security AB. All Rights Reserved. *  * This file contains Original Code and/or Modifications of Original Code as * defined in and that are subject to the MindTerm Public Source License, * Version 2.0, (the 'License'). You may not use this file except in compliance * with the License. *  * You should have received a copy of the MindTerm Public Source License * along with this software; see the file LICENSE.  If not, write to * AppGate Network Security AB, Otterhallegatan 2, SE-41118 Goteborg, SWEDEN * *****************************************************************************//* * Author's comment: The contents of this file is heavily based upon * xterm from the X Consortium, original copyright notices included * below. *//*Copyright (c) 1988  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*//* * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. * *                         All Rights Reserved * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation, and that the name of Digital Equipment * Corporation not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior permission. * * * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. */package com.mindbright.terminal;import java.util.NoSuchElementException;import java.awt.event.KeyEvent;import java.awt.event.InputEvent;public final class TerminalXTerm extends TerminalInterpreter {  // !!! Set to true for extensive debug  //  public final static boolean DEBUG        = false;  public final static boolean DEBUGNOTIMPL = false;  public final static boolean DEBUGPRINT   = false;  public final static int CASE_GROUND_STATE  = 0;  public final static int CASE_IGNORE_STATE  = 1;  public final static int CASE_IGNORE_ESC    = 2;  public final static int CASE_IGNORE        = 3;  public final static int CASE_BELL          = 4;  public final static int CASE_BS            = 5;  public final static int CASE_CR            = 6;  public final static int CASE_ESC           = 7;  public final static int CASE_VMOT          = 8;  public final static int CASE_TAB           = 9;  public final static int CASE_SI            = 10;  public final static int CASE_SO            = 11;  public final static int CASE_SCR_STATE     = 12;  public final static int CASE_SCS0_STATE    = 13;  public final static int CASE_SCS1_STATE    = 14;  public final static int CASE_SCS2_STATE    = 15;  public final static int CASE_SCS3_STATE    = 16;  public final static int CASE_ESC_IGNORE    = 17;  public final static int CASE_ESC_DIGIT     = 18;  public final static int CASE_ESC_SEMI      = 19;  public final static int CASE_DEC_STATE     = 20;  public final static int CASE_ICH           = 21;  public final static int CASE_CUU           = 22;  public final static int CASE_CUD           = 23;  public final static int CASE_CUF           = 24;  public final static int CASE_CUB           = 25;  public final static int CASE_CUP           = 26;  public final static int CASE_ED            = 27;  public final static int CASE_EL            = 28;  public final static int CASE_IL            = 29;  public final static int CASE_DL            = 30;  public final static int CASE_DCH           = 31;  public final static int CASE_DA1           = 32;  public final static int CASE_TRACK_MOUSE   = 33;  public final static int CASE_TBC           = 34;  public final static int CASE_SET           = 35;  public final static int CASE_RST           = 36;  public final static int CASE_SGR           = 37;  public final static int CASE_CPR           = 38;  public final static int CASE_DECSTBM       = 39;  public final static int CASE_DECREQTPARM   = 40;  public final static int CASE_DECSET        = 41;  public final static int CASE_DECRST        = 42;  public final static int CASE_DECALN        = 43;  public final static int CASE_GSETS         = 44;  public final static int CASE_DECSC         = 45;  public final static int CASE_DECRC         = 46;  public final static int CASE_DECKPAM       = 47;  public final static int CASE_DECKPNM       = 48;  public final static int CASE_IND           = 49;  public final static int CASE_NEL           = 50;  public final static int CASE_HTS           = 51;  public final static int CASE_RI            = 52;  public final static int CASE_SS2           = 53;  public final static int CASE_SS3           = 54;  public final static int CASE_CSI_STATE     = 55;  public final static int CASE_OSC           = 56;  public final static int CASE_RIS           = 57;  public final static int CASE_LS2           = 58;  public final static int CASE_LS3           = 59;  public final static int CASE_LS3R          = 60;  public final static int CASE_LS2R          = 61;  public final static int CASE_LS1R          = 62;  public final static int CASE_PRINT         = 63;  public final static int CASE_XTERM_SAVE    = 64;  public final static int CASE_XTERM_RESTORE = 65;  public final static int CASE_XTERM_TITLE   = 66;  public final static int CASE_DECID         = 67;  public final static int CASE_HP_MEM_LOCK   = 68;  public final static int CASE_HP_MEM_UNLOCK = 69;  public final static int CASE_HP_BUGGY_LL   = 70;  public final static int CASE_SEQ_CAPTURE   = 71;  public final static int CASE_ESC_SEMIOSC   = 72;  public final static int CASE_XTERM_SEQ     = 73;  public final static int CASE_ENQ           = 74;  public final static int CASE_XTERMWIN      = 75;  public final static int CASE_CNL           = 76;  public final static int CASE_CPL           = 77;  public final static int CASE_CHA           = 78;  public final static int CASE_CHT           = 79;  public final static int CASE_SU            = 80;  public final static int CASE_SD            = 81;  public final static int CASE_ECH           = 82;  public final static int CASE_CBT           = 83;  public final static int CASE_HPA           = 84;  public final static int CASE_REP           = 85;  public final static int CASE_VPA           = 86;  public final static int CASE_ANSI_PRINTER  = 87;  public final static int[] asciiLineDrawChars = {      ' ',  // 0x5f - _      '+',  // 0x60 - `      ':',  // 0x61 - a      ' ',  // 0x62 - b      ' ',  // 0x63 - c      ' ',  // 0x64 - d      ' ',  // 0x65 - e      '\\', // 0x66 - f      '#',  // 0x67 - g      '#',  // 0x68 - h      '#',  // 0x69 - i      '+',  // 0x6a - j      '+',  // 0x6b - k      '+',  // 0x6c - l      '+',  // 0x6d - m      '+',  // 0x6e - n      '~',  // 0x6f - o      '-',  // 0x70 - p      '-',  // 0x71 - q      '-',  // 0x72 - r      '_',  // 0x73 - s      '+',  // 0x74 - t      '+',  // 0x75 - u      '+',  // 0x76 - v      '+',  // 0x77 - w      '|',  // 0x78 - x      '<',  // 0x79 - y      '>',  // 0x7a - z      '*',  // 0x7b - {      '!',  // 0x7c - |      'f',  // 0x7d - }      'o',  // 0x7e - ~      '>',  // 0x2b - +      '<',  // 0x2c - ,      '^',  // 0x2d - -      'v',  // 0x2e - .  };  public final static int XVK_UP        = 0;  public final static int XVK_DOWN      = 1;  public final static int XVK_RIGHT     = 2;  public final static int XVK_LEFT      = 3;  public final static int XVK_PAGE_UP   = 4;  public final static int XVK_PAGE_DOWN = 5;  public final static int XVK_END       = 6;  public final static int XVK_HOME      = 7;  public final static int XVK_INSERT    = 8;  public final static int XVK_F1        = 9;  public final static int XVK_F2        = 10;  public final static int XVK_F3        = 11;  public final static int XVK_F4        = 12;  public final static int XVK_F5        = 13;  public final static int XVK_F6        = 14;  public final static int XVK_F7        = 15;  public final static int XVK_F8        = 16;  public final static int XVK_F9        = 17;  public final static int XVK_F10       = 18;  public final static int XVK_F11       = 19;  public final static int XVK_F12       = 20;  public final static int XVK_NUMPAD0   = 21;  public final static int XVK_NUMPAD1   = 22;  public final static int XVK_NUMPAD2   = 23;  public final static int XVK_NUMPAD3   = 24;  public final static int XVK_NUMPAD4   = 25;  public final static int XVK_NUMPAD5   = 26;  public final static int XVK_NUMPAD6   = 27;  public final static int XVK_NUMPAD7   = 28;  public final static int XVK_NUMPAD8   = 29;  public final static int XVK_NUMPAD9   = 30;  public final static int XVK_MULTIPLY  = 31;  public final static int XVK_ADD       = 32;  public final static int XVK_SUBTRACT  = 33;  public final static int XVK_DIVIDE    = 34;  public final static int XVK_MAX       = 35;  public final int[] vk2xvk = {    KeyEvent.VK_UP,    KeyEvent.VK_DOWN,    KeyEvent.VK_RIGHT,    KeyEvent.VK_LEFT,    KeyEvent.VK_PAGE_UP,    KeyEvent.VK_PAGE_DOWN,    KeyEvent.VK_END,    KeyEvent.VK_HOME,    KeyEvent.VK_INSERT,    KeyEvent.VK_F1,    KeyEvent.VK_F2,    KeyEvent.VK_F3,    KeyEvent.VK_F4,    KeyEvent.VK_F5,    KeyEvent.VK_F6,    KeyEvent.VK_F7,    KeyEvent.VK_F8,    KeyEvent.VK_F9,    KeyEvent.VK_F10,    KeyEvent.VK_F11,    KeyEvent.VK_F12,    KeyEvent.VK_NUMPAD0,    KeyEvent.VK_NUMPAD1,    KeyEvent.VK_NUMPAD2,    KeyEvent.VK_NUMPAD3,    KeyEvent.VK_NUMPAD4,    KeyEvent.VK_NUMPAD5,    KeyEvent.VK_NUMPAD6,    KeyEvent.VK_NUMPAD7,    KeyEvent.VK_NUMPAD8,    KeyEvent.VK_NUMPAD9,    KeyEvent.VK_MULTIPLY,    KeyEvent.VK_ADD,    KeyEvent.VK_SUBTRACT,    KeyEvent.VK_DIVIDE,  };  public final static int EMUL_XTERM    = 0;  public final static int EMUL_LINUX    = 1;  public final static int EMUL_SCOANSI  = 2;  public final static int EMUL_ATT6386  = 3;  public final static int EMUL_SUN      = 4;  public final static int EMUL_AIX      = 5;  public final static int EMUL_VT220    = 6;  public final static int EMUL_VT100    = 7;  public final static int EMUL_ANSI     = 8;  public final static int EMUL_VT52     = 9;  public final static int EMUL_ALTERNATENAME = 10;  public final static int EMUL_XTERMCOL      = EMUL_ALTERNATENAME + EMUL_XTERM;  public final static int EMUL_LINUXLAT      = EMUL_ALTERNATENAME + EMUL_LINUX;  public final static int EMUL_AT386         = EMUL_ALTERNATENAME + EMUL_ATT6386;  public final static int EMUL_VT102         = EMUL_ALTERNATENAME + EMUL_VT100;  public final static int EMUL_VT320         = EMUL_ALTERNATENAME + EMUL_VT220;  public final static boolean hasNullPadding(int personality) {    if(personality == EMUL_VT220 ||       personality == EMUL_VT100 ||       personality == EMUL_ANSI ||       personality == EMUL_VT52)      return true;    return false;  }  public final static int DEFAULT_TERM = EMUL_XTERM;  public final static String[] terminalTypes = {    "xterm", "linux", "scoansi",  "att6386", "sun", "aixterm",    "vt220", "vt100", "ansi",  "vt52",    "xterm-color", "linux-lat", "", "at386", "", "", "vt320", "vt102"  };  int whoAmI;  int whoAmIReally;  public final static String[][] specialKeyMap = {    //xterm   linux   scoansi att6386 sun     aixterm vt220   vt100   ansi    vt52    { "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A"  },    { "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B"  },    { "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C"  },    { "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D"  },    { "5~",   "5~",   "I",    "V",    "216z", "150q", "5~",   "5~",   "5~",   "5~" },    { "6~",   "6~",   "G",    "U",    "222z", "154q", "6~",   "6~",   "6~",   "6~" },    { "F",    "4~",   "F",    "Y",    "220z", "146q", "4~",   "4~",   "4~",   "4~" },    { "H",    "1~",   "H",    "H",    "214z", "H",    "1~",   "1~",   "1~",   "1~" },    { "2~",   "2~",   "L",    "@",    "2~",   "139q", "2~",   "2~",   "L",    "L"  },    { "11~",  "[A",   "M",    "P",    "224z", "001q", "P",    "P",    "P",    "P"  },    { "12~",  "[B",   "N",    "Q",    "225z", "002q", "Q",    "Q",    "Q",    "Q"  },    { "13~",  "[C",   "O",    "R",    "226z", "003q", "R",    "R",    "R",    "R"  },    { "14~",  "[D",   "P",    "S",    "227z", "004q", "S",    "S",    "S",    "S"  },    { "15~",  "[E",   "Q",    "T",    "228z", "005q", "17~",  null,   null,   null },    { "17~",  "17~",  "R",    "U",    "229z", "006q", "18~",  null,   null,   null },    { "18~",  "18~",  "S",    "V",    "230z", "007q", "19~",  null,   null,   null },    { "19~",  "19~",  "T",    "W",    "231z", "008q", "20~",  null,   null,   null },    { "20~",  "20~",  "U",    "X",    "232z", "009q", "21~",  null,   null,   null },    { "21~",  "21~",  "V",    "Y",    "233z", "010q", "29~",  null,   null,   null },    { "23~",  "23~",  "W",    "Z",    "234z", "011q", null,   null,   null,   null },    { "24~",  "24~",  "X",    "A",    "235z", "012q", null,   null,   null,   null },    // !!! NUMPAD missing, this is not trivial given java's messy so called virtual keys... :-(  };  public final static String[][] specialKeyMapShift = {    //xterm   linux   scoansi att6386 sun     aixterm vt220   vt100   ansi    vt52    { "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A"  },    { "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B"  },    { "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C"  },    { "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D"  },    { "5~",   "5~",   "I",    "V",    "216z", "150q", "5~",   "5~",   "5~",   "5~" },    { "6~",   "6~",   "G",    "U",    "222z", "154q", "6~",   "6~",   "6~",   "6~" },    { "4~",   "4~",   "F",    "Y",    "220z", "146q", "4~",   "4~",   "4~",   "4~" },    { "@",    "1~",   "H",    "H",    "214z", "H",    "1~",   "1~",   "1~",   "1~" },    { "2~",   "2~",   "L",    "@",    "2~",   "139q", "2~",   "2~",   "L",    "L"  },    { "23~",  "23~",  "Y",    "P",    "224z", "013q", "P",    "P",    "P",    "P"  },    { "24~",  "24~",  "Z",    "Q",    "225z", "014q", "Q",    "Q",    "Q",    "Q"  },    { "25~",  "25~",  "a",    "R",    "226z", "015q", "R",    "R",    "R",    "R"  },    { "26~",  "26~",  "b",    "S",    "227z", "016q", "S",    "S",    "S",    "S"  },    { "28~",  "28~",  "c",    "T",    "228z", "017q", "17~",  null,   null,   null },    { "29~",  "29~",  "d",    "U",    "229z", "018q", "18~",  null,   null,   null },    { "31~",  "31~",  "e",    "V",    "230z", "019q", "19~",  null,   null,   null },    { "32~",  "32~",  "f",    "W",    "231z", "020q", "20~",  null,   null,   null },    { "33~",  "33~",  "g",    "X",    "232z", "021q", "21~",  null,   null,   null },    { "34~",  "34~",  "h",    "Y",    "233z", "022q", "29~",  null,   null,   null },    { "23$",  null,   "i",    "Z",    "234z", "023q", null,   null,   null,   null },    { "24$",  null,   "j",    "A",    "235z", "024q", null,   null,   null,   null },    // !!! NUMPAD missing, this is not trivial given java's messy so called virtual keys... :-(  };  public final static String[][] specialKeyMapCtrl = {    //xterm   linux   scoansi att6386 sun     aixterm vt220   vt100   ansi    vt52    { "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A"  },    { "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B"  },    { "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C"  },    { "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D"  },    { "5~",   "5~",   "I",    "V",    "216z", "150q", "5~",   "5~",   "5~",   "5~" },    { "6~",   "6~",   "G",    "U",    "222z", "154q", "6~",   "6~",   "6~",   "6~" },    { "4~",   "4~",   "F",    "Y",    "220z", "146q", "4~",   "4~",   "4~",   "4~" },    { "@",    "1~",   "H",    "H",    "214z", "H",    "1~",   "1~",   "1~",   "1~" },    { "2~",   "2~",   "L",    "@",    "2~",   "139q", "2~",   "2~",   "L",    "L"  },    { "11^",  null,   "k",    "P",    "224z", "025q", "P",    "P",    "P",    "P"  },    { "12^",  null,   "l",    "Q",    "225z", "026q", "Q",    "Q",    "Q",    "Q"  },    { "13^",  null,   "m",    "R",    "226z", "027q", "R",    "R",    "R",    "R"  },    { "14^",  null,   "n",    "S",    "227z", "028q", "S",    "S",    "S",    "S"  },    { "15^",  null,   "o",    "T",    "228z", "029q", "17~",  null,   null,   null },    { "17^",  null,   "p",    "U",    "229z", "030q", "18~",  null,   null,   null },    { "18^",  null,   "q",    "V",    "230z", "031q", "19~",  null,   null,   null },    { "19^",  null,   "r",    "W",    "231z", "032q", "20~",  null,   null,   null },    { "20^",  null,   "s",    "X",    "232z", "033q", "21~",  null,   null,   null },    { "21^",  null,   "t",    "Y",    "233z", "034q", "29~",  null,   null,   null },    { "23^",  null,   "u",    "Z",    "234z", "035q", null,   null,   null,   null },    { "24^",  null,   "v",    "A",    "235z", "036q", null,   null,   null,   null },    // !!! NUMPAD missing, this is not trivial given java's messy so called virtual keys... :-(  };  public final static String[][] specialKeyMapCtrlShift = {    //xterm   linux   scoansi att6386 sun     aixterm vt220   vt100   ansi    vt52    { "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A",    "A"  },    { "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B",    "B"  },    { "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C",    "C"  },    { "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D",    "D"  },    { "5~",   "5~",   "I",    "V",    "216z", "150q", "5~",   "5~",   "5~",   "5~" },    { "6~",   "6~",   "G",    "U",    "222z", "154q", "6~",   "6~",   "6~",   "6~" },    { "4~",   "4~",   "F",    "Y",    "220z", "146q", "4~",   "4~",   "4~",   "4~" },    { "@",    "1~",   "H",    "H",    "214z", "H",    "1~",   "1~",   "1~",   "1~" },    { "2~",   "2~",   "L",    "@",    "2~",   "139q", "2~",   "2~",   "L",    "L"  },    { "23^",  null,   "w",    "P",    "224z", "001q", "P",    "P",    "P",    "P"  },    { "24^",  null,   "x",    "Q",    "225z", "002q", "Q",    "Q",    "Q",    "Q"  },    { "25^",  null,   "y",    "R",    "226z", "003q", "R",    "R",    "R",    "R"  },    { "26^",  null,   "z",    "S",    "227z", "004q", "S",    "S",    "S",    "S"  },    { "28^",  null,   "@",    "T",    "228z", "005q", "17~",  null,   null,   null },    { "29^",  null,   "[",    "U",    "229z", "006q", "18~",  null,   null,   null },    { "31^",  null,   "\\",   "V",    "230z", "007q", "19~",  null,   null,   null },    { "32^",  null,   "]",    "W",    "231z", "008q", "20~",  null,   null,   null },    { "33^",  null,   "^",    "X",    "232z", "009q", "21~",  null,   null,   null },    { "34^",  null,   "_",    "Y",    "233z", "010q", "29~",  null,   null,   null },    { "23@",  null,   "`",    "Z",    "234z", "011q", null,   null,   null,   null },    { "24@",  null,   "{",    "A",    "235z", "012q", null,   null,   null,   null },    // !!! NUMPAD missing, this is not trivial given java's messy so called virtual keys... :-(  };  public final static String[][][] theSpecialKeyMaps = {      specialKeyMap,      specialKeyMapShift,      specialKeyMapCtrl,      specialKeyMapCtrlShift  };  public final static int R_ESC = 0;  public final static int R_SS2 = 1;  public final static int R_SS3 = 2;  public final static int R_DCS = 3;  public final static int R_CSI = 4;  public final static int R_OSC = 5;  public final static int R_PM  = 6;  public final static int R_APC = 7;  public final static String[] replyTypes = {    "\033",    "\033N",    "\033O",

⌨️ 快捷键说明

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