Skip to content

Commit

Permalink
Restore ansi esc handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xdissent committed Aug 20, 2015
1 parent e96f097 commit 9d15535
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion client/ansi/filters/ansi.js
Expand Up @@ -3,8 +3,16 @@
var ansi_up = require('ansi_up');

module.exports = function () {
return function (input) {
return function (input, plaintext) {
if (!input) return '';
// 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, '');
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));
}
};
2 changes: 1 addition & 1 deletion test/unit/fixtures/ansi-1.out
@@ -1,7 +1,7 @@
SettingsManager, when initialized
with a single item
✓ should retrieve
✓ should set & retrieve
✓ should set & retrieve
with a nested item
✓ should be accessible as a.b
✓ should inherit type when not specified
Expand Down

0 comments on commit 9d15535

Please sign in to comment.