Skip to content

Commit e459216

Browse files
committed
UI-js: cleanup
1 parent 1143b69 commit e459216

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

static/js/main.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function logClear() {
5050
log.innerHTML = "";
5151
log_pos = 0;
5252
}
53-
function logAppend(str, is_volatile) {
53+
function logStatus(str) {
5454
log.innerHTML = log.innerHTML.substring(0, log_pos) + htmlEscape(str);
55-
if (!is_volatile) {
56-
log_pos = log.innerHTML.length;
57-
}
55+
}
56+
function logAppend(str) {
57+
logStatus(str);
58+
log_pos = log.innerHTML.length;
5859
}
5960

6061
const out = document.getElementById("output");
@@ -71,15 +72,15 @@ const stdin_input = document.getElementById("stdin");
7172

7273
function fatalError(msg) {
7374
logClear();
74-
logAppend(msg, true);
75+
logStatus(msg);
7576
compile_button.disabled = true;
7677
kill_button.disabled = true;
7778
stdin_input.disabled = true;
7879
}
7980

8081
const socket = io("/compiler");
8182
socket.on('connect', function() {
82-
logAppend("Click \"Compile & Execute\" when ready.", true);
83+
logStatus("Click \"Compile & Execute\" when ready.");
8384
compile_button.disabled = false;
8485
kill_button.disabled = true;
8586
stdin_input.disabled = true;
@@ -91,23 +92,23 @@ socket.on('backend_error', function(e) {
9192
fatalError(e.description);
9293
});
9394
socket.on('started', function(msg) {
94-
logAppend("Compiling...", true);
95+
logStatus("Compiling...");
9596
kill_button.disabled = false;
9697
});
9798
socket.on('compiled', function(msg) {
9899
if (msg.ecode == 0) {
99100
if (msg.logs) {
100-
logAppend("Compiled with logs:\n" + msg.logs, false);
101+
logAppend("Compiled with logs:\n" + msg.logs);
101102
} else {
102-
logAppend("Compiled successfully.\n", false);
103+
logAppend("Compiled successfully.\n");
103104
}
104-
logAppend("Executing...", true);
105+
logStatus("Executing...");
105106
} else if (msg.ecode == null) {
106-
logAppend("Compilation failed. Please try again...\n", false);
107+
logAppend("Compilation failed. Please try again...\n");
107108
} else if (msg.logs) {
108-
logAppend("Compiler reported errors:\n" + msg.logs, false);
109+
logAppend("Compiler reported errors:\n" + msg.logs);
109110
} else {
110-
logAppend("Compiler stopped!\n", false);
111+
logAppend("Compiler stopped!\n");
111112
}
112113
stdin_input.disabled = false;
113114
stdin_input.focus();
@@ -126,9 +127,9 @@ socket.on('stdin_ack', function(msg) {
126127
});
127128
socket.on('done', function(msg) {
128129
if (msg.ecode == 0) {
129-
logAppend("Execution completed.\n", false);
130+
logAppend("Execution completed.\n");
130131
} else if (msg.ecode !== null) {
131-
logAppend("Execution stopped. [" + msg.ecode + "]\n", false);
132+
logAppend("Execution stopped. [" + msg.ecode + "]\n");
132133
}
133134
compile_button.disabled = false;
134135
kill_button.disabled = true;
@@ -140,13 +141,13 @@ compile_button.onclick = function(e) {
140141
var source = editor.getValue();
141142
logClear();
142143
outClear();
143-
logAppend("Compilation requested...", true);
144+
logStatus("Compilation requested...");
144145
socket.emit("compile", source);
145146
compile_button.disabled = true;
146147
setSource(source);
147148
}
148149
kill_button.onclick = function(e) {
149-
logAppend("Trying to stop...", true);
150+
logStatus("Trying to stop...");
150151
socket.emit('kill', null);
151152
kill_button.disabled = true;
152153
}

0 commit comments

Comments
 (0)