10 |
11 |
12 | ## About
13 | [**Judge0 IDE**](https://ide.judge0.com) is a free and open-source online code editor that allows you to write and execute code from a rich set of languages. It's perfect for anybody who just wants to quickly write and run some code without opening a full-featured IDE on their computer. Moreover, it is also useful for teaching and learning or just trying out a new language.
14 |
15 | Judge0 IDE is using [**Judge0 API**](https://api.judge0.com) for executing the user's source code.
16 |
17 | Visit https://ide.judge0.com, enjoy and happy coding. :)
18 |
19 | ## Community
20 | Do you have a question, feature request or something else on your mind?
21 | Or you just want to follow Judge0 news?
22 | Check out these links:
23 |
24 | * [Subscribe to Judge0 news](https://judge0.com/#subscribe)
25 | * [Join a Discord server](https://discord.gg/6dvxeA8)
26 | * [Report an issue](https://github.com/judge0/ide/issues/new)
27 | * [Contact the author](https://github.com/hermanzdosilovic)
28 |
29 | ## Author and Contributors
30 | Judge0 IDE was created by [Herman Zvonimir Došilović](https://github.com/hermanzdosilovic).
31 |
32 | Thanks a lot to all [contributors](https://github.com/judge0/ide/graphs/contributors) for their contributions in this project.
33 |
34 | ## Supporters
35 | Thanks a lot to all my [Patrons](https://www.patreon.com/hermanzdosilovic) and [PayPal](https://paypal.me/hermanzdosilovic) donors that helped me keep Judge0 IDE free for everybody around the World. Thank you ♥
36 |
37 | ## Donate
38 | Your are more than welcome to support Judge0 on [Patreon](https://www.patreon.com/hermanzdosilovic) or via [PayPal](https://paypal.me/hermanzdosilovic). Your monthly or one-time donation will help pay server costs and will improve future development and maintenance. Thank you ♥
39 |
40 | ## License
41 | Judge0 IDE is licensed under the [MIT License](https://github.com/judge0/ide/blob/master/LICENSE).
42 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hermanz.dosilovic@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/third_party/download.js:
--------------------------------------------------------------------------------
1 | //download.js v3.0, by dandavis; 2008-2014. [CCBY2] see http://danml.com/download.html for tests/usage
2 | // v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
3 | // v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
4 | // v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support
5 |
6 | // data can be a string, Blob, File, or dataURL
7 |
8 |
9 |
10 |
11 | function download(data, strFileName, strMimeType) {
12 |
13 | var self = window, // this script is only for browsers anyway...
14 | u = "application/octet-stream", // this default mime also triggers iframe downloads
15 | m = strMimeType || u,
16 | x = data,
17 | D = document,
18 | a = D.createElement("a"),
19 | z = function(a){return String(a);},
20 |
21 |
22 | B = self.Blob || self.MozBlob || self.WebKitBlob || z,
23 | BB = self.MSBlobBuilder || self.WebKitBlobBuilder || self.BlobBuilder,
24 | fn = strFileName || "download",
25 | blob,
26 | b,
27 | ua,
28 | fr;
29 |
30 | //if(typeof B.bind === 'function' ){ B=B.bind(self); }
31 |
32 | if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
33 | x=[x, m];
34 | m=x[0];
35 | x=x[1];
36 | }
37 |
38 |
39 |
40 | //go ahead and download dataURLs right away
41 | if(String(x).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/)){
42 | return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
43 | navigator.msSaveBlob(d2b(x), fn) :
44 | saver(x) ; // everyone else can save dataURLs un-processed
45 | }//end if dataURL passed?
46 |
47 | try{
48 |
49 | blob = x instanceof B ?
50 | x :
51 | new B([x], {type: m}) ;
52 | }catch(y){
53 | if(BB){
54 | b = new BB();
55 | b.append([x]);
56 | blob = b.getBlob(m); // the blob
57 | }
58 |
59 | }
60 |
61 |
62 |
63 | function d2b(u) {
64 | var p= u.split(/[:;,]/),
65 | t= p[1],
66 | dec= p[2] == "base64" ? atob : decodeURIComponent,
67 | bin= dec(p.pop()),
68 | mx= bin.length,
69 | i= 0,
70 | uia= new Uint8Array(mx);
71 |
72 | for(i;i${JSON.stringify(jqXHR, null, 4)}`);
192 | }
193 |
194 | function handleRunError(jqXHR, textStatus, errorThrown) {
195 | handleError(jqXHR, textStatus, errorThrown);
196 | $runBtn.removeClass("loading");
197 | }
198 |
199 | function handleResult(data) {
200 | timeEnd = performance.now();
201 | console.log("It took " + (timeEnd - timeStart) + " ms to get submission result.");
202 |
203 | var status = data.status;
204 | var stdout = decode(data.stdout);
205 | var stderr = decode(data.stderr);
206 | var compile_output = decode(data.compile_output);
207 | var sandbox_message = decode(data.message);
208 | var time = (data.time === null ? "-" : data.time + "s");
209 | var memory = (data.memory === null ? "-" : data.memory + "KB");
210 |
211 | $statusLine.html(`${status.description}, ${time}, ${memory}`);
212 |
213 | if (blinkStatusLine) {
214 | $statusLine.addClass("blink");
215 | setTimeout(function() {
216 | blinkStatusLine = false;
217 | localStorageSetItem("blink", "false");
218 | $statusLine.removeClass("blink");
219 | }, 3000);
220 | }
221 |
222 | stdoutEditor.setValue(stdout);
223 | stderrEditor.setValue(stderr);
224 | compileOutputEditor.setValue(compile_output);
225 | sandboxMessageEditor.setValue(sandbox_message);
226 |
227 | if (stdout !== "") {
228 | var dot = document.getElementById("stdout-dot");
229 | if (!dot.parentElement.classList.contains("lm_active")) {
230 | dot.hidden = false;
231 | }
232 | }
233 | if (stderr !== "") {
234 | var dot = document.getElementById("stderr-dot");
235 | if (!dot.parentElement.classList.contains("lm_active")) {
236 | dot.hidden = false;
237 | }
238 | }
239 | if (compile_output !== "") {
240 | var dot = document.getElementById("compile-output-dot");
241 | if (!dot.parentElement.classList.contains("lm_active")) {
242 | dot.hidden = false;
243 | }
244 | }
245 | if (sandbox_message !== "") {
246 | var dot = document.getElementById("sandbox-message-dot");
247 | if (!dot.parentElement.classList.contains("lm_active")) {
248 | dot.hidden = false;
249 | }
250 | }
251 |
252 | $runBtn.removeClass("loading");
253 | }
254 |
255 | function getIdFromURI() {
256 | return location.search.substr(1).trim();
257 | }
258 |
259 | function save() {
260 | var content = JSON.stringify({
261 | source_code: encode(sourceEditor.getValue()),
262 | language_id: $selectLanguage.val(),
263 | compiler_options: $compilerOptions.val(),
264 | command_line_arguments: $commandLineArguments.val(),
265 | stdin: encode(stdinEditor.getValue()),
266 | stdout: encode(stdoutEditor.getValue()),
267 | stderr: encode(stderrEditor.getValue()),
268 | compile_output: encode(compileOutputEditor.getValue()),
269 | sandbox_message: encode(sandboxMessageEditor.getValue()),
270 | status_line: encode($statusLine.html())
271 | });
272 | var filename = "judge0-ide.json";
273 | var data = {
274 | content: content,
275 | filename: filename
276 | };
277 |
278 | $.ajax({
279 | url: pbUrl,
280 | type: "POST",
281 | async: true,
282 | headers: {
283 | "Accept": "application/json"
284 | },
285 | data: data,
286 | success: function (data, textStatus, jqXHR) {
287 | if (getIdFromURI() != data["short"]) {
288 | window.history.replaceState(null, null, location.origin + location.pathname + "?" + data["short"]);
289 | }
290 | },
291 | error: function (jqXHR, textStatus, errorThrown) {
292 | handleError(jqXHR, textStatus, errorThrown);
293 | }
294 | });
295 | }
296 |
297 | function downloadSource() {
298 | var value = parseInt($selectLanguage.val());
299 | download(sourceEditor.getValue(), fileNames[value], "text/plain");
300 | }
301 |
302 | function loadSavedSource() {
303 | snippet_id = getIdFromURI();
304 |
305 | if (snippet_id.length == 36) {
306 | $.ajax({
307 | url: apiUrl + "/submissions/" + snippet_id + "?fields=source_code,language_id,stdin,stdout,stderr,compile_output,message,time,memory,status,compiler_options,command_line_arguments&base64_encoded=true",
308 | type: "GET",
309 | success: function(data, textStatus, jqXHR) {
310 | sourceEditor.setValue(decode(data["source_code"]));
311 | $selectLanguage.dropdown("set selected", data["language_id"]);
312 | $compilerOptions.val(data["compiler_options"]);
313 | $commandLineArguments.val(data["command_line_arguments"]);
314 | stdinEditor.setValue(decode(data["stdin"]));
315 | stdoutEditor.setValue(decode(data["stdout"]));
316 | stderrEditor.setValue(decode(data["stderr"]));
317 | compileOutputEditor.setValue(decode(data["compile_output"]));
318 | sandboxMessageEditor.setValue(decode(data["message"]));
319 | var time = (data.time === null ? "-" : data.time + "s");
320 | var memory = (data.memory === null ? "-" : data.memory + "KB");
321 | $statusLine.html(`${data.status.description}, ${time}, ${memory}`);
322 | changeEditorLanguage();
323 | },
324 | error: handleRunError
325 | });
326 | } else if (snippet_id.length == 4) {
327 | $.ajax({
328 | url: pbUrl + "/" + snippet_id + ".json",
329 | type: "GET",
330 | success: function (data, textStatus, jqXHR) {
331 | sourceEditor.setValue(decode(data["source_code"]));
332 | $selectLanguage.dropdown("set selected", data["language_id"]);
333 | $compilerOptions.val(data["compiler_options"]);
334 | $commandLineArguments.val(data["command_line_arguments"]);
335 | stdinEditor.setValue(decode(data["stdin"]));
336 | stdoutEditor.setValue(decode(data["stdout"]));
337 | stderrEditor.setValue(decode(data["stderr"]));
338 | compileOutputEditor.setValue(decode(data["compile_output"]));
339 | sandboxMessageEditor.setValue(decode(data["sandbox_message"]));
340 | $statusLine.html(decode(data["status_line"]));
341 | changeEditorLanguage();
342 | },
343 | error: function (jqXHR, textStatus, errorThrown) {
344 | showError("Not Found", "Code not found!");
345 | window.history.replaceState(null, null, location.origin + location.pathname);
346 | loadRandomLanguage();
347 | }
348 | });
349 | }
350 | }
351 |
352 | function run() {
353 | if (sourceEditor.getValue().trim() === "") {
354 | showError("Error", "Source code can't be empty!");
355 | return;
356 | } else {
357 | $runBtn.addClass("loading");
358 | }
359 |
360 | document.getElementById("stdout-dot").hidden = true;
361 | document.getElementById("stderr-dot").hidden = true;
362 | document.getElementById("compile-output-dot").hidden = true;
363 | document.getElementById("sandbox-message-dot").hidden = true;
364 |
365 | stdoutEditor.setValue("");
366 | stderrEditor.setValue("");
367 | compileOutputEditor.setValue("");
368 | sandboxMessageEditor.setValue("");
369 |
370 | var sourceValue = encode(sourceEditor.getValue());
371 | var stdinValue = encode(stdinEditor.getValue());
372 | var languageId = resolveLanguageId($selectLanguage.val());
373 | var compilerOptions = $compilerOptions.val();
374 | var commandLineArguments = $commandLineArguments.val();
375 |
376 | if (parseInt(languageId) === 44) {
377 | sourceValue = sourceEditor.getValue();
378 | }
379 |
380 | var data = {
381 | source_code: sourceValue,
382 | language_id: languageId,
383 | stdin: stdinValue,
384 | compiler_options: compilerOptions,
385 | command_line_arguments: commandLineArguments
386 | };
387 |
388 | timeStart = performance.now();
389 | $.ajax({
390 | url: apiUrl + `/submissions?base64_encoded=true&wait=${wait}`,
391 | type: "POST",
392 | async: true,
393 | contentType: "application/json",
394 | data: JSON.stringify(data),
395 | success: function (data, textStatus, jqXHR) {
396 | console.log(`Your submission token is: ${data.token}`);
397 | if (wait == true) {
398 | handleResult(data);
399 | } else {
400 | setTimeout(fetchSubmission.bind(null, data.token), check_timeout);
401 | }
402 | },
403 | error: handleRunError
404 | });
405 | }
406 |
407 | function fetchSubmission(submission_token) {
408 | $.ajax({
409 | url: apiUrl + "/submissions/" + submission_token + "?base64_encoded=true",
410 | type: "GET",
411 | async: true,
412 | success: function (data, textStatus, jqXHR) {
413 | if (data.status.id <= 2) { // In Queue or Processing
414 | setTimeout(fetchSubmission.bind(null, submission_token), check_timeout);
415 | return;
416 | }
417 | handleResult(data);
418 | },
419 | error: handleRunError
420 | });
421 | }
422 |
423 | function changeEditorLanguage() {
424 | monaco.editor.setModelLanguage(sourceEditor.getModel(), $selectLanguage.find(":selected").attr("mode"));
425 | currentLanguageId = parseInt($selectLanguage.val());
426 | $(".lm_title")[0].innerText = fileNames[currentLanguageId];
427 | apiUrl = resolveApiUrl($selectLanguage.val());
428 | showApiUrl();
429 | }
430 |
431 | function insertTemplate() {
432 | currentLanguageId = parseInt($selectLanguage.val());
433 | sourceEditor.setValue(sources[currentLanguageId]);
434 | changeEditorLanguage();
435 | }
436 |
437 | function loadRandomLanguage() {
438 | var values = [];
439 | for (var i = 0; i < $selectLanguage[0].options.length; ++i) {
440 | values.push($selectLanguage[0].options[i].value);
441 | }
442 | $selectLanguage.dropdown("set selected", values[Math.floor(Math.random() * $selectLanguage[0].length)]);
443 | apiUrl = resolveApiUrl($selectLanguage.val());
444 | showApiUrl();
445 | insertTemplate();
446 | }
447 |
448 | function resizeEditor(layoutInfo) {
449 | if (editorMode != "normal") {
450 | var statusLineHeight = $("#editor-status-line").height();
451 | layoutInfo.height -= statusLineHeight;
452 | layoutInfo.contentHeight -= statusLineHeight;
453 | }
454 | }
455 |
456 | function disposeEditorModeObject() {
457 | try {
458 | editorModeObject.dispose();
459 | editorModeObject = null;
460 | } catch(ignorable) {
461 | }
462 | }
463 |
464 | function changeEditorMode() {
465 | disposeEditorModeObject();
466 |
467 | if (editorMode == "vim") {
468 | editorModeObject = MonacoVim.initVimMode(sourceEditor, $("#editor-status-line")[0]);
469 | } else if (editorMode == "emacs") {
470 | var statusNode = $("#editor-status-line")[0];
471 | editorModeObject = new MonacoEmacs.EmacsExtension(sourceEditor);
472 | editorModeObject.onDidMarkChange(function(e) {
473 | statusNode.textContent = e ? "Mark Set!" : "Mark Unset";
474 | });
475 | editorModeObject.onDidChangeKey(function(str) {
476 | statusNode.textContent = str;
477 | });
478 | editorModeObject.start();
479 | }
480 | }
481 |
482 | function resolveLanguageId(id) {
483 | id = parseInt(id);
484 | return languageIdTable[id] || id;
485 | }
486 |
487 | function resolveApiUrl(id) {
488 | id = parseInt(id);
489 | return languageApiUrlTable[id] || defaultUrl;
490 | }
491 |
492 | function editorsUpdateFontSize(fontSize) {
493 | sourceEditor.updateOptions({fontSize: fontSize});
494 | stdinEditor.updateOptions({fontSize: fontSize});
495 | stdoutEditor.updateOptions({fontSize: fontSize});
496 | stderrEditor.updateOptions({fontSize: fontSize});
497 | compileOutputEditor.updateOptions({fontSize: fontSize});
498 | sandboxMessageEditor.updateOptions({fontSize: fontSize});
499 | }
500 |
501 | $(window).resize(function() {
502 | layout.updateSize();
503 | showMessages();
504 | });
505 |
506 | $(document).ready(function () {
507 | console.log("Hey, Judge0 IDE is open-sourced: https://github.com/judge0/ide. Have fun!");
508 |
509 | $selectLanguage = $("#select-language");
510 | $selectLanguage.change(function (e) {
511 | if (!isEditorDirty) {
512 | insertTemplate();
513 | } else {
514 | changeEditorLanguage();
515 | }
516 | });
517 |
518 | $compilerOptions = $("#compiler-options");
519 | $commandLineArguments = $("#command-line-arguments");
520 | $commandLineArguments.attr("size", $commandLineArguments.attr("placeholder").length);
521 |
522 | $insertTemplateBtn = $("#insert-template-btn");
523 | $insertTemplateBtn.click(function (e) {
524 | if (isEditorDirty && confirm("Are you sure? Your current changes will be lost.")) {
525 | insertTemplate();
526 | }
527 | });
528 |
529 | $runBtn = $("#run-btn");
530 | $runBtn.click(function (e) {
531 | run();
532 | });
533 |
534 | $navigationMessage = $("#navigation-message span");
535 | $about = $("#about");
536 |
537 | $(`input[name="editor-mode"][value="${editorMode}"]`).prop("checked", true);
538 | $("input[name=\"editor-mode\"]").on("change", function(e) {
539 | $('#site-settings').modal('hide');
540 |
541 | editorMode = e.target.value;
542 | localStorageSetItem("editorMode", editorMode);
543 |
544 | resizeEditor(sourceEditor.getLayoutInfo());
545 | changeEditorMode();
546 |
547 | sourceEditor.focus();
548 | });
549 |
550 | $statusLine = $("#status-line");
551 |
552 | $("body").keydown(function (e) {
553 | var keyCode = e.keyCode || e.which;
554 | if (keyCode == 120) { // F9
555 | e.preventDefault();
556 | run();
557 | } else if (keyCode == 119) { // F8
558 | e.preventDefault();
559 | var url = prompt("Enter URL of Judge0 API:", apiUrl);
560 | if (url != null) {
561 | url = url.trim();
562 | }
563 | if (url != null && url != "") {
564 | apiUrl = url;
565 | localStorageSetItem("api-url", apiUrl);
566 | showApiUrl();
567 | }
568 | } else if (keyCode == 118) { // F7
569 | e.preventDefault();
570 | wait = !wait;
571 | localStorageSetItem("wait", wait);
572 | alert(`Submission wait is ${wait ? "ON. Enjoy" : "OFF"}.`);
573 | } else if (event.ctrlKey && keyCode == 83) { // Ctrl+S
574 | e.preventDefault();
575 | save();
576 | } else if (event.ctrlKey && keyCode == 107) { // Ctrl++
577 | e.preventDefault();
578 | fontSize += 1;
579 | editorsUpdateFontSize(fontSize);
580 | } else if (event.ctrlKey && keyCode == 109) { // Ctrl+-
581 | e.preventDefault();
582 | fontSize -= 1;
583 | editorsUpdateFontSize(fontSize);
584 | }
585 | });
586 |
587 | $("select.dropdown").dropdown();
588 | $(".ui.dropdown").dropdown();
589 | $(".ui.dropdown.site-links").dropdown({action: "hide", on: "hover"});
590 | $(".ui.checkbox").checkbox();
591 | $(".message .close").on("click", function () {
592 | $(this).closest(".message").transition("fade");
593 | });
594 |
595 | showApiUrl();
596 | loadMessages();
597 |
598 | require(["vs/editor/editor.main", "monaco-vim", "monaco-emacs"], function (ignorable, MVim, MEmacs) {
599 | layout = new GoldenLayout(layoutConfig, $("#site-content"));
600 |
601 | MonacoVim = MVim;
602 | MonacoEmacs = MEmacs;
603 |
604 | layout.registerComponent("source", function (container, state) {
605 | sourceEditor = monaco.editor.create(container.getElement()[0], {
606 | automaticLayout: true,
607 | theme: "vs-dark",
608 | scrollBeyondLastLine: true,
609 | readOnly: state.readOnly,
610 | language: "cpp",
611 | minimap: {
612 | enabled: false
613 | },
614 | rulers: [80, 120]
615 | });
616 |
617 | changeEditorMode();
618 |
619 | sourceEditor.getModel().onDidChangeContent(function (e) {
620 | currentLanguageId = parseInt($selectLanguage.val());
621 | isEditorDirty = sourceEditor.getValue() != sources[currentLanguageId];
622 | });
623 |
624 | sourceEditor.onDidLayoutChange(resizeEditor);
625 | });
626 |
627 | layout.registerComponent("stdin", function (container, state) {
628 | stdinEditor = monaco.editor.create(container.getElement()[0], {
629 | automaticLayout: true,
630 | theme: "vs-dark",
631 | scrollBeyondLastLine: false,
632 | readOnly: state.readOnly,
633 | language: "plaintext",
634 | minimap: {
635 | enabled: false
636 | }
637 | });
638 | });
639 |
640 | layout.registerComponent("stdout", function (container, state) {
641 | stdoutEditor = monaco.editor.create(container.getElement()[0], {
642 | automaticLayout: true,
643 | theme: "vs-dark",
644 | scrollBeyondLastLine: false,
645 | readOnly: state.readOnly,
646 | language: "plaintext",
647 | minimap: {
648 | enabled: false
649 | }
650 | });
651 |
652 | container.on("tab", function(tab) {
653 | tab.element.append("");
654 | tab.element.on("mousedown", function(e) {
655 | e.target.closest(".lm_tab").children[3].hidden = true;
656 | });
657 | });
658 | });
659 |
660 | layout.registerComponent("stderr", function (container, state) {
661 | stderrEditor = monaco.editor.create(container.getElement()[0], {
662 | automaticLayout: true,
663 | theme: "vs-dark",
664 | scrollBeyondLastLine: false,
665 | readOnly: state.readOnly,
666 | language: "plaintext",
667 | minimap: {
668 | enabled: false
669 | }
670 | });
671 |
672 | container.on("tab", function(tab) {
673 | tab.element.append("");
674 | tab.element.on("mousedown", function(e) {
675 | e.target.closest(".lm_tab").children[3].hidden = true;
676 | });
677 | });
678 | });
679 |
680 | layout.registerComponent("compile output", function (container, state) {
681 | compileOutputEditor = monaco.editor.create(container.getElement()[0], {
682 | automaticLayout: true,
683 | theme: "vs-dark",
684 | scrollBeyondLastLine: false,
685 | readOnly: state.readOnly,
686 | language: "plaintext",
687 | minimap: {
688 | enabled: false
689 | }
690 | });
691 |
692 | container.on("tab", function(tab) {
693 | tab.element.append("");
694 | tab.element.on("mousedown", function(e) {
695 | e.target.closest(".lm_tab").children[3].hidden = true;
696 | });
697 | });
698 | });
699 |
700 | layout.registerComponent("sandbox message", function (container, state) {
701 | sandboxMessageEditor = monaco.editor.create(container.getElement()[0], {
702 | automaticLayout: true,
703 | theme: "vs-dark",
704 | scrollBeyondLastLine: false,
705 | readOnly: state.readOnly,
706 | language: "plaintext",
707 | minimap: {
708 | enabled: false
709 | }
710 | });
711 |
712 | container.on("tab", function(tab) {
713 | tab.element.append("");
714 | tab.element.on("mousedown", function(e) {
715 | e.target.closest(".lm_tab").children[3].hidden = true;
716 | });
717 | });
718 | });
719 |
720 | layout.on("initialised", function () {
721 | $(".monaco-editor")[0].appendChild($("#editor-status-line")[0]);
722 | if (getIdFromURI()) {
723 | loadSavedSource();
724 | } else {
725 | loadRandomLanguage();
726 | }
727 | $("#site-navigation").css("border-bottom", "1px solid black");
728 | sourceEditor.focus();
729 | });
730 |
731 | layout.init();
732 | });
733 | });
734 |
735 | // Template Sources
736 | var assemblySource = "\
737 | section .text\n\
738 | global _start\n\
739 | \n\
740 | _start:\n\
741 | \n\
742 | xor eax, eax\n\
743 | lea edx, [rax+len]\n\
744 | mov al, 1\n\
745 | mov esi, msg\n\
746 | mov edi, eax\n\
747 | syscall\n\
748 | \n\
749 | xor edi, edi\n\
750 | lea eax, [rdi+60]\n\
751 | syscall\n\
752 | \n\
753 | section .rodata\n\
754 | \n\
755 | msg db 'hello, world', 0xa\n\
756 | len equ $ - msg\n\
757 | ";
758 |
759 | var bashSource = "echo \"hello, world\"";
760 |
761 | var basicSource = "PRINT \"hello, world\"";
762 |
763 | var cSource = "\
764 | #include