First pass formatting with Prettier
* Added .prettierrc.json * Added .prettierignore * Formatted
This commit is contained in:
@@ -43,48 +43,48 @@
|
||||
//
|
||||
|
||||
// ENiGMA½
|
||||
const miscUtil = require('./misc_util.js');
|
||||
const miscUtil = require('./misc_util.js');
|
||||
|
||||
// deps
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const _ = require('lodash');
|
||||
|
||||
exports.getFullMatchRegExp = getFullMatchRegExp;
|
||||
exports.getFGColorValue = getFGColorValue;
|
||||
exports.getBGColorValue = getBGColorValue;
|
||||
exports.sgr = sgr;
|
||||
exports.getSGRFromGraphicRendition = getSGRFromGraphicRendition;
|
||||
exports.clearScreen = clearScreen;
|
||||
exports.resetScreen = resetScreen;
|
||||
exports.normal = normal;
|
||||
exports.goHome = goHome;
|
||||
exports.disableVT100LineWrapping = disableVT100LineWrapping;
|
||||
exports.setSyncTermFont = setSyncTermFont;
|
||||
exports.getSyncTermFontFromAlias = getSyncTermFontFromAlias;
|
||||
exports.setSyncTermFontWithAlias = setSyncTermFontWithAlias;
|
||||
exports.setCursorStyle = setCursorStyle;
|
||||
exports.setEmulatedBaudRate = setEmulatedBaudRate;
|
||||
exports.vtxHyperlink = vtxHyperlink;
|
||||
exports.getFullMatchRegExp = getFullMatchRegExp;
|
||||
exports.getFGColorValue = getFGColorValue;
|
||||
exports.getBGColorValue = getBGColorValue;
|
||||
exports.sgr = sgr;
|
||||
exports.getSGRFromGraphicRendition = getSGRFromGraphicRendition;
|
||||
exports.clearScreen = clearScreen;
|
||||
exports.resetScreen = resetScreen;
|
||||
exports.normal = normal;
|
||||
exports.goHome = goHome;
|
||||
exports.disableVT100LineWrapping = disableVT100LineWrapping;
|
||||
exports.setSyncTermFont = setSyncTermFont;
|
||||
exports.getSyncTermFontFromAlias = getSyncTermFontFromAlias;
|
||||
exports.setSyncTermFontWithAlias = setSyncTermFontWithAlias;
|
||||
exports.setCursorStyle = setCursorStyle;
|
||||
exports.setEmulatedBaudRate = setEmulatedBaudRate;
|
||||
exports.vtxHyperlink = vtxHyperlink;
|
||||
|
||||
//
|
||||
// See also
|
||||
// https://github.com/TooTallNate/ansi.js/blob/master/lib/ansi.js
|
||||
|
||||
const ESC_CSI = '\u001b[';
|
||||
const ESC_CSI = '\u001b[';
|
||||
|
||||
const CONTROL = {
|
||||
up : 'A',
|
||||
down : 'B',
|
||||
up: 'A',
|
||||
down: 'B',
|
||||
|
||||
forward : 'C',
|
||||
right : 'C',
|
||||
forward: 'C',
|
||||
right: 'C',
|
||||
|
||||
back : 'D',
|
||||
left : 'D',
|
||||
back: 'D',
|
||||
left: 'D',
|
||||
|
||||
nextLine : 'E',
|
||||
prevLine : 'F',
|
||||
horizAbsolute : 'G',
|
||||
nextLine: 'E',
|
||||
prevLine: 'F',
|
||||
horizAbsolute: 'G',
|
||||
|
||||
//
|
||||
// CSI [ p1 ] J
|
||||
@@ -103,10 +103,10 @@ const CONTROL = {
|
||||
// * NetRunner: Always clears a screen *height* (e.g. 25) regardless of p1
|
||||
// and screen remainder
|
||||
//
|
||||
eraseData : 'J',
|
||||
eraseData: 'J',
|
||||
|
||||
eraseLine : 'K',
|
||||
insertLine : 'L',
|
||||
eraseLine: 'K',
|
||||
insertLine: 'L',
|
||||
|
||||
//
|
||||
// CSI [ p1 ] M
|
||||
@@ -128,28 +128,28 @@ const CONTROL = {
|
||||
// incompatibilities & oddities around this sequence. ANSI-BBS
|
||||
// states that it *should* work with any value of p1.
|
||||
//
|
||||
deleteLine : 'M',
|
||||
ansiMusic : 'M',
|
||||
deleteLine: 'M',
|
||||
ansiMusic: 'M',
|
||||
|
||||
scrollUp : 'S',
|
||||
scrollDown : 'T',
|
||||
setScrollRegion : 'r',
|
||||
savePos : 's',
|
||||
restorePos : 'u',
|
||||
queryPos : '6n',
|
||||
queryScreenSize : '255n', // See bansi.txt
|
||||
goto : 'H', // row Pr, column Pc -- same as f
|
||||
gotoAlt : 'f', // same as H
|
||||
scrollUp: 'S',
|
||||
scrollDown: 'T',
|
||||
setScrollRegion: 'r',
|
||||
savePos: 's',
|
||||
restorePos: 'u',
|
||||
queryPos: '6n',
|
||||
queryScreenSize: '255n', // See bansi.txt
|
||||
goto: 'H', // row Pr, column Pc -- same as f
|
||||
gotoAlt: 'f', // same as H
|
||||
|
||||
blinkToBrightIntensity : '?33h',
|
||||
blinkNormal : '?33l',
|
||||
blinkToBrightIntensity: '?33h',
|
||||
blinkNormal: '?33l',
|
||||
|
||||
emulationSpeed : '*r', // Set output emulation speed. See cterm.txt
|
||||
emulationSpeed: '*r', // Set output emulation speed. See cterm.txt
|
||||
|
||||
hideCursor : '?25l', // Nonstandard - cterm.txt
|
||||
showCursor : '?25h', // Nonstandard - cterm.txt
|
||||
hideCursor: '?25l', // Nonstandard - cterm.txt
|
||||
showCursor: '?25h', // Nonstandard - cterm.txt
|
||||
|
||||
queryDeviceAttributes : 'c', // Nonstandard - cterm.txt
|
||||
queryDeviceAttributes: 'c', // Nonstandard - cterm.txt
|
||||
|
||||
// :TODO: see https://code.google.com/p/conemu-maximus5/wiki/AnsiEscapeCodes
|
||||
// apparently some terms can report screen size and text area via 18t and 19t
|
||||
@@ -160,41 +160,44 @@ const CONTROL = {
|
||||
// See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt
|
||||
//
|
||||
const SGRValues = {
|
||||
reset : 0,
|
||||
bold : 1,
|
||||
dim : 2,
|
||||
blink : 5,
|
||||
fastBlink : 6,
|
||||
negative : 7,
|
||||
hidden : 8,
|
||||
reset: 0,
|
||||
bold: 1,
|
||||
dim: 2,
|
||||
blink: 5,
|
||||
fastBlink: 6,
|
||||
negative: 7,
|
||||
hidden: 8,
|
||||
|
||||
normal : 22, //
|
||||
steady : 25,
|
||||
positive : 27,
|
||||
normal: 22, //
|
||||
steady: 25,
|
||||
positive: 27,
|
||||
|
||||
black : 30,
|
||||
red : 31,
|
||||
green : 32,
|
||||
yellow : 33,
|
||||
blue : 34,
|
||||
magenta : 35,
|
||||
cyan : 36,
|
||||
white : 37,
|
||||
black: 30,
|
||||
red: 31,
|
||||
green: 32,
|
||||
yellow: 33,
|
||||
blue: 34,
|
||||
magenta: 35,
|
||||
cyan: 36,
|
||||
white: 37,
|
||||
|
||||
blackBG : 40,
|
||||
redBG : 41,
|
||||
greenBG : 42,
|
||||
yellowBG : 43,
|
||||
blueBG : 44,
|
||||
magentaBG : 45,
|
||||
cyanBG : 46,
|
||||
whiteBG : 47,
|
||||
blackBG: 40,
|
||||
redBG: 41,
|
||||
greenBG: 42,
|
||||
yellowBG: 43,
|
||||
blueBG: 44,
|
||||
magentaBG: 45,
|
||||
cyanBG: 46,
|
||||
whiteBG: 47,
|
||||
};
|
||||
|
||||
function getFullMatchRegExp(flags = 'g') {
|
||||
// :TODO: expand this a bit - see strip-ansi/etc.
|
||||
// :TODO: \u009b ?
|
||||
return new RegExp(/[\u001b][[()#;?]*([0-9]{1,4}(?:;[0-9]{0,4})*)?([0-9A-ORZcf-npqrsuy=><])/, flags); // eslint-disable-line no-control-regex
|
||||
return new RegExp(
|
||||
/[\u001b][[()#;?]*([0-9]{1,4}(?:;[0-9]{0,4})*)?([0-9A-ORZcf-npqrsuy=><])/,
|
||||
flags
|
||||
); // eslint-disable-line no-control-regex
|
||||
}
|
||||
|
||||
function getFGColorValue(name) {
|
||||
@@ -205,7 +208,6 @@ function getBGColorValue(name) {
|
||||
return SGRValues[name + 'BG'];
|
||||
}
|
||||
|
||||
|
||||
// See http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/src/conio/cterm.txt
|
||||
// :TODO: document
|
||||
// :TODO: Create mappings for aliases... maybe make this a map to values instead
|
||||
@@ -275,49 +277,48 @@ const SYNCTERM_FONT_AND_ENCODING_TABLE = [
|
||||
// replaced with '_' for lookup purposes.
|
||||
//
|
||||
const FONT_ALIAS_TO_SYNCTERM_MAP = {
|
||||
'cp437' : 'cp437',
|
||||
'ibm_vga' : 'cp437',
|
||||
'ibmpc' : 'cp437',
|
||||
'ibm_pc' : 'cp437',
|
||||
'pc' : 'cp437',
|
||||
'cp437_art' : 'cp437',
|
||||
'ibmpcart' : 'cp437',
|
||||
'ibmpc_art' : 'cp437',
|
||||
'ibm_pc_art' : 'cp437',
|
||||
'msdos_art' : 'cp437',
|
||||
'msdosart' : 'cp437',
|
||||
'pc_art' : 'cp437',
|
||||
'pcart' : 'cp437',
|
||||
cp437: 'cp437',
|
||||
ibm_vga: 'cp437',
|
||||
ibmpc: 'cp437',
|
||||
ibm_pc: 'cp437',
|
||||
pc: 'cp437',
|
||||
cp437_art: 'cp437',
|
||||
ibmpcart: 'cp437',
|
||||
ibmpc_art: 'cp437',
|
||||
ibm_pc_art: 'cp437',
|
||||
msdos_art: 'cp437',
|
||||
msdosart: 'cp437',
|
||||
pc_art: 'cp437',
|
||||
pcart: 'cp437',
|
||||
|
||||
'ibm_vga50' : 'cp437',
|
||||
'ibm_vga25g' : 'cp437',
|
||||
'ibm_ega' : 'cp437',
|
||||
'ibm_ega43' : 'cp437',
|
||||
ibm_vga50: 'cp437',
|
||||
ibm_vga25g: 'cp437',
|
||||
ibm_ega: 'cp437',
|
||||
ibm_ega43: 'cp437',
|
||||
|
||||
'topaz' : 'topaz',
|
||||
'amiga_topaz_1' : 'topaz',
|
||||
'amiga_topaz_1+' : 'topaz_plus',
|
||||
'topazplus' : 'topaz_plus',
|
||||
'topaz_plus' : 'topaz_plus',
|
||||
'amiga_topaz_2' : 'topaz',
|
||||
'amiga_topaz_2+' : 'topaz_plus',
|
||||
'topaz2plus' : 'topaz_plus',
|
||||
topaz: 'topaz',
|
||||
amiga_topaz_1: 'topaz',
|
||||
'amiga_topaz_1+': 'topaz_plus',
|
||||
topazplus: 'topaz_plus',
|
||||
topaz_plus: 'topaz_plus',
|
||||
amiga_topaz_2: 'topaz',
|
||||
'amiga_topaz_2+': 'topaz_plus',
|
||||
topaz2plus: 'topaz_plus',
|
||||
|
||||
'pot_noodle' : 'pot_noodle',
|
||||
'p0tnoodle' : 'pot_noodle',
|
||||
'amiga_p0t-noodle' : 'pot_noodle',
|
||||
pot_noodle: 'pot_noodle',
|
||||
p0tnoodle: 'pot_noodle',
|
||||
'amiga_p0t-noodle': 'pot_noodle',
|
||||
|
||||
'mo_soul' : 'mo_soul',
|
||||
'mosoul' : 'mo_soul',
|
||||
'mo\'soul' : 'mo_soul',
|
||||
'amiga_mosoul' : 'mo_soul',
|
||||
mo_soul: 'mo_soul',
|
||||
mosoul: 'mo_soul',
|
||||
"mo'soul": 'mo_soul',
|
||||
amiga_mosoul: 'mo_soul',
|
||||
|
||||
'amiga_microknight' : 'microknight',
|
||||
'amiga_microknight+' : 'microknight_plus',
|
||||
|
||||
'atari' : 'atari',
|
||||
'atarist' : 'atari',
|
||||
amiga_microknight: 'microknight',
|
||||
'amiga_microknight+': 'microknight_plus',
|
||||
|
||||
atari: 'atari',
|
||||
atarist: 'atari',
|
||||
};
|
||||
|
||||
function setSyncTermFont(name, fontPage) {
|
||||
@@ -326,7 +327,7 @@ function setSyncTermFont(name, fontPage) {
|
||||
assert(p1 >= 0 && p1 <= 3);
|
||||
|
||||
const p2 = SYNCTERM_FONT_AND_ENCODING_TABLE.indexOf(name);
|
||||
if(p2 > -1) {
|
||||
if (p2 > -1) {
|
||||
return `${ESC_CSI}${p1};${p2} D`;
|
||||
}
|
||||
|
||||
@@ -343,31 +344,30 @@ function setSyncTermFontWithAlias(nameOrAlias) {
|
||||
}
|
||||
|
||||
const DEC_CURSOR_STYLE = {
|
||||
'blinking block' : 0,
|
||||
'default' : 1,
|
||||
'steady block' : 2,
|
||||
'blinking underline' : 3,
|
||||
'steady underline' : 4,
|
||||
'blinking bar' : 5,
|
||||
'steady bar' : 6,
|
||||
'blinking block': 0,
|
||||
default: 1,
|
||||
'steady block': 2,
|
||||
'blinking underline': 3,
|
||||
'steady underline': 4,
|
||||
'blinking bar': 5,
|
||||
'steady bar': 6,
|
||||
};
|
||||
|
||||
function setCursorStyle(cursorStyle) {
|
||||
const ps = DEC_CURSOR_STYLE[cursorStyle];
|
||||
if(ps) {
|
||||
if (ps) {
|
||||
return `${ESC_CSI}${ps} q`;
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
// Create methods such as up(), nextLine(),...
|
||||
Object.keys(CONTROL).forEach(function onControlName(name) {
|
||||
const code = CONTROL[name];
|
||||
|
||||
exports[name] = function() {
|
||||
exports[name] = function () {
|
||||
let c = code;
|
||||
if(arguments.length > 0) {
|
||||
if (arguments.length > 0) {
|
||||
// arguments are array like -- we want an array
|
||||
c = Array.prototype.slice.call(arguments).map(Math.round).join(';') + code;
|
||||
}
|
||||
@@ -376,10 +376,10 @@ Object.keys(CONTROL).forEach(function onControlName(name) {
|
||||
});
|
||||
|
||||
// Create various color methods such as white(), yellowBG(), reset(), ...
|
||||
Object.keys(SGRValues).forEach( name => {
|
||||
Object.keys(SGRValues).forEach(name => {
|
||||
const code = SGRValues[name];
|
||||
|
||||
exports[name] = function() {
|
||||
exports[name] = function () {
|
||||
return `${ESC_CSI}${code}m`;
|
||||
};
|
||||
});
|
||||
@@ -390,18 +390,18 @@ function sgr() {
|
||||
// - Each element can be either a integer or string found in SGRValues
|
||||
// which in turn maps to a integer
|
||||
//
|
||||
if(arguments.length <= 0) {
|
||||
if (arguments.length <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let result = [];
|
||||
const args = Array.isArray(arguments[0]) ? arguments[0] : arguments;
|
||||
let result = [];
|
||||
const args = Array.isArray(arguments[0]) ? arguments[0] : arguments;
|
||||
|
||||
for(let i = 0; i < args.length; ++i) {
|
||||
for (let i = 0; i < args.length; ++i) {
|
||||
const arg = args[i];
|
||||
if(_.isString(arg) && arg in SGRValues) {
|
||||
if (_.isString(arg) && arg in SGRValues) {
|
||||
result.push(SGRValues[arg]);
|
||||
} else if(_.isNumber(arg)) {
|
||||
} else if (_.isNumber(arg)) {
|
||||
result.push(arg);
|
||||
}
|
||||
}
|
||||
@@ -414,25 +414,25 @@ function sgr() {
|
||||
// to a ANSI SGR sequence.
|
||||
//
|
||||
function getSGRFromGraphicRendition(graphicRendition, initialReset) {
|
||||
let sgrSeq = [];
|
||||
let styleCount = 0;
|
||||
let sgrSeq = [];
|
||||
let styleCount = 0;
|
||||
|
||||
[ 'intensity', 'underline', 'blink', 'negative', 'invisible' ].forEach( s => {
|
||||
if(graphicRendition[s]) {
|
||||
['intensity', 'underline', 'blink', 'negative', 'invisible'].forEach(s => {
|
||||
if (graphicRendition[s]) {
|
||||
sgrSeq.push(graphicRendition[s]);
|
||||
++styleCount;
|
||||
}
|
||||
});
|
||||
|
||||
if(graphicRendition.fg) {
|
||||
if (graphicRendition.fg) {
|
||||
sgrSeq.push(graphicRendition.fg);
|
||||
}
|
||||
|
||||
if(graphicRendition.bg) {
|
||||
if (graphicRendition.bg) {
|
||||
sgrSeq.push(graphicRendition.bg);
|
||||
}
|
||||
|
||||
if(0 === styleCount || initialReset) {
|
||||
if (0 === styleCount || initialReset) {
|
||||
sgrSeq.unshift(0);
|
||||
}
|
||||
|
||||
@@ -452,11 +452,11 @@ function resetScreen() {
|
||||
}
|
||||
|
||||
function normal() {
|
||||
return sgr( [ 'normal', 'reset' ] );
|
||||
return sgr(['normal', 'reset']);
|
||||
}
|
||||
|
||||
function goHome() {
|
||||
return exports.goto(); // no params = home = 1,1
|
||||
return exports.goto(); // no params = home = 1,1
|
||||
}
|
||||
|
||||
//
|
||||
@@ -476,32 +476,36 @@ function disableVT100LineWrapping() {
|
||||
}
|
||||
|
||||
function setEmulatedBaudRate(rate) {
|
||||
const speed = {
|
||||
unlimited : 0,
|
||||
off : 0,
|
||||
0 : 0,
|
||||
300 : 1,
|
||||
600 : 2,
|
||||
1200 : 3,
|
||||
2400 : 4,
|
||||
4800 : 5,
|
||||
9600 : 6,
|
||||
19200 : 7,
|
||||
38400 : 8,
|
||||
57600 : 9,
|
||||
76800 : 10,
|
||||
115200 : 11,
|
||||
}[rate] || 0;
|
||||
const speed =
|
||||
{
|
||||
unlimited: 0,
|
||||
off: 0,
|
||||
0: 0,
|
||||
300: 1,
|
||||
600: 2,
|
||||
1200: 3,
|
||||
2400: 4,
|
||||
4800: 5,
|
||||
9600: 6,
|
||||
19200: 7,
|
||||
38400: 8,
|
||||
57600: 9,
|
||||
76800: 10,
|
||||
115200: 11,
|
||||
}[rate] || 0;
|
||||
return 0 === speed ? exports.emulationSpeed() : exports.emulationSpeed(1, speed);
|
||||
}
|
||||
|
||||
function vtxHyperlink(client, url, len) {
|
||||
if(!client.terminalSupports('vtx_hyperlink')) {
|
||||
if (!client.terminalSupports('vtx_hyperlink')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
len = len || url.length;
|
||||
|
||||
url = url.split('').map(c => c.charCodeAt(0)).join(';');
|
||||
url = url
|
||||
.split('')
|
||||
.map(c => c.charCodeAt(0))
|
||||
.join(';');
|
||||
return `${ESC_CSI}1;${len};1;1;${url}\\`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user