Skip to content

Instantly share code, notes, and snippets.

@mjm mjm/ordered_log.js
Last active Dec 29, 2015

Embed
What would you like to do?
function deansi(log) {
var ansi, text;
log = log.replace(/\r\r/g, '\r').replace(/\033\[K\r/g, '\r').replace(/\[2K/g, '').replace(/\033\(B/g, '').replace(/\033\[\d+G/g, '');
ansi = ansiparse(log);
text = '';
ansi.forEach(function(part) {
var classes = [];
part.foreground && classes.push(part.foreground);
part.background && classes.push('bg-' + part.background);
part.bold && classes.push('bold');
part.italic && classes.push('italic');
return text += (classes.length ? '<span class=\'' + classes.join(' ') + '\'>' + part.text + '</span>' : part.text);
});
return text.replace(/\033/g, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.