mirror of
https://github.com/nuintun/command-manager.git
synced 2025-10-20 09:51:31 +08:00
update files
This commit is contained in:
145
static/js/terminal/lib/csi/charAttributes.js
Normal file
145
static/js/terminal/lib/csi/charAttributes.js
Normal file
@@ -0,0 +1,145 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
|
||||
// CSI Pm m Character Attributes (SGR).
|
||||
// Ps = 0 -> Normal (default).
|
||||
// Ps = 1 -> Bold.
|
||||
// Ps = 4 -> Underlined.
|
||||
// Ps = 5 -> Blink (appears as Bold).
|
||||
// Ps = 7 -> Inverse.
|
||||
// Ps = 8 -> Invisible, i.e., hidden (VT300).
|
||||
// Ps = 2 2 -> Normal (neither bold nor faint).
|
||||
// Ps = 2 4 -> Not underlined.
|
||||
// Ps = 2 5 -> Steady (not blinking).
|
||||
// Ps = 2 7 -> Positive (not inverse).
|
||||
// Ps = 2 8 -> Visible, i.e., not hidden (VT300).
|
||||
// Ps = 3 0 -> Set foreground color to Black.
|
||||
// Ps = 3 1 -> Set foreground color to Red.
|
||||
// Ps = 3 2 -> Set foreground color to Green.
|
||||
// Ps = 3 3 -> Set foreground color to Yellow.
|
||||
// Ps = 3 4 -> Set foreground color to Blue.
|
||||
// Ps = 3 5 -> Set foreground color to Magenta.
|
||||
// Ps = 3 6 -> Set foreground color to Cyan.
|
||||
// Ps = 3 7 -> Set foreground color to White.
|
||||
// Ps = 3 9 -> Set foreground color to default (original).
|
||||
// Ps = 4 0 -> Set background color to Black.
|
||||
// Ps = 4 1 -> Set background color to Red.
|
||||
// Ps = 4 2 -> Set background color to Green.
|
||||
// Ps = 4 3 -> Set background color to Yellow.
|
||||
// Ps = 4 4 -> Set background color to Blue.
|
||||
// Ps = 4 5 -> Set background color to Magenta.
|
||||
// Ps = 4 6 -> Set background color to Cyan.
|
||||
// Ps = 4 7 -> Set background color to White.
|
||||
// Ps = 4 9 -> Set background color to default (original).
|
||||
|
||||
// If 16-color support is compiled, the following apply. Assume
|
||||
// that xterm's resources are set so that the ISO color codes are
|
||||
// the first 8 of a set of 16. Then the aixterm colors are the
|
||||
// bright versions of the ISO colors:
|
||||
// Ps = 9 0 -> Set foreground color to Black.
|
||||
// Ps = 9 1 -> Set foreground color to Red.
|
||||
// Ps = 9 2 -> Set foreground color to Green.
|
||||
// Ps = 9 3 -> Set foreground color to Yellow.
|
||||
// Ps = 9 4 -> Set foreground color to Blue.
|
||||
// Ps = 9 5 -> Set foreground color to Magenta.
|
||||
// Ps = 9 6 -> Set foreground color to Cyan.
|
||||
// Ps = 9 7 -> Set foreground color to White.
|
||||
// Ps = 1 0 0 -> Set background color to Black.
|
||||
// Ps = 1 0 1 -> Set background color to Red.
|
||||
// Ps = 1 0 2 -> Set background color to Green.
|
||||
// Ps = 1 0 3 -> Set background color to Yellow.
|
||||
// Ps = 1 0 4 -> Set background color to Blue.
|
||||
// Ps = 1 0 5 -> Set background color to Magenta.
|
||||
// Ps = 1 0 6 -> Set background color to Cyan.
|
||||
// Ps = 1 0 7 -> Set background color to White.
|
||||
|
||||
// If xterm is compiled with the 16-color support disabled, it
|
||||
// supports the following, from rxvt:
|
||||
// Ps = 1 0 0 -> Set foreground and background color to
|
||||
// default.
|
||||
|
||||
// If 88- or 256-color support is compiled, the following apply.
|
||||
// Ps = 3 8 ; 5 ; Ps -> Set foreground color to the second
|
||||
// Ps.
|
||||
// Ps = 4 8 ; 5 ; Ps -> Set background color to the second
|
||||
// Ps.
|
||||
Terminal.prototype.charAttributes = function (params){
|
||||
var l = params.length,
|
||||
i = 0,
|
||||
bg, fg, p;
|
||||
|
||||
for (; i < l; i++) {
|
||||
p = params[i];
|
||||
if (p >= 30 && p <= 37) {
|
||||
// fg color 8
|
||||
this.curAttr = (this.curAttr & ~(0x1ff << 9)) | ((p - 30) << 9);
|
||||
} else if (p >= 40 && p <= 47) {
|
||||
// bg color 8
|
||||
this.curAttr = (this.curAttr & ~0x1ff) | (p - 40);
|
||||
} else if (p >= 90 && p <= 97) {
|
||||
// fg color 16
|
||||
p += 8;
|
||||
this.curAttr = (this.curAttr & ~(0x1ff << 9)) | ((p - 90) << 9);
|
||||
} else if (p >= 100 && p <= 107) {
|
||||
// bg color 16
|
||||
p += 8;
|
||||
this.curAttr = (this.curAttr & ~0x1ff) | (p - 100);
|
||||
} else if (p === 0) {
|
||||
// default
|
||||
this.curAttr = this.defAttr;
|
||||
} else if (p === 1) {
|
||||
// bold text
|
||||
this.curAttr = this.curAttr | (1 << 18);
|
||||
} else if (p === 4) {
|
||||
// underlined text
|
||||
this.curAttr = this.curAttr | (2 << 18);
|
||||
} else if (p === 7 || p === 27) {
|
||||
// inverse and positive
|
||||
// test with: echo -e '\e[31m\e[42mhello\e[7mworld\e[27mhi\e[m'
|
||||
if (p === 7) {
|
||||
if ((this.curAttr >> 18) & 4) continue;
|
||||
this.curAttr = this.curAttr | (4 << 18);
|
||||
} else if (p === 27) {
|
||||
if (~(this.curAttr >> 18) & 4) continue;
|
||||
this.curAttr = this.curAttr & ~(4 << 18);
|
||||
}
|
||||
|
||||
bg = this.curAttr & 0x1ff;
|
||||
fg = (this.curAttr >> 9) & 0x1ff;
|
||||
|
||||
this.curAttr = (this.curAttr & ~0x3ffff) | ((bg << 9) | fg);
|
||||
} else if (p === 22) {
|
||||
// not bold
|
||||
this.curAttr = this.curAttr & ~(1 << 18);
|
||||
} else if (p === 24) {
|
||||
// not underlined
|
||||
this.curAttr = this.curAttr & ~(2 << 18);
|
||||
} else if (p === 39) {
|
||||
// reset fg
|
||||
this.curAttr = this.curAttr & ~(0x1ff << 9);
|
||||
this.curAttr = this.curAttr | (((this.defAttr >> 9) & 0x1ff) << 9);
|
||||
} else if (p === 49) {
|
||||
// reset bg
|
||||
this.curAttr = this.curAttr & ~0x1ff;
|
||||
this.curAttr = this.curAttr | (this.defAttr & 0x1ff);
|
||||
} else if (p === 38) {
|
||||
// fg color 256
|
||||
if (params[i + 1] !== 5) continue;
|
||||
i += 2;
|
||||
p = params[i] & 0xff;
|
||||
// convert 88 colors to 256
|
||||
// if (this.is('rxvt-unicode') && p < 88) p = p * 2.9090 | 0;
|
||||
this.curAttr = (this.curAttr & ~(0x1ff << 9)) | (p << 9);
|
||||
} else if (p === 48) {
|
||||
// bg color 256
|
||||
if (params[i + 1] !== 5) continue;
|
||||
i += 2;
|
||||
p = params[i] & 0xff;
|
||||
// convert 88 colors to 256
|
||||
// if (this.is('rxvt-unicode') && p < 88) p = p * 2.9090 | 0;
|
||||
this.curAttr = (this.curAttr & ~0x1ff) | p;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
136
static/js/terminal/lib/csi/cursor.js
Normal file
136
static/js/terminal/lib/csi/cursor.js
Normal file
@@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
// CSI s
|
||||
// Save cursor (ANSI.SYS).
|
||||
Terminal.prototype.saveCursor = function (params){
|
||||
this.savedX = this.x;
|
||||
this.savedY = this.y;
|
||||
};
|
||||
|
||||
// CSI u
|
||||
// Restore cursor (ANSI.SYS).
|
||||
Terminal.prototype.restoreCursor = function (params){
|
||||
this.x = this.savedX || 0;
|
||||
this.y = this.savedY || 0;
|
||||
};
|
||||
|
||||
// CSI Ps A
|
||||
// Cursor Up Ps Times (default = 1) (CUU).
|
||||
Terminal.prototype.cursorUp = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.y -= param;
|
||||
if (this.y < 0) this.y = 0;
|
||||
};
|
||||
|
||||
// CSI Ps B
|
||||
// Cursor Down Ps Times (default = 1) (CUD).
|
||||
Terminal.prototype.cursorDown = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.y += param;
|
||||
if (this.y >= this.rows) {
|
||||
this.y = this.rows - 1;
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Ps C
|
||||
// Cursor Forward Ps Times (default = 1) (CUF).
|
||||
Terminal.prototype.cursorForward = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.x += param;
|
||||
if (this.x >= this.cols) {
|
||||
this.x = this.cols - 1;
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Ps D
|
||||
// Cursor Backward Ps Times (default = 1) (CUB).
|
||||
Terminal.prototype.cursorBackward = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.x -= param;
|
||||
if (this.x < 0) this.x = 0;
|
||||
};
|
||||
|
||||
// CSI Ps ; Ps H
|
||||
// Cursor Position [row;column] (default = [1,1]) (CUP).
|
||||
Terminal.prototype.cursorPos = function (params){
|
||||
var row, col;
|
||||
|
||||
row = params[0] - 1;
|
||||
|
||||
if (params.length >= 2) {
|
||||
col = params[1] - 1;
|
||||
} else {
|
||||
col = 0;
|
||||
}
|
||||
|
||||
if (row < 0) {
|
||||
row = 0;
|
||||
} else if (row >= this.rows) {
|
||||
row = this.rows - 1;
|
||||
}
|
||||
|
||||
if (col < 0) {
|
||||
col = 0;
|
||||
} else if (col >= this.cols) {
|
||||
col = this.cols - 1;
|
||||
}
|
||||
|
||||
this.x = col;
|
||||
this.y = row;
|
||||
};
|
||||
|
||||
// CSI Ps E
|
||||
// Cursor Next Line Ps Times (default = 1) (CNL).
|
||||
// same as CSI Ps B ?
|
||||
Terminal.prototype.cursorNextLine = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.y += param;
|
||||
if (this.y >= this.rows) {
|
||||
this.y = this.rows - 1;
|
||||
}
|
||||
this.x = 0;
|
||||
};
|
||||
|
||||
// CSI Ps F
|
||||
// Cursor Preceding Line Ps Times (default = 1) (CNL).
|
||||
// reuse CSI Ps A ?
|
||||
Terminal.prototype.cursorPrecedingLine = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.y -= param;
|
||||
if (this.y < 0) this.y = 0;
|
||||
this.x = 0;
|
||||
};
|
||||
|
||||
// CSI Ps G
|
||||
// Cursor Character Absolute [column] (default = [row,1]) (CHA).
|
||||
Terminal.prototype.cursorCharAbsolute = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.x = param - 1;
|
||||
};
|
||||
|
||||
// CSI Ps I
|
||||
// Cursor Forward Tabulation Ps tab stops (default = 1) (CHT).
|
||||
Terminal.prototype.cursorForwardTab = function (params){
|
||||
var param = params[0] || 1;
|
||||
while (param--) {
|
||||
this.x = this.nextStop();
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
|
||||
Terminal.prototype.cursorBackwardTab = function (params){
|
||||
var param = params[0] || 1;
|
||||
while (param--) {
|
||||
this.x = this.prevStop();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
104
static/js/terminal/lib/csi/insert-delete.js
Normal file
104
static/js/terminal/lib/csi/insert-delete.js
Normal file
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
|
||||
// CSI Ps @
|
||||
// Insert Ps (Blank) Character(s) (default = 1) (ICH).
|
||||
Terminal.prototype.insertChars = function (params){
|
||||
var param, row, j, ch;
|
||||
|
||||
param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
|
||||
row = this.y + this.ybase;
|
||||
j = this.x;
|
||||
ch = [this.curAttr, ' ']; // xterm
|
||||
|
||||
while (param-- && j < this.cols) {
|
||||
this.lines[row].splice(j++, 0, ch);
|
||||
this.lines[row].pop();
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Ps L
|
||||
// Insert Ps Line(s) (default = 1) (IL).
|
||||
Terminal.prototype.insertLines = function (params){
|
||||
var param, row, j;
|
||||
|
||||
param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
row = this.y + this.ybase;
|
||||
|
||||
j = this.rows - 1 - this.scrollBottom;
|
||||
j = this.rows - 1 + this.ybase - j + 1;
|
||||
|
||||
while (param--) {
|
||||
// test: echo -e '\e[44m\e[1L\e[0m'
|
||||
// blankLine(true) - xterm/linux behavior
|
||||
this.lines.splice(row, 0, this.blankLine(true));
|
||||
this.lines.splice(j, 1);
|
||||
}
|
||||
|
||||
// this.maxRange();
|
||||
this.updateRange(this.y);
|
||||
this.updateRange(this.scrollBottom);
|
||||
};
|
||||
|
||||
// CSI Ps M
|
||||
// Delete Ps Line(s) (default = 1) (DL).
|
||||
Terminal.prototype.deleteLines = function (params){
|
||||
var param, row, j;
|
||||
|
||||
param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
row = this.y + this.ybase;
|
||||
|
||||
j = this.rows - 1 - this.scrollBottom;
|
||||
j = this.rows - 1 + this.ybase - j;
|
||||
|
||||
while (param--) {
|
||||
// test: echo -e '\e[44m\e[1M\e[0m'
|
||||
// blankLine(true) - xterm/linux behavior
|
||||
this.lines.splice(j + 1, 0, this.blankLine(true));
|
||||
this.lines.splice(row, 1);
|
||||
}
|
||||
|
||||
// this.maxRange();
|
||||
this.updateRange(this.y);
|
||||
this.updateRange(this.scrollBottom);
|
||||
};
|
||||
|
||||
// CSI Ps P
|
||||
// Delete Ps Character(s) (default = 1) (DCH).
|
||||
Terminal.prototype.deleteChars = function (params){
|
||||
var param, row, ch;
|
||||
|
||||
param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
|
||||
row = this.y + this.ybase;
|
||||
ch = [this.curAttr, ' ']; // xterm
|
||||
|
||||
while (param--) {
|
||||
this.lines[row].splice(this.x, 1);
|
||||
this.lines[row].push(ch);
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Ps X
|
||||
// Erase Ps Character(s) (default = 1) (ECH).
|
||||
Terminal.prototype.eraseChars = function (params){
|
||||
var param, row, j, ch;
|
||||
|
||||
param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
|
||||
row = this.y + this.ybase;
|
||||
j = this.x;
|
||||
ch = [this.curAttr, ' ']; // xterm
|
||||
|
||||
while (param-- && j < this.cols) {
|
||||
this.lines[row][j++] = ch;
|
||||
}
|
||||
};
|
||||
};
|
66
static/js/terminal/lib/csi/position.js
Normal file
66
static/js/terminal/lib/csi/position.js
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
// CSI Pm ` Character Position Absolute
|
||||
// [column] (default = [row,1]) (HPA).
|
||||
Terminal.prototype.charPosAbsolute = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.x = param - 1;
|
||||
if (this.x >= this.cols) {
|
||||
this.x = this.cols - 1;
|
||||
}
|
||||
};
|
||||
|
||||
// 141 61 a * HPR -
|
||||
// Horizontal Position Relative
|
||||
// reuse CSI Ps C ?
|
||||
Terminal.prototype.HPositionRelative = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.x += param;
|
||||
if (this.x >= this.cols) {
|
||||
this.x = this.cols - 1;
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Pm d
|
||||
// Line Position Absolute [row] (default = [1,column]) (VPA).
|
||||
Terminal.prototype.linePosAbsolute = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.y = param - 1;
|
||||
if (this.y >= this.rows) {
|
||||
this.y = this.rows - 1;
|
||||
}
|
||||
};
|
||||
|
||||
// 145 65 e * VPR - Vertical Position Relative
|
||||
// reuse CSI Ps B ?
|
||||
Terminal.prototype.VPositionRelative = function (params){
|
||||
var param = params[0];
|
||||
if (param < 1) param = 1;
|
||||
this.y += param;
|
||||
if (this.y >= this.rows) {
|
||||
this.y = this.rows - 1;
|
||||
}
|
||||
};
|
||||
|
||||
// CSI Ps ; Ps f
|
||||
// Horizontal and Vertical Position [row;column] (default =
|
||||
// [1,1]) (HVP).
|
||||
Terminal.prototype.HVPosition = function (params){
|
||||
if (params[0] < 1) params[0] = 1;
|
||||
if (params[1] < 1) params[1] = 1;
|
||||
|
||||
this.y = params[0] - 1;
|
||||
if (this.y >= this.rows) {
|
||||
this.y = this.rows - 1;
|
||||
}
|
||||
|
||||
this.x = params[1] - 1;
|
||||
if (this.x >= this.cols) {
|
||||
this.x = this.cols - 1;
|
||||
}
|
||||
};
|
||||
};
|
12
static/js/terminal/lib/csi/repeatPrecedingCharacter.js
Normal file
12
static/js/terminal/lib/csi/repeatPrecedingCharacter.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
// CSI Ps b Repeat the preceding graphic character Ps times (REP).
|
||||
Terminal.prototype.repeatPrecedingCharacter = function (params){
|
||||
var param = params[0] || 1,
|
||||
line = this.lines[this.ybase + this.y],
|
||||
ch = line[this.x - 1] || [this.defAttr, ' '];
|
||||
|
||||
while (param--) line[this.x++] = ch;
|
||||
};
|
||||
};
|
20
static/js/terminal/lib/csi/softReset.js
Normal file
20
static/js/terminal/lib/csi/softReset.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
// CSI ! p Soft terminal reset (DECSTR).
|
||||
// http://vt100.net/docs/vt220-rm/table4-10.html
|
||||
Terminal.prototype.softReset = function (params){
|
||||
this.cursorHidden = false;
|
||||
this.insertMode = false;
|
||||
this.originMode = false;
|
||||
this.wraparoundMode = false; // autowrap
|
||||
this.applicationKeypad = false; // ?
|
||||
this.scrollTop = 0;
|
||||
this.scrollBottom = this.rows - 1;
|
||||
this.curAttr = this.defAttr;
|
||||
this.x = this.y = 0; // ?
|
||||
this.charset = null;
|
||||
this.glevel = 0; // ??
|
||||
this.charsets = [null]; // ??
|
||||
};
|
||||
};
|
18
static/js/terminal/lib/csi/tabClear.js
Normal file
18
static/js/terminal/lib/csi/tabClear.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (Terminal){
|
||||
// CSI Ps g Tab Clear (TBC).
|
||||
// Ps = 0 -> Clear Current Column (default).
|
||||
// Ps = 3 -> Clear All.
|
||||
// Potentially:
|
||||
// Ps = 2 -> Clear Stops on Line.
|
||||
// http://vt100.net/annarbor/aaa-ug/section6.html
|
||||
Terminal.prototype.tabClear = function (params){
|
||||
var param = params[0];
|
||||
if (param <= 0) {
|
||||
delete this.tabs[this.x];
|
||||
} else if (param === 3) {
|
||||
this.tabs = {};
|
||||
}
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user