\n';
var rstr='';
for (var c=0; c'+rstr+'<\/td><\/tr>\n';
}
s+='<\/table><\/td><\/tr>\n';
s+='<\/table><\/td><\/tr>\n';
s+='<\/table>\n';
var termOffset=2+this.conf.frameWidth;
if (this.globals.hasSubDivs) {
for (var r=0; r<\/div>\n';
}
this.globals.termStringStart='';
this.globals.termStringEnd='<\/td><\/tr><\/table>';
}
this.globals.writeElement(this.termDiv,s);
}
if (!rebuild) {
this.globals.setElementXY(this.termDiv,this.conf.x,this.conf.y);
this.globals.setVisible(this.termDiv,1);
}
window.status='';
},
rebuild: function() {
// check for bounds and array lengths
var rl=this.conf.rows;
var cl=this.conf.cols;
for (var r=0; r=rl) {
r=rl-1;
resetcrsr=true;
}
if (this.c>=cl) {
c=cl-1;
resetcrsr=true;
}
if (resetcrsr && this.cursoractive) this.cursorOn();
// and actually rebuild
this._makeTerm(true);
for (var r=0; r';
for (var k=tstls.length-1; k>=0; k--) {
var st=tstls[k];
if (curStyle & st) s+=tscls[st];
}
}
curStyle=cs;
for (var k=0; k>>8;
clr= (cc<16)? tclrs[cc] : '#'+tnclrs[cc-16];
}
else if (curStyle & 0xff0000) {
clr='#'+twclrs[(curStyle & 0xff0000)>>>16];
}
if (clr) {
if (curStyle&1) {
s+='';
}
else if (typeof blur === 'object') {
s+='';
}
else if (blur) {
s+='';
}
else {
s+='';
}
}
}
s+= (tspcl[c])? tspcl[c] : String.fromCharCode(c);
}
if (curStyle>0) {
if (curStyle & 0xffff00) s+='';
for (var k=tstls.length-1; k>=0; k--) {
var st=tstls[k];
if (curStyle&st) s+=tscls[st];
}
}
s+=this.globals.termStringEnd;
this.globals.writeElement(this.termDiv+'_r'+r,s);
},
guiReady: function() {
var ready=true;
if (this.globals.guiElementsReady(this.termDiv)) {
for (var r=0; r='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))? true:false;
},
isHexOnlyChar: function(c) {
return ((c>='a' && c<='f') || (c>='A' && c<='F'))? true:false;
},
hexToNum: {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
'8': 8, '9': 9, 'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15,
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15
},
// data for color support
webColors: [],
webColorCodes: [''],
colors: {
// ANSI bright (bold) color set
black: 1,
red: 2,
green: 3,
yellow: 4,
blue: 5,
magenta: 6,
cyan: 7,
white: 8,
// dark color set
grey: 9,
red2: 10,
green2: 11,
yellow2: 12,
blue2: 13,
magenta2: 14,
cyan2: 15,
// synonyms
red1: 2,
green1: 3,
yellow1: 4,
blue1: 5,
magenta1: 6,
cyan1: 7,
gray: 9,
darkred: 10,
darkgreen: 11,
darkyellow: 12,
darkblue: 13,
darkmagenta: 14,
darkcyan: 15,
// default color
'default': 0,
clear: 0
},
colorCodes: [
'', '#000000', '#ff0000', '#00ff00', '#ffff00', '#0066ff', '#ff00ff', '#00ffff', '#ffffff',
'#808080', '#990000', '#009900', '#999900', '#003399', '#990099', '#009999'
],
nsColors: {
'aliceblue': 1, 'antiquewhite': 2, 'aqua': 3, 'aquamarine': 4,
'azure': 5, 'beige': 6, 'black': 7, 'blue': 8,
'blueviolet': 9, 'brown': 10, 'burlywood': 11, 'cadetblue': 12,
'chartreuse': 13, 'chocolate': 14, 'coral': 15, 'cornflowerblue': 16,
'cornsilk': 17, 'crimson': 18, 'darkblue': 19, 'darkcyan': 20,
'darkgoldenrod': 21, 'darkgray': 22, 'darkgreen': 23, 'darkkhaki': 24,
'darkmagenta': 25, 'darkolivegreen': 26, 'darkorange': 27, 'darkorchid': 28,
'darkred': 29, 'darksalmon': 30, 'darkseagreen': 31, 'darkslateblue': 32,
'darkslategray': 33, 'darkturquoise': 34, 'darkviolet': 35, 'deeppink': 36,
'deepskyblue': 37, 'dimgray': 38, 'dodgerblue': 39, 'firebrick': 40,
'floralwhite': 41, 'forestgreen': 42, 'fuchsia': 43, 'gainsboro': 44,
'ghostwhite': 45, 'gold': 46, 'goldenrod': 47, 'gray': 48,
'green': 49, 'greenyellow': 50, 'honeydew': 51, 'hotpink': 52,
'indianred': 53, 'indigo': 54, 'ivory': 55, 'khaki': 56,
'lavender': 57, 'lavenderblush': 58, 'lawngreen': 59, 'lemonchiffon': 60,
'lightblue': 61, 'lightcoral': 62, 'lightcyan': 63, 'lightgoldenrodyellow': 64,
'lightgreen': 65, 'lightgrey': 66, 'lightpink': 67, 'lightsalmon': 68,
'lightseagreen': 69, 'lightskyblue': 70, 'lightslategray': 71, 'lightsteelblue': 72,
'lightyellow': 73, 'lime': 74, 'limegreen': 75, 'linen': 76,
'maroon': 77, 'mediumaquamarine': 78, 'mediumblue': 79, 'mediumorchid': 80,
'mediumpurple': 81, 'mediumseagreen': 82, 'mediumslateblue': 83, 'mediumspringgreen': 84,
'mediumturquoise': 85, 'mediumvioletred': 86, 'midnightblue': 87, 'mintcream': 88,
'mistyrose': 89, 'moccasin': 90, 'navajowhite': 91, 'navy': 92,
'oldlace': 93, 'olive': 94, 'olivedrab': 95, 'orange': 96,
'orangered': 97, 'orchid': 98, 'palegoldenrod': 99, 'palegreen': 100,
'paleturquoise': 101, 'palevioletred': 102, 'papayawhip': 103, 'peachpuff': 104,
'peru': 105, 'pink': 106, 'plum': 107, 'powderblue': 108,
'purple': 109, 'red': 110, 'rosybrown': 111, 'royalblue': 112,
'saddlebrown': 113, 'salmon': 114, 'sandybrown': 115, 'seagreen': 116,
'seashell': 117, 'sienna': 118, 'silver': 119, 'skyblue': 120,
'slateblue': 121, 'slategray': 122, 'snow': 123, 'springgreen': 124,
'steelblue': 125, 'tan': 126, 'teal': 127, 'thistle': 128,
'tomato': 129, 'turquoise': 130, 'violet': 131, 'wheat': 132,
'white': 133, 'whitesmoke': 134, 'yellow': 135, 'yellowgreen': 136
},
nsColorCodes: [
'',
'f0f8ff', 'faebd7', '00ffff', '7fffd4',
'f0ffff', 'f5f5dc', '000000', '0000ff',
'8a2be2', 'a52a2a', 'deb887', '5f9ea0',
'7fff00', 'd2691e', 'ff7f50', '6495ed',
'fff8dc', 'dc143c', '00008b', '008b8b',
'b8860b', 'a9a9a9', '006400', 'bdb76b',
'8b008b', '556b2f', 'ff8c00', '9932cc',
'8b0000', 'e9967a', '8fbc8f', '483d8b',
'2f4f4f', '00ced1', '9400d3', 'ff1493',
'00bfff', '696969', '1e90ff', 'b22222',
'fffaf0', '228b22', 'ff00ff', 'dcdcdc',
'f8f8ff', 'ffd700', 'daa520', '808080',
'008000', 'adff2f', 'f0fff0', 'ff69b4',
'cd5c5c', '4b0082', 'fffff0', 'f0e68c',
'e6e6fa', 'fff0f5', '7cfc00', 'fffacd',
'add8e6', 'f08080', 'e0ffff', 'fafad2',
'90ee90', 'd3d3d3', 'ffb6c1', 'ffa07a',
'20b2aa', '87cefa', '778899', 'b0c4de',
'ffffe0', '00ff00', '32cd32', 'faf0e6',
'800000', '66cdaa', '0000cd', 'ba55d3',
'9370db', '3cb371', '7b68ee', '00fa9a',
'48d1cc', 'c71585', '191970', 'f5fffa',
'ffe4e1', 'ffe4b5', 'ffdead', '000080',
'fdf5e6', '808000', '6b8e23', 'ffa500',
'ff4500', 'da70d6', 'eee8aa', '98fb98',
'afeeee', 'db7093', 'ffefd5', 'ffdab9',
'cd853f', 'ffc0cb', 'dda0dd', 'b0e0e6',
'800080', 'ff0000', 'bc8f8f', '4169e1',
'8b4513', 'fa8072', 'f4a460', '2e8b57',
'fff5ee', 'a0522d', 'c0c0c0', '87ceeb',
'6a5acd', '708090', 'fffafa', '00ff7f',
'4682b4', 'd2b48c', '008080', 'd8bfd8',
'ff6347', '40e0d0', 'ee82ee', 'f5deb3',
'ffffff', 'f5f5f5', 'ffff00', '9acd32'
],
_webSwatchChars: ['0','3','6','9','c','f'],
_initWebColors: function() {
// generate long and short web color ref
var tg=Terminal.prototype.globals;
var ws=tg._webColorSwatch;
var wn=tg.webColors;
var cc=tg.webColorCodes;
var n=1;
var a, b, c, al, bl, bs, cl;
for (var i=0; i<6; i++) {
a=tg._webSwatchChars[i];
al=a+a;
for (var j=0; j<6; j++) {
b=tg._webSwatchChars[j];
bl=al+b+b;
bs=a+b;
for (var k=0; k<6; k++) {
c=tg._webSwatchChars[k];
cl=bl+c+c;
wn[bs+c]=wn[cl]=n;
cc[n]=cl;
n++;
}
}
}
},
webifyColor: function(s) {
// return nearest web color in 3 digit format
// (do without RegExp for compatibility)
var tg=Terminal.prototype.globals;
if (s.length==6) {
var c='';
for (var i=0; i<6; i+=2) {
var a=s.charAt(i);
var b=s.charAt(i+1);
if (tg.isHexChar(a) && tg.isHexChar(b)) {
c+=tg._webSwatchChars[Math.round(parseInt(a+b,16)/255*5)];
}
else {
return '';
}
}
return c;
}
else if (s.length==3) {
var c='';
for (var i=0; i<3; i++) {
var a=s.charAt(i);
if (tg.isHexChar(a)) {
c+=tg._webSwatchChars[Math.round(parseInt(a,16)/15*5)];
}
else {
return '';
}
}
return c;
}
else {
return '';
}
},
// public methods for color support
setColor: function(label, value) {
var tg=Terminal.prototype.globals;
if (typeof label == 'number' && label>=1 && label<=15) {
tg.colorCodes[label]=value;
}
else if (typeof label == 'string') {
label=label.toLowerCase();
if (label.length==1 && tg.isHexChar(label)) {
var n=tg.hexToNum[label];
if (n) tg.colorCodes[n]=value;
}
else if (typeof tg.colors[label] != 'undefined') {
var n=tg.colors[label];
if (n) tg.colorCodes[n]=value;
}
}
},
getColorString: function(label) {
var tg=Terminal.prototype.globals;
if (typeof label == 'number' && label>=0 && label<=15) {
return tg.colorCodes[label];
}
else if (typeof label == 'string') {
label=label.toLowerCase();
if (label.length==1 && tg.isHexChar(label)) {
return tg.colorCodes[tg.hexToNum[label]];
}
else if (typeof tg.colors[label] != 'undefined') {
return tg.colorCodes[tg.colors[label]];
}
}
return '';
},
getColorCode: function(label) {
var tg=Terminal.prototype.globals;
if (typeof label == 'number' && label>=0 && label<=15) {
return label;
}
else if (typeof label == 'string') {
label=label.toLowerCase();
if (label.length==1 && tg.isHexChar(label)) {
return parseInt(label,16);
}
else if (typeof tg.colors[label] != 'undefined') {
return tg.colors[label];
}
}
return 0;
},
// import/paste methods (methods return success)
insertText: function(text) {
// auto-types a given string to the active terminal
// returns success (false indicates a lock or no active terminal)
var tg=Terminal.prototype.globals;
var termRef = tg.activeTerm;
if (!termRef || termRef.closed || tg.keylock || termRef.lock || termRef.charMode || termRef.fieldMode) return false;
// terminal open and unlocked, so type the text
for (var i=0; i;
// (no history entry for this)
termRef.lineBuffer = text;
termRef.lastLine = '';
termRef.inputChar = 0;
termRef.handler();
return true;
},
// text related service functions
normalize: function(n,m) {
var s=''+n;
while (s.length=0) {
t=t.substring(0,ofs)+s2+t.substring(ofs+l1);
ofs=t.indexOf(s1,ofs+l2);
}
return t;
},
// config data for text wrap
wrapChars: {
// keys: charCode
// values: 1 = white space, 2 = wrap after, 3 = wrap before, 4 = conditional word break
9: 1, // tab
10: 1, // new line - don't change this (used internally)!!!
12: 4, // form feed (use this for conditional word breaks)
13: 1, // cr
32: 1, // blank
40: 3, // (
45: 2, // dash/hyphen
61: 2, // =
91: 3, // [
94: 3, // caret (non-printing chars)
123: 3 // {
},
// keyboard methods & controls
setFocus: function(termref) {
Terminal.prototype.globals.activeTerm=termref;
Terminal.prototype.globals.clearRepeatTimer();
},
termKey: {
// codes of special keys
'NUL': 0x00,
'SOH': 0x01,
'STX': 0x02,
'ETX': 0x03,
'EOT': 0x04,
'ENQ': 0x05,
'ACK': 0x06,
'BEL': 0x07,
'BS': 0x08,
'BACKSPACE': 0x08,
'HT': 0x09,
'TAB': 0x09,
'LF': 0x0A,
'VT': 0x0B,
'FF': 0x0C,
'CR': 0x0D,
'SO': 0x0E,
'SI': 0x0F,
'DLE': 0x10,
'DC1': 0x11,
'DC2': 0x12,
'DC3': 0x13,
'DC4': 0x14,
'NAK': 0x15,
'SYN': 0x16,
'ETB': 0x17,
'CAN': 0x18,
'EM': 0x19,
'SUB': 0x1A,
'ESC': 0x1B,
'IS4': 0x1C,
'IS3': 0x1D,
'IS2': 0x1E,
'IS1': 0x1F,
'DEL': 0x7F,
// other specials
'EURO': 0x20AC,
// cursor mapping
'LEFT': 0x1C,
'RIGHT': 0x1D,
'UP': 0x1E,
'DOWN': 0x1F
},
// map some DOM_VK_* properties to values defined in termKey
termDomKeyRef: {},
_domKeyMappingData: {
'LEFT': 'LEFT',
'RIGHT': 'RIGHT',
'UP': 'UP',
'DOWN': 'DOWN',
'BACK_SPACE': 'BS',
'RETURN': 'CR',
'ENTER': 'CR',
'ESCAPE': 'ESC',
'DELETE': 'DEL',
'TAB': 'TAB'
},
_initDomKeyRef: function() {
var tg=Terminal.prototype.globals;
var m=tg._domKeyMappingData;
var r=tg.termDomKeyRef;
var k=tg.termKey;
for (var i in m) r['DOM_VK_'+i]=k[m[i]];
},
registerEvent: function(obj, eventType, handler, capture) {
if (obj.addEventListener) {
obj.addEventListener(eventType.toLowerCase(), handler, capture);
}
/*
else if (obj.attachEvent) {
obj.attachEvent('on'+eventType.toLowerCase(), handler);
}
*/
else {
var et=eventType.toUpperCase();
if (window.Event && window.Event[et] && obj.captureEvents) obj.captureEvents(Event[et]);
obj['on'+eventType.toLowerCase()]=handler;
}
},
releaseEvent: function(obj, eventType, handler, capture) {
if (obj.removeEventListener) {
obj.removeEventListener(eventType.toLowerCase(), handler, capture);
}
/*
else if (obj.detachEvent) {
obj.detachEvent('on'+eventType.toLowerCase(), handler);
}
*/
else {
var et=eventType.toUpperCase();
if (window.Event && window.Event[et] && obj.releaseEvents) obj.releaseEvents(Event[et]);
et='on'+eventType.toLowerCase();
if (obj[et] && obj[et]==handler) obj.et=null;
}
},
enableKeyboard: function(term) {
var tg=Terminal.prototype.globals;
if (!tg.kbdEnabled) {
tg.registerEvent(document, 'keypress', tg.keyHandler, true);
tg.registerEvent(document, 'keydown', tg.keyFix, true);
tg.registerEvent(document, 'keyup', tg.clearRepeatTimer, true);
tg.kbdEnabled=true;
}
tg.activeTerm=term;
},
disableKeyboard: function(term) {
var tg=Terminal.prototype.globals;
if (tg.kbdEnabled) {
tg.releaseEvent(document, 'keypress', tg.keyHandler, true);
tg.releaseEvent(document, 'keydown', tg.keyFix, true);
tg.releaseEvent(document, 'keyup', tg.clearRepeatTimer, true);
tg.kbdEnabled=false;
}
tg.activeTerm=null;
},
// remap some special key mappings on keydown
keyFix: function(e) {
var tg=Terminal.prototype.globals;
var term=tg.activeTerm;
var ch;
if (tg.keylock || term.lock) return true;
if (window.event) {
if (!e) e=window.event;
ch=e.keyCode;
if (e.DOM_VK_UP) {
for (var i in tg.termDomKeyRef) {
if (e[i] && ch == e[i]) {
tg.keyHandler({which:tg.termDomKeyRef[i],_remapped:true,_repeat:(ch==0x1B)? true:false});
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble=true;
return false;
}
}
e.cancelBubble=false;
return true;
}
else {
// no DOM support
var termKey=term.termKey;
var keyHandler=tg.keyHandler;
if (ch==8 && !term.isOpera) { keyHandler({which:termKey.BS,_remapped:true,_repeat:true}); }
else if (ch==9) { keyHandler({which:termKey.TAB,_remapped:true,_repeat: (term.printTab)? false:true}); }
else if (ch==27) { keyHandler({which:termKey.ESC,_remapped:true,_repeat: (term.printTab)? false:true}); }
else if (ch==37) { keyHandler({which:termKey.LEFT,_remapped:true,_repeat:true}); }
else if (ch==39) { keyHandler({which:termKey.RIGHT,_remapped:true,_repeat:true}); }
else if (ch==38) { keyHandler({which:termKey.UP,_remapped:true,_repeat:true}); }
else if (ch==40) { keyHandler({which:termKey.DOWN,_remapped:true,_repeat:true}); }
else if (ch==127 || ch==46) { keyHandler({which:termKey.DEL,_remapped:true,_repeat:true}); }
else if (ch>=57373 && ch<=57376) {
if (ch==57373) { keyHandler({which:termKey.UP,_remapped:true,_repeat:true}); }
else if (ch==57374) { keyHandler({which:termKey.DOWN,_remapped:true,_repeat:true}); }
else if (ch==57375) { keyHandler({which:termKey.LEFT,_remapped:true,_repeat:true}); }
else if (ch==57376) { keyHandler({which:termKey.RIGHT,_remapped:true,_repeat:true}); }
}
else {
e.cancelBubble=false;
return true;
}
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble=true;
return false;
}
}
},
clearRepeatTimer: function(e) {
var tg=Terminal.prototype.globals;
if (tg.keyRepeatTimer) {
clearTimeout(tg.keyRepeatTimer);
tg.keyRepeatTimer=null;
}
},
doKeyRepeat: function(ch) {
Terminal.prototype.globals.keyHandler({which:ch,_remapped:true,_repeated:true})
},
keyHandler: function(e) {
var tg=Terminal.prototype.globals;
var term=tg.activeTerm;
if (tg.keylock || term.lock || term.isMac && e && e.metaKey) return true;
if (window.event) {
if (window.event.preventDefault) window.event.preventDefault();
if (window.event.stopPropagation) window.event.stopPropagation();
}
else if (e) {
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
}
var ch;
var ctrl=false;
var shft=false;
var remapped=false;
var termKey=term.termKey;
var keyRepeat=0;
if (e) {
ch=e.which;
ctrl=((e.ctrlKey && !e.altKey) || e.modifiers==2);
shft=(e.shiftKey || e.modifiers==4);
if (e._remapped) {
remapped=true;
if (window.event) {
//ctrl=(ctrl || window.event.ctrlKey);
ctrl=(ctrl || (window.event.ctrlKey && !window.event.altKey));
shft=(shft || window.event.shiftKey);
}
}
if (e._repeated) {
keyRepeat=2;
}
else if (e._repeat) {
keyRepeat=1;
}
}
else if (window.event) {
ch=window.event.keyCode;
//ctrl=(window.event.ctrlKey);
ctrl=(window.event.ctrlKey && !window.event.altKey); // allow alt gr == ctrl alt
shft=(window.event.shiftKey);
if (window.event._repeated) {
keyRepeat=2;
}
else if (window.event._repeat) {
keyRepeat=1;
}
}
else {
return true;
}
if (ch=='' && remapped==false) {
// map specials
if (e==null) e=window.event;
if (e.charCode==0 && e.keyCode) {
if (e.DOM_VK_UP) {
var dkr=tg.termDomKeyRef;
for (var i in dkr) {
if (e[i] && e.keyCode == e[i]) {
ch=dkr[i];
break;
}
}
}
else {
// NS4
if (e.keyCode==28) { ch=termKey.LEFT; }
else if (e.keyCode==29) { ch=termKey.RIGHT; }
else if (e.keyCode==30) { ch=termKey.UP; }
else if (e.keyCode==31) { ch=termKey.DOWN; }
// Mozilla alike but no DOM support
else if (e.keyCode==37) { ch=termKey.LEFT; }
else if (e.keyCode==39) { ch=termKey.RIGHT; }
else if (e.keyCode==38) { ch=termKey.UP; }
else if (e.keyCode==40) { ch=termKey.DOWN; }
// just to have the TAB mapping here too
else if (e.keyCode==9) { ch=termKey.TAB; }
}
}
}
// leave on unicode private use area (might be function key etc)
if ((ch>=0xE000) && (ch<= 0xF8FF)) return;
if (keyRepeat) {
tg.clearRepeatTimer();
tg.keyRepeatTimer = window.setTimeout(
'Terminal.prototype.globals.doKeyRepeat('+ch+')',
(keyRepeat==1)? tg.keyRepeatDelay1:tg.keyRepeatDelay2
);
}
// key actions
if (term.charMode) {
term.insert=false;
term.inputChar=ch;
term.lineBuffer='';
term.handler();
if (ch<=32 && window.event) window.event.cancelBubble=true;
return false;
}
if (!ctrl) {
// special keys
if (ch==termKey.CR) {
term.lock=true;
term.cursorOff();
term.insert=false;
if (term.rawMode) {
term.lineBuffer=term.lastLine;
}
else if (term.fieldMode) {
term.lineBuffer=term.lastLine;
term.exitFieldMode();
}
else {
term.lineBuffer=term._getLine(true);
if (
term.lineBuffer!='' &&
(!term.historyUnique || term.history.length==0 ||
term.lineBuffer!=term.history[term.history.length-1])
) {
term.history[term.history.length]=term.lineBuffer;
}
term.histPtr=term.history.length;
}
term.lastLine='';
term.inputChar=0;
term.handler();
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (term.fieldMode) {
if (ch==termKey.ESC) {
term.lineBuffer=term.lastLine='';
term.exitFieldMode();
term.lastLine='';
term.inputChar=0;
term.handler();
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (ch==termKey.LEFT) {
if (term.fieldC>0) term.fieldC--;
}
else if (ch==termKey.RIGHT) {
if (term.fieldC0) {
term.lastLine=term.lastLine.substring(0,term.fieldC-1)+term.lastLine.substring(term.fieldC);
term.fieldC--;
}
}
else if (ch==termKey.DEL) {
if (term.fieldC=32) {
term.lastLine=term.lastLine.substring(0,term.fieldC)+String.fromCharCode(ch)+term.lastLine.substring(term.fieldC);
term.fieldC++;
}
term.drawField();
return false;
}
else if (ch==termKey.ESC && term.conf.closeOnESC) {
term.close();
if (window.event) window.event.cancelBubble=true;
return false;
}
if (ch<32 && term.rawMode) {
if (window.event) window.event.cancelBubble=true;
return false;
}
else {
if (ch==termKey.LEFT) {
term.cursorLeft();
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (ch==termKey.RIGHT) {
term.cursorRight();
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (ch==termKey.UP) {
term.cursorOff();
if (term.histPtr==term.history.length) term.lastLine=term._getLine();
term._clearLine();
if (term.history.length && term.histPtr>=0) {
if (term.histPtr>0) term.histPtr--;
term.type(term.history[term.histPtr]);
}
else if (term.lastLine) {
term.type(term.lastLine);
}
term.cursorOn();
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (ch==termKey.DOWN) {
term.cursorOff();
if (term.histPtr==term.history.length) term.lastLine=term._getLine();
term._clearLine();
if (term.history.length && term.histPtr<=term.history.length) {
if (term.histPtr=65 && ch<=96) || ch==63) {
// remap canonical
if (ch==63) {
ch=31;
}
else {
ch-=64;
}
}
term.inputChar=ch;
term.ctrlHandler();
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (ctrl || !term.isPrintable(ch,true)) {
if (window.event) window.event.cancelBubble=true;
return false;
}
else if (term.isPrintable(ch,true)) {
if (term.blinkTimer) clearTimeout(term.blinkTimer);
if (term.insert) {
term.cursorOff();
term._scrollRight(term.r,term.c);
}
term._charOut(ch);
term.cursorOn();
if (ch==32 && window.event) {
window.event.cancelBubble=true;
}
else if (window.opera && window.event) {
window.event.cancelBubble=true;
}
return false;
}
}
return true;
},
// gui mappings
hasSubDivs: false,
termStringStart: '',
termStringEnd: '',
termSpecials: {
// special HTML escapes
0: ' ',
1: ' ',
9: ' ',
32: ' ',
34: '"',
38: '&',
60: '<',
62: '>',
127: '◊',
0x20AC: '€'
},
// extensive list of max 8 styles (2^n, n<16)
termStyles: [1,2,4,8, 16],
// style markup: one letter keys, reserved keys: "p" (plain), "c" (color)
termStyleMarkup: {
'r': 1,
'u': 2,
'i': 4,
's': 8,
'b': 16 // map "b" to 16 (italics) for ANSI mapping
},
// mappings for styles (heading HTML)
termStyleOpen: {
1: '',
2: '',
4: '',
8: '',
16: ''
},
// mapping for styles (trailing HTML)
termStyleClose: {
1: '<\/span>',
2: '<\/u>',
4: '<\/i>',
8: '<\/strike>',
16: ''
},
// method to install custom styles
assignStyle: function(styleCode, markup, htmlOpen, htmlClose) {
var tg=Terminal.prototype.globals;
// check params
if (!styleCode || isNaN(styleCode)) {
if (styleCode>=256) {
alert('termlib.js:\nCould not assign style.\n'+s+' is not a valid power of 2 between 0 and 256.');
return;
}
}
var s=styleCode&0xff;
var matched=false;
for (var i=0; i<8; i++) {
if ((s>>>i)&1) {
if (matched) {
alert('termlib.js:\nCould not assign style code.\n'+s+' is not a power of 2!');
return;
}
matched=true;
}
}
if (!matched) {
alert('termlib.js:\nCould not assign style code.\n'+s+' is not a valid power of 2 between 0 and 256.');
return;
}
markup=String(markup).toLowerCase();
if (markup=='c' || markup=='p') {
alert('termlib.js:\nCould not assign mark up.\n"'+markup+'" is a reserved code.');
return;
}
if (markup.length>1) {
alert('termlib.js:\nCould not assign mark up.\n"'+markup+'" is not a single letter code.');
return;
}
var exists=false;
for (var i=0; i=32) {
var cs=unescape("%"+high+low);
termString_keyref[cc]=cs;
termString_keycoderef[cs]=cc;
}
}
}
},
_extendMissingStringMethods: function() {
if (!String.fromCharCode || !String.prototype.charCodeAt) {
Terminal.prototype.globals._termString_makeKeyref();
}
if (!String.fromCharCode) {
String.fromCharCode=function(cc) {
return (cc!=null)? Terminal.prototype.globals.termString_keyref[cc] : '';
};
}
if (!String.prototype.charCodeAt) {
String.prototype.charCodeAt=function(n) {
cs=this.charAt(n);
return (Terminal.prototype.globals.termString_keycoderef[cs])?
Terminal.prototype.globals.termString_keycoderef[cs] : 0;
};
}
}
// end of Terminal.prototype.globals
}
// end of Terminal.prototype
}
// initialize global data
Terminal.prototype.globals._initGlobals();
// global entities for backward compatibility with termlib 1.x applications
var TerminalDefaults = Terminal.prototype.Defaults;
var termDefaultHandler = Terminal.prototype.defaultHandler;
var TermGlobals = Terminal.prototype.globals;
var termKey = Terminal.prototype.globals.termKey;
var termDomKeyRef = Terminal.prototype.globals.termDomKeyRef;
/*
=== termlib.js Socket Extension v.1.02 ===
(c) Norbert Landsteiner 2003-2007
mass:werk - media environments
# Synopsis:
Integrates async XMLHttpRequests (AJAX/JSON) tightly into termlib.js
# Example:
myTerm = new Terminal( { handler: myTermHandler } );
myTerm.open();
function myTermHandler() {
this.newLine();
if (this.lineBuffer == 'get file') {
myTerm.send(
{
url: 'myservice',
data: {
book: 'theBook',
chapter: 7,
page: 45
},
callback: myCallback
}
);
return;
}
else {
// ...
}
this.prompt();
}
function myCallback() {
if (this.socket.success) {
this.write(this.socket.responseText);
}
else {
this.write('OOPS: ' + this.socket.status + ' ' + this.socket.statusText);
if (this.socket.errno) {
this.newLine();
this.write('Error: ' + this.socket.errstring);
}
}
this.prompt();
}
# Documentation:
for usage and description see readme.txt chapter 13:
or refer to the sample page:
*/
Terminal.prototype._HttpSocket = function() {
var req=null;
if (window.XMLHttpRequest) {
try {
req=new XMLHttpRequest();
}
catch(e) {}
}
else if (window.ActiveXObject) {
var prtcls=this._msXMLHttpObjects;
for (var i=0; i1) this.prototype._msXMLHttpObjects= [ prtcls[i] ];
break;
}
}
catch(e) {}
}
}
this.request=req;
this.url;
this.data=null;
this.query='';
this.timeoutTimer=null;
this.localMode=Boolean(window.location.href.search(/^file:/i)==0);
this.error=0;
}
Terminal.prototype._HttpSocket.prototype = {
version: '1.02',
// config
useXMLEncoding: false, // use ";" as separator if true, "&" else
defaulTimeout: 10000, // request timeout in ticks (milliseconds)
defaultMethod: 'GET',
forceNewline: true, // translate line-breaks in responseText to newlines
// static const
errno: {
OK: 0,
NOTIMPLEMENTED: 1,
FATALERROR: 2,
TIMEOUT: 3,
NETWORKERROR: 4,
LOCALFILEERROR: 5
},
errstring: [
'',
'XMLHttpRequest not implemented.',
'Could not open XMLHttpRequest.',
'The connection timed out.',
'Network error.',
'The requested local document was not found.'
],
// private static data
_msXMLHttpObjects: [
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP',
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0'
],
// internal methods
serializeData: function() {
this.query=this.serialize(this.data);
},
serialize: function(data) {
var v='';
if( data != null ) {
switch (typeof data) {
case 'object':
var d=[];
if (data instanceof Array) {
// array
for (var i=0; i= 200 && r.status < 300) {
success=true;
}
else if (r.status >= 12000) {
// MSIE network error
failed=true;
this.error=this.errno.NETWORKERROR;
}
}
}
}
catch(e) {}
if (!failed) {
response.status=r.status;
response.statusText= (r.status==404)? 'Not Found':r.statusText; // force correct header
response.responseText=r.responseText;
response.responseXML=r.responseXML;
if (this.getHeaders) {
if (this.getHeaders instanceof Array) {
for (var i=0; i |
| |
|