summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/codeq/comms.js10
-rw-r--r--js/python.js66
-rw-r--r--python.html4
3 files changed, 56 insertions, 24 deletions
diff --git a/js/codeq/comms.js b/js/codeq/comms.js
index 8b89cde..25c1f8c 100644
--- a/js/codeq/comms.js
+++ b/js/codeq/comms.js
@@ -121,6 +121,16 @@
return send('query', query);
},
+ sendPush: function commsSendPush (json) {
+ json['sid'] = codeq.sid;
+ return send('python_push', json);
+ },
+
+ sendPull: function commsSendPull (json) {
+ json['sid'] = codeq.sid;
+ return send('python_pull', json);
+ },
+
sendHint: function commsSendHint (json) {
json['sid'] = codeq.sid;
return send('hint', json);
diff --git a/js/python.js b/js/python.js
index f4703b2..df23773 100644
--- a/js/python.js
+++ b/js/python.js
@@ -7,17 +7,45 @@
var firstCharacterPos = {'line': 0, 'ch': 0};
var makePythonTerminalHandler = function (jqConsole, editor, problem_id, activityHandler) {
- var terminal = jqConsole.terminal(function (command, terminal) {
- terminal.echo('Not implemented yet.');
- }, {
- 'history': true,
- 'prompt': '>>> ',
- 'greetings': 'CodeQ python terminal proxy',
- 'exit': false,
- 'clear': false
- });
+ var terminal = codeq.makeConsole(jqConsole, {
+ 'greeting': 'CodeQ Python terminal proxy'
+ });
+ terminal.onInput = function (text) {
+ if (!text)
+ 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();
+ };
+
+ 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);
- return {};
+ return terminal;
};
var makeActivityHandler = function (editor) {
@@ -282,8 +310,7 @@
});
$('#btn_code_hint').on('click', function () {
// handler.processServerHints([{id:'drop_down', start: 20, end: 26, choices:['ena', 'dva', 'tri']}]);
- jqConsole.echo('?- hint.');
- jqConsole.pause();
+ terminal.append('>>> hint\n');
var doc = editor.getDoc();
codeq.comms.sendHint({
'language': 'python',
@@ -291,21 +318,18 @@
'problem_id': problem.id
}).then(
function hintSuccess(data) {
- jqConsole.resume();
if (data.code === 0)
handler.processServerHints(data.hints);
else
- jqConsole.error(data.message);
+ terminal.append('error: ' + data.message);
},
function hintFailed (error) {
- jqConsole.resume();
- jqConsole.exception(error);
+ terminal.append('exception: ' + error);
}
).done();
});
$('#btn_code_test').on('click', function () {
- jqConsole.echo('?- test.');
- jqConsole.pause();
+ terminal.append('>>> test\n');
var doc = editor.getDoc();
codeq.comms.sendTest({
'language': 'python',
@@ -313,15 +337,13 @@
'problem_id': problem.id
}).then(
function testSuccess(data) {
- jqConsole.resume();
if (data.code === 0)
handler.processServerHints(data.hints);
else
- jqConsole.error(data.message);
+ terminal.append('error: ' + data.message);
},
function testFailed (error) {
- jqConsole.resume();
- jqConsole.exception(error);
+ terminal.append('exception: ' + error);
}
).done();
});
diff --git a/python.html b/python.html
index 4e3b788..798f60c 100644
--- a/python.html
+++ b/python.html
@@ -15,6 +15,7 @@
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- App -->
<link rel="stylesheet" href="css/codeq.css" type="text/css">
+ <link rel="stylesheet" href="css/codeq/console.css" type="text/css">
</head>
<body>
@@ -80,8 +81,6 @@
<!-- jQuery stuff -->
<script src="js/jquery/jquery-1.11.3.js"></script>
- <script src="js/jquery/jquery.terminal-0.8.8.js"></script>
- <!--script src="js/jquery/jquery.console.js"></script>
<!-- Q promise library -->
<script src="js/q.js"></script>
<!-- Bootstrap -->
@@ -96,6 +95,7 @@
<!-- codeq app -->
<script src="js/codeq.js"></script>
<script src="js/codeq/comms.js"></script>
+ <script src="js/codeq/console.js"></script>
<script src="js/def_parser.js"></script>
<script src="js/python.js"></script>
</body>