mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.5 KiB
80 lines
1.5 KiB
9 years ago
|
'use strict';
|
||
|
var ESC = '\u001b[';
|
||
|
var x = module.exports;
|
||
|
|
||
|
x.cursorTo = function (x, y) {
|
||
|
if (arguments.length === 0) {
|
||
|
return ESC + 'H';
|
||
|
}
|
||
|
|
||
|
if (arguments.length === 1) {
|
||
|
return ESC + (x + 1) + 'G';
|
||
|
}
|
||
|
|
||
|
return ESC + (y + 1) + ';' + (x + 1) + 'H';
|
||
|
};
|
||
|
|
||
|
x.cursorMove = function (x, y) {
|
||
|
var ret = '';
|
||
|
|
||
|
if (x < 0) {
|
||
|
ret += ESC + (-x) + 'D';
|
||
|
} else if (x > 0) {
|
||
|
ret += ESC + x + 'C';
|
||
|
}
|
||
|
|
||
|
if (y < 0) {
|
||
|
ret += ESC + (-y) + 'A';
|
||
|
} else if (y > 0) {
|
||
|
ret += ESC + y + 'B';
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
x.cursorUp = function (count) {
|
||
|
return ESC + (typeof count === 'number' ? count : 1) + 'A';
|
||
|
};
|
||
|
|
||
|
x.cursorDown = function (count) {
|
||
|
return ESC + (typeof count === 'number' ? count : 1) + 'B';
|
||
|
};
|
||
|
|
||
|
x.cursorForward = function (count) {
|
||
|
return ESC + (typeof count === 'number' ? count : 1) + 'C';
|
||
|
};
|
||
|
|
||
|
x.cursorBackward = function (count) {
|
||
|
return ESC + (typeof count === 'number' ? count : 1) + 'D';
|
||
|
};
|
||
|
|
||
|
x.cursorLeft = ESC + '1000D';
|
||
|
x.cursorSavePosition = ESC + 's';
|
||
|
x.cursorRestorePosition = ESC + 'u';
|
||
|
x.cursorGetPosition = ESC + '6n';
|
||
|
x.cursorNextLine = ESC + 'E';
|
||
|
x.cursorPrevLine = ESC + 'F';
|
||
|
x.cursorHide = ESC + '?25l';
|
||
|
x.cursorShow = ESC + '?25h';
|
||
|
|
||
|
x.eraseLines = function (count) {
|
||
|
var clear = '';
|
||
|
|
||
|
for (var i = 0; i < count; i++) {
|
||
|
clear += x.cursorLeft + x.eraseEndLine + (i < count - 1 ? x.cursorUp() : '');
|
||
|
}
|
||
|
|
||
|
return clear;
|
||
|
};
|
||
|
|
||
|
x.eraseEndLine = ESC + 'K';
|
||
|
x.eraseStartLine = ESC + '1K';
|
||
|
x.eraseLine = ESC + '2K';
|
||
|
x.eraseDown = ESC + 'J';
|
||
|
x.eraseUp = ESC + '1J';
|
||
|
x.eraseScreen = ESC + '2J';
|
||
|
x.scrollUp = ESC + 'S';
|
||
|
x.scrollDown = ESC + 'T';
|
||
|
|
||
|
x.beep = '\u0007';
|