summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/python.js60
1 files changed, 26 insertions, 34 deletions
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;
};
})();