From e80366dbbbd4e3d00a77608a0dfe64da244d5a8b Mon Sep 17 00:00:00 2001 From: Petter Wahlman Date: Fri, 6 Oct 2017 16:43:31 +0200 Subject: [PATCH] Improve compiler/execution/program output Compact output. Do not print compiler return code if successful execution Print console output with monospaced font Print console stderr with red color --- static/output.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/static/output.js b/static/output.js index 68f32731f..104c259fe 100644 --- a/static/output.js +++ b/static/output.js @@ -59,15 +59,19 @@ define(function (require) { this.add(obj.text, obj.tag ? obj.tag.line : obj.line); }, this); - this.add("Compiler exited with result code " + result.code); + if (!result.execResult) { + this.add("compiler returned: " + result.code); + } else { + this.add("program returned: " + result.execResult.code); + if (result.execResult.stderr.length || result.execResult.stdout.length) { + _.each(result.execResult.stderr, function (obj) { + this.programOutput(obj.text, "red"); + }, this); - if (result.execResult) { - var elem = $('

').appendTo(this.contentRoot); - this.add("Output from execution:"); - _.each((result.execResult.stdout || []).concat(result.execResult.stderr || []), function (obj) { - this.add(obj.text, obj.line); - }, this); - this.add("User code exited with result code " + result.execResult.code); + _.each(result.execResult.stdout, function (obj) { + this.programOutput(obj.text); + }, this); + } } this.updateCompilerName(); @@ -77,6 +81,14 @@ define(function (require) { if (id === this.compilerId) this.fontScale.setScale(scale); }; + Output.prototype.programOutput = function (msg, color) { + var elem = $('
').appendTo(this.contentRoot); + elem.text(msg); + elem.css('font-family', '"Courier New", Courier, monospace'); + if (color) + elem.css("color", color); + }; + Output.prototype.add = function (msg, lineNum) { var elem = $('
').appendTo(this.contentRoot); if (lineNum) {