consolecolor/dist/index.js

56 lines
4.3 KiB
JavaScript
Raw Normal View History

2017-01-21 17:10:27 +00:00
"use strict";
require("typings-global");
const ansiColors = require("ansi-256-colors");
/**
* the color translator function
*/
let colorTranslator = (colorArg) => {
switch (colorArg) {
2017-01-21 17:26:22 +00:00
case 'black':
return { r: 0, g: 0, b: 0 };
2017-01-21 17:10:27 +00:00
case 'blue':
2017-01-21 19:30:53 +00:00
return { r: 0, g: 2, b: 5 };
2017-01-21 17:26:22 +00:00
case 'brown':
return { r: 1, g: 0, b: 0 };
2017-01-21 17:10:27 +00:00
case 'cyan':
2017-01-21 18:46:51 +00:00
return { r: 2, g: 4, b: 4 };
2017-01-21 17:10:27 +00:00
case 'green':
2017-01-21 19:27:25 +00:00
return { r: 2, g: 4, b: 1 };
2017-01-21 17:10:27 +00:00
case 'orange':
2017-01-21 19:27:25 +00:00
return { r: 5, g: 3, b: 1 };
2017-01-21 17:26:22 +00:00
case 'pink':
2017-01-21 19:27:25 +00:00
return { r: 3, g: 2, b: 4 };
2017-01-21 17:26:22 +00:00
case 'red':
return { r: 5, g: 0, b: 0 };
2017-01-21 17:10:27 +00:00
case 'white':
return { r: 5, g: 5, b: 5 };
default:
return { r: 5, g: 5, b: 5 };
}
};
/**
* colors the font of a string
*/
let coloredFont = (stringArg, colorArg) => {
let rgbCode = colorTranslator(colorArg);
return ansiColors.fg.getRgb(rgbCode.r, rgbCode.g, rgbCode.b) + stringArg;
};
/**
* colors the back of a string
*/
let coloredBackground = (stringArg, colorArg) => {
let rgbCode = colorTranslator(colorArg);
return ansiColors.bg.getRgb(rgbCode.r, rgbCode.g, rgbCode.b) + stringArg;
};
/**
* color a string with xterm
*/
exports.coloredString = (stringArg, colorFontArg, colorBackgroundArg) => {
let returnString = coloredFont(stringArg, colorFontArg);
if (colorBackgroundArg) {
returnString = coloredBackground(returnString, colorBackgroundArg);
}
returnString = returnString + ansiColors.reset;
return returnString;
};
2017-01-21 17:26:22 +00:00
//# sourceMappingURL=data:application/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