Skip to content

Commit

Permalink
Actually fix ansi usage
Browse files Browse the repository at this point in the history
Returning a function was an artifact from angular
  • Loading branch information
Ilya Radchenko committed Sep 13, 2016
1 parent 728f8d9 commit 003a0cb
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/ansi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
var ansi_up = require('ansi_up');

// Copy of client/ansi/filters/ansi.js
module.exports = function () {
return function (input, plaintext) {
if (!input) return '';
if (input.length > 100000) return input;
// handle the characters for "delete line" and "move to start of line"
var startswithcr = /^[^\n]*\r[^\n]/.test(input);
module.exports = function (input, plaintext) {
if (!input) return '';
if (input.length > 100000) return input;
// handle the characters for "delete line" and "move to start of line"
var startswithcr = /^[^\n]*\r[^\n]/.test(input);

input = input.replace(/^[^\n\r]*\u001b\[2K/gm, '')
.replace(/\u001b\[K[^\n\r]*/g, '')
.replace(/[^\n]*\r([^\n])/g, '$1')
.replace(/^[^\n]*\u001b\[0G/gm, '');
input = input.replace(/^[^\n\r]*\u001b\[2K/gm, '')
.replace(/\u001b\[K[^\n\r]*/g, '')
.replace(/[^\n]*\r([^\n])/g, '$1')
.replace(/^[^\n]*\u001b\[0G/gm, '');

if (startswithcr) input = `\r${input}`;
if (plaintext) return ansi_up.ansi_to_text(input);
if (startswithcr) input = `\r${input}`;
if (plaintext) return ansi_up.ansi_to_text(input);

return ansi_up.ansi_to_html(ansi_up.escape_for_html(input));
};
return ansi_up.ansi_to_html(ansi_up.escape_for_html(input));
};

0 comments on commit 003a0cb

Please sign in to comment.