* Some work on color codes module
This commit is contained in:
parent
658c64c8c8
commit
c87c0d69b7
|
@ -29,7 +29,6 @@ exports.disableVT100LineWrapping = disableVT100LineWrapping;
|
|||
exports.setSyncTERMFont = setSyncTERMFont;
|
||||
exports.getSyncTERMFontFromAlias = getSyncTERMFontFromAlias;
|
||||
exports.setCursorStyle = setCursorStyle;
|
||||
exports.fromPipeCode = fromPipeCode;
|
||||
|
||||
|
||||
//
|
||||
|
@ -394,54 +393,3 @@ function goHome() {
|
|||
function disableVT100LineWrapping() {
|
||||
return ESC_CSI + '7l';
|
||||
}
|
||||
|
||||
// Also add:
|
||||
// * fromRenegade(): |<0-23>
|
||||
// * fromCelerity(): |<case sensitive letter>
|
||||
// * fromPCBoard(): (@X<bg><fg>@)
|
||||
// * fromWildcat(): (@<bg><fg>@ (same as PCBoard without 'X' prefix)
|
||||
// * fromWWIV(): <ctrl-c><0-7>
|
||||
// * fromSyncronet(): <ctrl-a><colorCode>
|
||||
// See http://wiki.synchro.net/custom:colors
|
||||
function fromPipeCode(s) {
|
||||
if(-1 == s.indexOf('|')) {
|
||||
return s; // no pipe codes present
|
||||
}
|
||||
|
||||
var result = '';
|
||||
var re = /\|(\d{2,3}|\|)/g;
|
||||
var m;
|
||||
var lastIndex = 0;
|
||||
while((m = re.exec(s))) {
|
||||
var val = m[1];
|
||||
|
||||
if('|' == val) {
|
||||
result += '|';
|
||||
continue;
|
||||
}
|
||||
|
||||
// convert to number
|
||||
val = parseInt(val, 10);
|
||||
if(isNaN(val)) {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
assert(val >= 0 && val <= 256);
|
||||
|
||||
var attr = '';
|
||||
if(7 == val) {
|
||||
attr = sgr('normal');
|
||||
} else if (val < 7 || val >= 16) {
|
||||
attr = sgr(['normal', val]);
|
||||
} else if (val <= 15) {
|
||||
attr = sgr(['normal', val - 8, 'bold']);
|
||||
}
|
||||
|
||||
result += s.substr(lastIndex, m.index - lastIndex) + attr;
|
||||
lastIndex = re.lastIndex;
|
||||
}
|
||||
|
||||
result = (0 === result.length ? s : result + s.substr(lastIndex));
|
||||
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var ansi = require('./ansi_term.js');
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
exports.pipeToAnsi = exports.renegadeToAnsi = renegadeToAnsi;
|
||||
exports.stripPipeCodes = exports.stripRenegadeCodes = stripRenegadeCodes;
|
||||
|
||||
// :TODO: Not really happy with the module name of "color_codes". Would like something better
|
||||
|
||||
|
||||
|
||||
// Also add:
|
||||
// * fromCelerity(): |<case sensitive letter>
|
||||
// * fromPCBoard(): (@X<bg><fg>)
|
||||
// * fromWildcat(): (@<bg><fg>@ (same as PCBoard without 'X' prefix and '@' suffix)
|
||||
// * fromWWIV(): <ctrl-c><0-7>
|
||||
// * fromSyncronet(): <ctrl-a><colorCode>
|
||||
// See http://wiki.synchro.net/custom:colors
|
||||
function renegadeToAnsi(s) {
|
||||
if(-1 == s.indexOf('|')) {
|
||||
return s; // no pipe codes present
|
||||
}
|
||||
|
||||
var result = '';
|
||||
var re = /\|(\d{2,3}|\|)/g;
|
||||
var m;
|
||||
var lastIndex = 0;
|
||||
while((m = re.exec(s))) {
|
||||
var val = m[1];
|
||||
|
||||
if('|' == val) {
|
||||
result += '|';
|
||||
continue;
|
||||
}
|
||||
|
||||
// convert to number
|
||||
val = parseInt(val, 10);
|
||||
if(isNaN(val)) {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
assert(val >= 0 && val <= 256);
|
||||
|
||||
var attr = '';
|
||||
if(7 == val) {
|
||||
attr = ansi.sgr('normal');
|
||||
} else if (val < 7 || val >= 16) {
|
||||
attr = ansi.sgr(['normal', val]);
|
||||
} else if (val <= 15) {
|
||||
attr = ansi.sgr(['normal', val - 8, 'bold']);
|
||||
}
|
||||
|
||||
result += s.substr(lastIndex, m.index - lastIndex) + attr;
|
||||
lastIndex = re.lastIndex;
|
||||
}
|
||||
|
||||
result = (0 === result.length ? s : result + s.substr(lastIndex));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function stripRenegadeCodes(s) {
|
||||
return s.replace(/\|[\d]{2,3}/g, '');
|
||||
}
|
||||
|
|
@ -2,11 +2,13 @@
|
|||
'use strict';
|
||||
|
||||
var ansi = require('./ansi_term.js');
|
||||
//var artwork = require('./art.js');
|
||||
var colorCodes = require('./color_codes.js');
|
||||
var theme = require('./theme.js');
|
||||
var moduleUtil = require('./module_util.js');
|
||||
var Log = require('./logger.js').log;
|
||||
var Config = require('./config.js').config;
|
||||
|
||||
|
||||
var packageJson = require('../package.json');
|
||||
|
||||
var assert = require('assert');
|
||||
|
@ -77,7 +79,8 @@ function prepareTerminal(term) {
|
|||
|
||||
function displayBanner(term) {
|
||||
// :TODO: add URL(s) to banner
|
||||
term.write(ansi.fromPipeCode(util.format('' +
|
||||
//term.write(ansi.fromPipeCode(util.format('' +
|
||||
term.write(colorCodes.pipeToAnsi(util.format(
|
||||
'|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' +
|
||||
'|00|33Copyright (c) 2014-2015 Bryan Ashby\n' +
|
||||
'|00', packageJson.version)));
|
||||
|
|
Loading…
Reference in New Issue