diff --git a/static/panes/diff.js b/static/panes/diff.js index 2aa76cf39..244dea446 100644 --- a/static/panes/diff.js +++ b/static/panes/diff.js @@ -33,22 +33,50 @@ var ga = require('../analytics'); require('../modes/asm-mode'); require('selectize'); -function State(id, model) { +var + DiffType_ASM = 0, + DiffType_CompilerStdOut = 1, + DiffType_CompilerStdErr = 2, + DiffType_ExecStdOut = 3, + DiffType_ExecStdErr = 4; + +function State(id, model, difftype) { this.id = id; this.model = model; this.compiler = null; this.result = null; + this.difftype = difftype; } State.prototype.update = function (id, compiler, result) { if (this.id !== id) return false; this.compiler = compiler; this.result = result; - var asm = result.asm || []; - this.model.setValue(_.pluck(asm, 'text').join("\n")); + this.refresh(); + return true; }; +State.prototype.refresh = function () { + var output = []; + if (this.result) { + if (this.difftype === DiffType_ASM) { + output = this.result.asm || []; + } else if (this.difftype === DiffType_CompilerStdOut) { + output = this.result.stdout; + } else if (this.difftype === DiffType_CompilerStdErr) { + output = this.result.stderr || []; + } else if (this.difftype === DiffType_ExecStdOut) { + if (this.result.execResult) + output = this.result.execResult.stdout || []; + } else if (this.difftype === DiffType_ExecStdErr) { + if (this.result.execResult) + output = this.result.execResult.stderr || []; + } + } + this.model.setValue(_.pluck(output, 'text').join("\n")); +}; + function Diff(hub, container, state) { this.container = container; this.eventHub = hub.createEventHub(); @@ -63,10 +91,41 @@ function Diff(hub, container, state) { language: 'asm' }); - this.lhs = new State(state.lhs, monaco.editor.createModel('', 'asm')); - this.rhs = new State(state.rhs, monaco.editor.createModel('', 'asm')); + this.lhs = new State(state.lhs, monaco.editor.createModel('', 'asm'), state.lhsdifftype || DiffType_ASM); + this.rhs = new State(state.rhs, monaco.editor.createModel('', 'asm'), state.rhsdifftype || DiffType_ASM); this.outputEditor.setModel({original: this.lhs.model, modified: this.rhs.model}); + var selectizeType = this.domRoot.find(".difftype-picker").selectize({ + sortField: 'name', + valueField: 'id', + labelField: 'name', + searchField: ['name'], + options: [ + {id: DiffType_ASM, name: 'Assembly'}, + {id: DiffType_CompilerStdOut, name: 'Compiler stdout'}, + {id: DiffType_CompilerStdErr, name: 'Compiler stderr'}, + {id: DiffType_ExecStdOut, name: 'Execution stdout'}, + {id: DiffType_ExecStdErr, name: 'Execution stderr'} + ], + items: [], + render: { + option: function (item, escape) { + return '