From 3c02044761366fe474c7bf8cb5ba7307960c788c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Tue, 15 Sep 2015 20:06:01 +0200 Subject: Prolog handler now uses CodeQ terminal. --- js/python.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'js/python.js') diff --git a/js/python.js b/js/python.js index d16cc72..82423c6 100644 --- a/js/python.js +++ b/js/python.js @@ -48,11 +48,11 @@ return terminal; }; - var makeActivityHandler = function (editor) { + var makeActivityHandler = function (editor, problem_id) { var lastActivityMillis = Date.now(), deltaActivityMillis = function deltaActivityMillisFunc () { var now = Date.now(), - dt = Math.max(0, Math.min(30000, now - lastActivityMillis)); // 0 sec <= dt <= 30 sec + dt = now - lastActivityMillis; lastActivityMillis = now; return dt; }, @@ -62,7 +62,7 @@ var promise; ts = null; if (queue.length === 0) return Q(true); - promise = codeq.comms.sendActivity(queue, editor.getDoc().getValue()); + promise = codeq.comms.sendActivity(queue, editor.getDoc().getValue(), problem_id); queue.length = 0; return promise; }, @@ -111,7 +111,7 @@ jqConsole = $('#console'), jqHints = $('#info'), editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true, mode: 'python' }), - activityHandler = makeActivityHandler(editor), + activityHandler = makeActivityHandler(editor, problem.id), terminal = makePythonTerminalHandler(jqConsole, editor, problem.id, activityHandler), /** Object. */ @@ -248,6 +248,7 @@ var handler = { destroy: function () { + terminal.destroy(); jqDescription.empty(); jqEditor.empty(); // TODO: perhaps you do not want to "free" the editor, just empty it jqConsole.empty(); // TODO: the same with the console -- cgit v1.2.1 From d10866be04d45fc73eddce0ec7005161e69e97a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Wed, 16 Sep 2015 11:37:52 +0200 Subject: Removed the "run" and "break" buttons. Removed commented-out code from prolog and python handlers. --- js/python.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'js/python.js') diff --git a/js/python.js b/js/python.js index 82423c6..11e8a2b 100644 --- a/js/python.js +++ b/js/python.js @@ -72,17 +72,11 @@ }; return { - "trace": function (trace) { + 'queueTrace': function (trace) { trace['dt'] = deltaActivityMillis(); - return trace; - }, - 'queue': function (trace) { queue.push(trace); if (ts === null) setTimeout(timer, 10000); // flush every 10 seconds }, - 'queueTrace': function (trace) { - this.queue(this.trace(trace)); - }, 'flush': flush, 'addAndPurge': function (trace) { var accumulatedTrace = queue; @@ -113,8 +107,6 @@ editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true, mode: 'python' }), activityHandler = makeActivityHandler(editor, problem.id), terminal = makePythonTerminalHandler(jqConsole, editor, problem.id, activityHandler), - - /** Object. */ hintDefs = problem.hint, hintCounter = 0, // for generating unique class-names hintCleaners = [], @@ -313,14 +305,6 @@ // $(jqButtons.get(1)).on('click', function () { handler.processServerHints([{id:'popup_unknown', start: 20, end: 26}]); }); // $(jqButtons.get(2)).on('click', function () { handler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]); }); - $('#btn_code_run').on('click', function () { - var doc = editor.getDoc(); -// codeq.comms.sendActivity({'typ': 'slv', 'dt': dt, 'qry': }); -// handler.processServerHints([{id:'list_empty'}]); - }); - $('#btn_code_break').on('click', function () { -// handler.processServerHints([{id:'popup_unknown', start: 20, end: 26}]); - }); $('#btn_code_hint').on('click', function () { // handler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]); terminal.append('>>> hint\n'); -- cgit v1.2.1 From 0eec2bd8f8fd8669682cf618bf22983a36f828a9 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 16 Sep 2015 16:17:52 +0200 Subject: Implement async. comm. with Python interpreter --- js/python.js | 60 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) (limited to 'js/python.js') diff --git a/js/python.js b/js/python.js index 11e8a2b..7d7458e 100644 --- a/js/python.js +++ b/js/python.js @@ -8,42 +8,31 @@ var makePythonTerminalHandler = function (jqConsole, editor, problem_id, activityHandler) { var terminal = codeq.makeConsole(jqConsole, { - 'greeting': 'CodeQ Python terminal proxy' - }); + 'greeting': 'CodeQ Python terminal proxy' + }), + tcs = function terminalCommandSuccess (data) { + if (data.code !== 0) { + terminal.append(data.message, 'error'); + } + }, + tcf = function terminalCommandFailed (error) { + terminal.append(error + '\n', 'error'); + }; + terminal.onInput = function (text) { - if (!text) - return; - codeq.comms.sendPush({ + return codeq.comms.sendPush({ 'text': text + '\n' - }).then( - function pushSuccess (data) { - if (data.code !== 0) - terminal.append('error: ' + data.message); - }, - function pushFailed (error) { - terminal.append('exception: '+ error); - } - ).done(); + }).then(tcs, tcf); }; - var interval_id = setInterval(function () { - codeq.comms.sendPull({}).then( - function pullSuccess (data) { - if (data.code === 0) { - t = data.terminal; - if (!t.text) - return; - terminal.append(t.text); - } - else { - terminal.append('error: ' + data.message); - } - }, - function pullFailed (error) { - terminal.append('exception: '+ error); - } - ).done(); - }, 200); + codeq.comms.on('terminal_output', function (data) { + var text = data.text; + terminal.append(text, 'output'); + lines = text.split('\n'); + terminal.leftmostCol = lines[lines.length-1].length; + }); + + terminal.leftmostCol = 1; return terminal; }; @@ -307,7 +296,6 @@ $('#btn_code_hint').on('click', function () { // handler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]); - terminal.append('>>> hint\n'); var doc = editor.getDoc(); codeq.comms.sendHint({ 'language': 'python', @@ -326,7 +314,6 @@ ).done(); }); $('#btn_code_test').on('click', function () { - terminal.append('>>> test\n'); var doc = editor.getDoc(); codeq.comms.sendTest({ 'language': 'python', @@ -345,6 +332,11 @@ ).done(); }); + // TODO first line of interpreter output is buffered without this, why? + codeq.comms.sendPush({ + 'text': '' + }); + return handler; }; })(); -- cgit v1.2.1