Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts ANSI terminal codes to HTML in logs #5620

Merged
merged 2 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ui/app/utils/classes/log.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { alias } from '@ember/object/computed';
import { assert } from '@ember/debug';
import { htmlSafe } from '@ember/template';
import Evented from '@ember/object/evented';
import EmberObject, { computed } from '@ember/object';
import { assign } from '@ember/polyfills';
import queryString from 'query-string';
import { task } from 'ember-concurrency';
import StreamLogger from 'nomad-ui/utils/classes/stream-logger';
import PollLogger from 'nomad-ui/utils/classes/poll-logger';
import Anser from 'anser';

const MAX_OUTPUT_LENGTH = 50000;

Expand Down Expand Up @@ -37,7 +39,9 @@ const Log = EmberObject.extend(Evented, {
// The top or bottom of the log, depending on whether
// the logPointer is pointed at head or tail
output: computed('logPointer', 'head', 'tail', function() {
return this.logPointer === 'head' ? this.head : this.tail;
let logs = this.logPointer === 'head' ? this.head : this.tail;
let colouredLogs = Anser.ansiToHtml(logs);
return htmlSafe(colouredLogs);
}),

init() {
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"'app/styles/**/*.*'": ["prettier --write", "git add"]
},
"devDependencies": {
"anser": "^1.4.8",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@ember/jquery": "^0.6.0",
"@ember/optional-features": "^0.7.0",
Expand Down
4 changes: 2 additions & 2 deletions ui/tests/unit/utils/log-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ module('Unit | Util | Log', function(hooks) {
});

await settled();
assert.ok(log.get('output').endsWith(truncationMessage), 'Truncation message is shown');
assert.ok(log.get('output').toString().endsWith(truncationMessage), 'Truncation message is shown');
assert.equal(
log.get('output').length,
log.get('output').toString().length,
50000 + truncationMessage.length,
'Output is truncated the appropriate amount'
);
Expand Down
5 changes: 5 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,11 @@ amdefine@>=0.0.4:
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=

anser@^1.4.8:
version "1.4.8"
resolved "https://registry.yarnpkg.com/anser/-/anser-1.4.8.tgz#19a3bfc5f0e31c49efaea38f58fd0d136597f2a3"
integrity sha512-tVHucTCKIt9VRrpQKzPtOlwm/3AmyQ7J+QE29ixFnvuE2hm83utEVrN7jJapYkHV6hI0HOHkEX9TOMCzHtwvuA==

ansi-escapes@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-1.4.0.tgz#d3a8a83b319aa67793662b13e761c7911422306e"
Expand Down