-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.js
139 lines (117 loc) · 2.82 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var editor;
var session;
function clear_errors() {
$("#errors").html('');
}
var prevItem = null;
function highlightItem(item) {
if (prevItem) {
$(prevItem).css({ background: "none" });
}
$(item).css({ background: "red", });
prevItem = item;
}
function errorLine(err) {
var M = err.match(/^(\d+):(\d+)?:?/);
var lineno;
if (M && M.length > 0) {
lineno = Number(M[1]);
}
return lineno;
}
function addError(err) {
$('<pre>' + err + '</pre>')
.click(function () {
var ln = errorLine(err);
if (ln) editor.gotoLine(ln, false);
highlightItem(this);
})
.appendTo("#errors");
}
function showErrors(errs) {
clear_errors();
if (errs.length == 0) {
$("#errors").css({ height: 0 });
$("#runButton").button("enable");
$("#compileButton")
.button("disable")
.button({ icons: { primary: 'ui-icon-check' } });
} else {
$("#errors").css({ height: "30%" });
$("#runButton").button("disable");
for (var i = 0; i < errs.length; i++) {
addError(errs[i]);
}
}
var H = $("#errors").height();
$("#editor").css({ bottom: H + 2 });
editor.resize();
}
function compileProgram() {
var code = editor.getSession().getDocument().getValue();
session.compile(code, showErrors);
}
function showOutput(linesOfOutput) {
alert(linesOfOutput);
}
function runProgram() {
if (!$(this).button("option", "disabled")) {
session.run("", showOutput);
}
}
function openSettings() {
$("#configDialog").dialog('open');
return false;
}
function sessionStart(_session) {
session = _session;
$("#compileButton").button("enable");
}
function sourceCodeChanged() {
$("#compileButton")
.button("enable")
.button({ icons: { primary: 'ui-icon-gear' } });
$("#runButton").button("disable");
}
function setup(remote) {
var EditSession = require("ace/edit_session").EditSession;
var CppMode = require("ace/mode/c_cpp").Mode;
editor = ace.edit("editor");
var program = $("#program").html();
var session = new EditSession(program);
session.setMode(new CppMode());
session.setTabSize(2);
session.on('change', sourceCodeChanged);
editor.setSession(session);
$("#configDialog").dialog({
autoOpen: false,
modal: true,
width: 600,
height: 420,
buttons: {
"D'acord": function() {
$(this).dialog("close");
}
},
});
$("#compileButton")
.button({ icons: { primary: 'ui-icon-gear' } })
.button("disable")
.click(compileProgram);
$("#runButton")
.button({ icons: { primary: 'ui-icon-play' } })
.button("disable")
.click(runProgram);
$("#settingsButton")
.button({ icons: { primary: 'ui-icon-wrench' } })
.click(openSettings);
$("#errors").resize(function () {
var y = $("body").height() - $("#errors").height();
alert(y);
$("#editor").css({ bottom: y });
});
remote.startSession(sessionStart);
}
$(document).ready(function () {
DNode.connect(setup);
});