Added support for rendering style tagged strings
This commit is contained in:
parent
e3272e8449
commit
5dae42e9c5
4 changed files with 60 additions and 0 deletions
19
index.js
19
index.js
|
|
@ -77,6 +77,24 @@ function applyStyle() {
|
|||
return str;
|
||||
}
|
||||
|
||||
function colorize(text){
|
||||
// Permit a map of aliases for long styles
|
||||
var styleAliases = {
|
||||
'b' : 'bold',
|
||||
'u' : 'underline',
|
||||
'i' : 'italic',
|
||||
'inv' : 'inverse',
|
||||
'h' : 'hidden',
|
||||
's' : 'strikethrough',
|
||||
'd' : 'dim'
|
||||
};
|
||||
return text.replace(/<(\/?)(\w+)>/g,function(full,closed,tag){
|
||||
var color = ansiStyles[(tag in styleAliases) ? styleAliases[tag] : tag];
|
||||
return color ? color[closed ? 'close' : 'open'] : full;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function init() {
|
||||
var ret = {};
|
||||
|
||||
|
|
@ -98,3 +116,4 @@ module.exports.styles = ansiStyles;
|
|||
module.exports.hasColor = hasAnsi;
|
||||
module.exports.stripColor = stripAnsi;
|
||||
module.exports.supportsColor = supportsColor;
|
||||
module.exports.colorize = colorize;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue