diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..dde8d1a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: hermanzdosilovic diff --git a/.github/screenshot.png b/.github/screenshot.png new file mode 100644 index 0000000..80cb233 Binary files /dev/null and b/.github/screenshot.png differ diff --git a/.github/wallpaper.png b/.github/wallpaper.png new file mode 100644 index 0000000..416eaa2 Binary files /dev/null and b/.github/wallpaper.png differ diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..be8b8a4 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +ide.judge0.com \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..333d855 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +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. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +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. + +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. + +## Scope + +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. + +## Enforcement + +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. + +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. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..16fb28c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Herman Zvonimir Došilović + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/css/ide.css b/css/ide.css new file mode 100644 index 0000000..0213ec5 --- /dev/null +++ b/css/ide.css @@ -0,0 +1,193 @@ +html, body { + height: 100%; + min-height: 100%; + margin: 0; + padding: 0; +} + +body { + background: url(/images/judge0_background.png) no-repeat center center fixed; + -webkit-background-size: cover; + -moz-background-size: cover; + -o-background-size: cover; + background-size: cover; +} + +.ui[class*="left action"].input>.dropdown { + border-radius: 0 .28571429rem .28571429rem 0; +} + +.ui.selection.dropdown { + width: 205px; +} + +.lm_header .lm_tab { + padding-bottom: 3px; + height: 16px; + font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; + font-size: 14px; +} + +.lm_header .lm_tab.lm_active { + box-shadow: none; + padding-bottom: 3px; +} + +#site-navigation { + border-radius: 0; + margin: 0; + background: #1e1e1e; + border-bottom: 1px solid rgba(255, 255, 255, 0.08); + height: 45px; +} + +#navigation-message { + font-size: 1.2em; + white-space: nowrap; + overflow: hidden; +} + +@keyframes slide { + 0% { transform: translateX(570px); } + 100% { transform: translateX(-100%); } +} +@-webkit-keyframes slide { + 0% { transform: translateX(570px); } + 100% { transform: translateX(-100%); } +} + +.navigation-message-text { + white-space: nowrap; + -moz-animation: slide 60s linear infinite; + -webkit-animation: slide 60s linear infinite; + animation: slide 60s linear infinite; +} + +.navigation-message-text:hover { + -moz-animation-play-state: paused; + -webkit-animation-play-state: paused; + animation-play-state: paused; +} + +#navigation-message a { + color: #41a5f1; + font-weight: bold; +} + +#site-icon { + width: 30px; + height: 30px; + vertical-align: middle; +} + +#site-header { + padding-left: 0; + padding-top: 0; + padding-bottom: 0; +} + +#site-header h2 { + display: inline; + vertical-align: middle; + font-family: 'Exo 2', sans-serif; +} + +#site-content { + height: calc(100% - 45px - 19px); +} + +#site-modal .header { + color: #db2828; +} + +#site-footer, #status-line, #donate-line { + background-color: #0E6EB8; + bottom: 0; + font-family: "Droid Sans Mono", monospace, monospace, "Droid Sans Fallback"; + font-size: 13px; + height: 19px; + padding-left: 16px; + padding-right: 16px; + position: fixed; +} + +#site-footer { + color: #41a5f1; + left: 0; + text-align: center; + width: 100%; +} + +#site-footer a { + color: #41a5f1; + font-weight: bold; +} + +#site-footer a:hover { + color: #a0d2f8; +} + +#donate-line { + float: left; + left: 0; + text-align: left; + width: fit-content; +} + +#status-line { + color: #fff; + float: right; + right: 0; + text-align: right; + width: fit-content; +} + +#editor-status-line { + background: transparent; + color: #fff; + font-family: monospace; + height: 19px; + padding: 0px 16px; + width: inherit; +} + +#editor-status-line input[type=text] { + background: transparent; + border: none; + color: #fff; + font-family: monospace; + outline: none; +} + +#editor-status-line input[type=text]::selection { + background-color: #cce2ff; + color: #fff; +} + +.blink { + animation: blinker 1s linear infinite; +} + +@keyframes blinker { + 50% { + background: #FFD700; + } +} + +.dot { + background: #0E6EB8; + position: absolute; + border-radius: 50px; + width: 5px; + height: 5px; + right: 7.5px; + top: 7.5px; +} + +.no-left-padding { + padding-left: 0 !important; +} + +input[type="text"] { + width: 205px !important; +} \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..457b274 Binary files /dev/null and b/favicon.ico differ diff --git a/images/judge0_background.png b/images/judge0_background.png new file mode 100644 index 0000000..0996e7a Binary files /dev/null and b/images/judge0_background.png differ diff --git a/images/judge0_icon.png b/images/judge0_icon.png new file mode 100644 index 0000000..f1073fa Binary files /dev/null and b/images/judge0_icon.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..5938f8a --- /dev/null +++ b/index.html @@ -0,0 +1,303 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +${JSON.stringify(jqXHR, null, 4)}`); +} + +function handleRunError(jqXHR, textStatus, errorThrown) { + handleError(jqXHR, textStatus, errorThrown); + $runBtn.removeClass("loading"); +} + +function handleResult(data) { + timeEnd = performance.now(); + console.log("It took " + (timeEnd - timeStart) + " ms to get submission result."); + + var status = data.status; + var stdout = decode(data.stdout); + var stderr = decode(data.stderr); + var compile_output = decode(data.compile_output); + var sandbox_message = decode(data.message); + var time = (data.time === null ? "-" : data.time + "s"); + var memory = (data.memory === null ? "-" : data.memory + "KB"); + + $statusLine.html(`${status.description}, ${time}, ${memory}`); + + if (blinkStatusLine) { + $statusLine.addClass("blink"); + setTimeout(function() { + blinkStatusLine = false; + localStorageSetItem("blink", "false"); + $statusLine.removeClass("blink"); + }, 3000); + } + + stdoutEditor.setValue(stdout); + stderrEditor.setValue(stderr); + compileOutputEditor.setValue(compile_output); + sandboxMessageEditor.setValue(sandbox_message); + + if (stdout !== "") { + var dot = document.getElementById("stdout-dot"); + if (!dot.parentElement.classList.contains("lm_active")) { + dot.hidden = false; + } + } + if (stderr !== "") { + var dot = document.getElementById("stderr-dot"); + if (!dot.parentElement.classList.contains("lm_active")) { + dot.hidden = false; + } + } + if (compile_output !== "") { + var dot = document.getElementById("compile-output-dot"); + if (!dot.parentElement.classList.contains("lm_active")) { + dot.hidden = false; + } + } + if (sandbox_message !== "") { + var dot = document.getElementById("sandbox-message-dot"); + if (!dot.parentElement.classList.contains("lm_active")) { + dot.hidden = false; + } + } + + $runBtn.removeClass("loading"); +} + +function getIdFromURI() { + var uri = location.search.substr(1).trim(); + return uri.split("&")[0]; +} + +function save() { + var content = JSON.stringify({ + source_code: encode(sourceEditor.getValue()), + language_id: $selectLanguage.val(), + compiler_options: $compilerOptions.val(), + command_line_arguments: $commandLineArguments.val(), + stdin: encode(stdinEditor.getValue()), + stdout: encode(stdoutEditor.getValue()), + stderr: encode(stderrEditor.getValue()), + compile_output: encode(compileOutputEditor.getValue()), + sandbox_message: encode(sandboxMessageEditor.getValue()), + status_line: encode($statusLine.html()) + }); + var filename = "judge0-ide.json"; + var data = { + content: content, + filename: filename + }; + + $.ajax({ + url: pbUrl, + type: "POST", + async: true, + headers: { + "Accept": "application/json" + }, + data: data, + xhrFields: { + withCredentials: true + }, + success: function (data, textStatus, jqXHR) { + if (getIdFromURI() != data["short"]) { + window.history.replaceState(null, null, location.origin + location.pathname + "?" + data["short"]); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + handleError(jqXHR, textStatus, errorThrown); + } + }); +} + +function downloadSource() { + var value = parseInt($selectLanguage.val()); + download(sourceEditor.getValue(), fileNames[value], "text/plain"); +} + +function loadSavedSource() { + snippet_id = getIdFromURI(); + + if (snippet_id.length == 36) { + $.ajax({ + 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", + type: "GET", + success: function(data, textStatus, jqXHR) { + sourceEditor.setValue(decode(data["source_code"])); + $selectLanguage.dropdown("set selected", data["language_id"]); + $compilerOptions.val(data["compiler_options"]); + $commandLineArguments.val(data["command_line_arguments"]); + stdinEditor.setValue(decode(data["stdin"])); + stdoutEditor.setValue(decode(data["stdout"])); + stderrEditor.setValue(decode(data["stderr"])); + compileOutputEditor.setValue(decode(data["compile_output"])); + sandboxMessageEditor.setValue(decode(data["message"])); + var time = (data.time === null ? "-" : data.time + "s"); + var memory = (data.memory === null ? "-" : data.memory + "KB"); + $statusLine.html(`${data.status.description}, ${time}, ${memory}`); + changeEditorLanguage(); + }, + error: handleRunError + }); + } else if (snippet_id.length == 4) { + $.ajax({ + url: pbUrl + "/" + snippet_id + ".json", + type: "GET", + success: function (data, textStatus, jqXHR) { + sourceEditor.setValue(decode(data["source_code"])); + $selectLanguage.dropdown("set selected", data["language_id"]); + $compilerOptions.val(data["compiler_options"]); + $commandLineArguments.val(data["command_line_arguments"]); + stdinEditor.setValue(decode(data["stdin"])); + stdoutEditor.setValue(decode(data["stdout"])); + stderrEditor.setValue(decode(data["stderr"])); + compileOutputEditor.setValue(decode(data["compile_output"])); + sandboxMessageEditor.setValue(decode(data["sandbox_message"])); + $statusLine.html(decode(data["status_line"])); + changeEditorLanguage(); + }, + error: function (jqXHR, textStatus, errorThrown) { + showError("Not Found", "Code not found!"); + window.history.replaceState(null, null, location.origin + location.pathname); + loadRandomLanguage(); + } + }); + } else { + loadRandomLanguage(); + } +} + +function run() { + if (sourceEditor.getValue().trim() === "") { + showError("Error", "Source code can't be empty!"); + return; + } else { + $runBtn.addClass("loading"); + } + + document.getElementById("stdout-dot").hidden = true; + document.getElementById("stderr-dot").hidden = true; + document.getElementById("compile-output-dot").hidden = true; + document.getElementById("sandbox-message-dot").hidden = true; + + stdoutEditor.setValue(""); + stderrEditor.setValue(""); + compileOutputEditor.setValue(""); + sandboxMessageEditor.setValue(""); + + var sourceValue = encode(sourceEditor.getValue()); + var stdinValue = encode(stdinEditor.getValue()); + var languageId = resolveLanguageId($selectLanguage.val()); + var compilerOptions = $compilerOptions.val(); + var commandLineArguments = $commandLineArguments.val(); + + if (parseInt(languageId) === 44) { + sourceValue = sourceEditor.getValue(); + } + + var data = { + source_code: sourceValue, + language_id: languageId, + stdin: stdinValue, + compiler_options: compilerOptions, + command_line_arguments: commandLineArguments, + redirect_stderr_to_stdout: redirectStderrToStdout + }; + + var sendRequest = function(data) { + timeStart = performance.now(); + $.ajax({ + url: apiUrl + `/submissions?base64_encoded=true&wait=${wait}`, + type: "POST", + async: true, + contentType: "application/json", + data: JSON.stringify(data), + xhrFields: { + withCredentials: apiUrl.indexOf("/secure") != -1 ? true : false + }, + success: function (data, textStatus, jqXHR) { + console.log(`Your submission token is: ${data.token}`); + if (wait == true) { + handleResult(data); + } else { + setTimeout(fetchSubmission.bind(null, data.token), check_timeout); + } + }, + error: handleRunError + }); + } + + var fetchAdditionalFiles = false; + if (parseInt(languageId) === 82) { + if (sqliteAdditionalFiles === "") { + fetchAdditionalFiles = true; + $.ajax({ + url: `https://minio.judge0.com/public/ide/sqliteAdditionalFiles.base64.txt?${Date.now()}`, + type: "GET", + async: true, + contentType: "text/plain", + success: function (responseData, textStatus, jqXHR) { + sqliteAdditionalFiles = responseData; + data["additional_files"] = sqliteAdditionalFiles; + sendRequest(data); + }, + error: handleRunError + }); + } + else { + data["additional_files"] = sqliteAdditionalFiles; + } + } + + if (!fetchAdditionalFiles) { + sendRequest(data); + } +} + +function fetchSubmission(submission_token) { + $.ajax({ + url: apiUrl + "/submissions/" + submission_token + "?base64_encoded=true", + type: "GET", + async: true, + success: function (data, textStatus, jqXHR) { + if (data.status.id <= 2) { // In Queue or Processing + setTimeout(fetchSubmission.bind(null, submission_token), check_timeout); + return; + } + handleResult(data); + }, + error: handleRunError + }); +} + +function changeEditorLanguage() { + monaco.editor.setModelLanguage(sourceEditor.getModel(), $selectLanguage.find(":selected").attr("mode")); + currentLanguageId = parseInt($selectLanguage.val()); + $(".lm_title")[0].innerText = fileNames[currentLanguageId]; + apiUrl = resolveApiUrl($selectLanguage.val()); +} + +function insertTemplate() { + currentLanguageId = parseInt($selectLanguage.val()); + sourceEditor.setValue(sources[currentLanguageId]); + changeEditorLanguage(); +} + +function loadRandomLanguage() { + var values = []; + for (var i = 0; i < $selectLanguage[0].options.length; ++i) { + values.push($selectLanguage[0].options[i].value); + } + $selectLanguage.dropdown("set selected", values[Math.floor(Math.random() * $selectLanguage[0].length)]); + apiUrl = resolveApiUrl($selectLanguage.val()); + insertTemplate(); +} + +function resizeEditor(layoutInfo) { + if (editorMode != "normal") { + var statusLineHeight = $("#editor-status-line").height(); + layoutInfo.height -= statusLineHeight; + layoutInfo.contentHeight -= statusLineHeight; + } +} + +function disposeEditorModeObject() { + try { + editorModeObject.dispose(); + editorModeObject = null; + } catch(ignorable) { + } +} + +function changeEditorMode() { + disposeEditorModeObject(); + + if (editorMode == "vim") { + editorModeObject = MonacoVim.initVimMode(sourceEditor, $("#editor-status-line")[0]); + } else if (editorMode == "emacs") { + var statusNode = $("#editor-status-line")[0]; + editorModeObject = new MonacoEmacs.EmacsExtension(sourceEditor); + editorModeObject.onDidMarkChange(function(e) { + statusNode.textContent = e ? "Mark Set!" : "Mark Unset"; + }); + editorModeObject.onDidChangeKey(function(str) { + statusNode.textContent = str; + }); + editorModeObject.start(); + } +} + +function resolveLanguageId(id) { + id = parseInt(id); + return languageIdTable[id] || id; +} + +function resolveApiUrl(id) { + id = parseInt(id); + return languageApiUrlTable[id] || defaultUrl; +} + +function editorsUpdateFontSize(fontSize) { + sourceEditor.updateOptions({fontSize: fontSize}); + stdinEditor.updateOptions({fontSize: fontSize}); + stdoutEditor.updateOptions({fontSize: fontSize}); + stderrEditor.updateOptions({fontSize: fontSize}); + compileOutputEditor.updateOptions({fontSize: fontSize}); + sandboxMessageEditor.updateOptions({fontSize: fontSize}); +} + +function updateScreenElements() { + var display = window.innerWidth <= 1200 ? "none" : ""; + $(".wide.screen.only").each(function(index) { + $(this).css("display", display); + }); +} + +$(window).resize(function() { + layout.updateSize(); + updateScreenElements(); + showMessages(); +}); + +$(document).ready(function () { + updateScreenElements(); + + console.log("Hey, Judge0 IDE is open-sourced: https://github.com/judge0/ide. Have fun!"); + + $selectLanguage = $("#select-language"); + $selectLanguage.change(function (e) { + if (!isEditorDirty) { + insertTemplate(); + } else { + changeEditorLanguage(); + } + }); + + $compilerOptions = $("#compiler-options"); + $commandLineArguments = $("#command-line-arguments"); + $commandLineArguments.attr("size", $commandLineArguments.attr("placeholder").length); + + $insertTemplateBtn = $("#insert-template-btn"); + $insertTemplateBtn.click(function (e) { + if (isEditorDirty && confirm("Are you sure? Your current changes will be lost.")) { + insertTemplate(); + } + }); + + $runBtn = $("#run-btn"); + $runBtn.click(function (e) { + run(); + }); + + $navigationMessage = $("#navigation-message span"); + $updates = $("#updates"); + + $(`input[name="editor-mode"][value="${editorMode}"]`).prop("checked", true); + $("input[name=\"editor-mode\"]").on("change", function(e) { + editorMode = e.target.value; + localStorageSetItem("editorMode", editorMode); + + resizeEditor(sourceEditor.getLayoutInfo()); + changeEditorMode(); + + sourceEditor.focus(); + }); + + $("input[name=\"redirect-output\"]").prop("checked", redirectStderrToStdout) + $("input[name=\"redirect-output\"]").on("change", function(e) { + redirectStderrToStdout = e.target.checked; + localStorageSetItem("redirectStderrToStdout", redirectStderrToStdout); + }); + + $statusLine = $("#status-line"); + + $("body").keydown(function (e) { + var keyCode = e.keyCode || e.which; + if (keyCode == 120) { // F9 + e.preventDefault(); + run(); + } else if (keyCode == 119) { // F8 + e.preventDefault(); + var url = prompt("Enter URL of Judge0 API:", apiUrl); + if (url != null) { + url = url.trim(); + } + if (url != null && url != "") { + apiUrl = url; + localStorageSetItem("api-url", apiUrl); + } + } else if (keyCode == 118) { // F7 + e.preventDefault(); + wait = !wait; + localStorageSetItem("wait", wait); + alert(`Submission wait is ${wait ? "ON. Enjoy" : "OFF"}.`); + } else if (event.ctrlKey && keyCode == 83) { // Ctrl+S + e.preventDefault(); + save(); + } else if (event.ctrlKey && keyCode == 107) { // Ctrl++ + e.preventDefault(); + fontSize += 1; + editorsUpdateFontSize(fontSize); + } else if (event.ctrlKey && keyCode == 109) { // Ctrl+- + e.preventDefault(); + fontSize -= 1; + editorsUpdateFontSize(fontSize); + } + }); + + $("select.dropdown").dropdown(); + $(".ui.dropdown").dropdown(); + $(".ui.dropdown.site-links").dropdown({action: "hide", on: "hover"}); + $(".ui.checkbox").checkbox(); + $(".message .close").on("click", function () { + $(this).closest(".message").transition("fade"); + }); + + loadMessages(); + + require(["vs/editor/editor.main", "monaco-vim", "monaco-emacs"], function (ignorable, MVim, MEmacs) { + layout = new GoldenLayout(layoutConfig, $("#site-content")); + + MonacoVim = MVim; + MonacoEmacs = MEmacs; + + layout.registerComponent("source", function (container, state) { + sourceEditor = monaco.editor.create(container.getElement()[0], { + automaticLayout: true, + theme: "vs-dark", + scrollBeyondLastLine: true, + readOnly: state.readOnly, + language: "cpp", + minimap: { + enabled: false + }, + rulers: [80, 120] + }); + + changeEditorMode(); + + sourceEditor.getModel().onDidChangeContent(function (e) { + currentLanguageId = parseInt($selectLanguage.val()); + isEditorDirty = sourceEditor.getValue() != sources[currentLanguageId]; + }); + + sourceEditor.onDidLayoutChange(resizeEditor); + }); + + layout.registerComponent("stdin", function (container, state) { + stdinEditor = monaco.editor.create(container.getElement()[0], { + automaticLayout: true, + theme: "vs-dark", + scrollBeyondLastLine: false, + readOnly: state.readOnly, + language: "plaintext", + minimap: { + enabled: false + } + }); + }); + + layout.registerComponent("stdout", function (container, state) { + stdoutEditor = monaco.editor.create(container.getElement()[0], { + automaticLayout: true, + theme: "vs-dark", + scrollBeyondLastLine: false, + readOnly: state.readOnly, + language: "plaintext", + minimap: { + enabled: false + } + }); + + container.on("tab", function(tab) { + tab.element.append(""); + tab.element.on("mousedown", function(e) { + e.target.closest(".lm_tab").children[3].hidden = true; + }); + }); + }); + + layout.registerComponent("stderr", function (container, state) { + stderrEditor = monaco.editor.create(container.getElement()[0], { + automaticLayout: true, + theme: "vs-dark", + scrollBeyondLastLine: false, + readOnly: state.readOnly, + language: "plaintext", + minimap: { + enabled: false + } + }); + + container.on("tab", function(tab) { + tab.element.append(""); + tab.element.on("mousedown", function(e) { + e.target.closest(".lm_tab").children[3].hidden = true; + }); + }); + }); + + layout.registerComponent("compile output", function (container, state) { + compileOutputEditor = monaco.editor.create(container.getElement()[0], { + automaticLayout: true, + theme: "vs-dark", + scrollBeyondLastLine: false, + readOnly: state.readOnly, + language: "plaintext", + minimap: { + enabled: false + } + }); + + container.on("tab", function(tab) { + tab.element.append(""); + tab.element.on("mousedown", function(e) { + e.target.closest(".lm_tab").children[3].hidden = true; + }); + }); + }); + + layout.registerComponent("sandbox message", function (container, state) { + sandboxMessageEditor = monaco.editor.create(container.getElement()[0], { + automaticLayout: true, + theme: "vs-dark", + scrollBeyondLastLine: false, + readOnly: state.readOnly, + language: "plaintext", + minimap: { + enabled: false + } + }); + + container.on("tab", function(tab) { + tab.element.append(""); + tab.element.on("mousedown", function(e) { + e.target.closest(".lm_tab").children[3].hidden = true; + }); + }); + }); + + layout.on("initialised", function () { + $(".monaco-editor")[0].appendChild($("#editor-status-line")[0]); + if (getIdFromURI()) { + loadSavedSource(); + } else { + loadRandomLanguage(); + } + $("#site-navigation").css("border-bottom", "1px solid black"); + sourceEditor.focus(); + }); + + layout.init(); + }); +}); + +// Template Sources +var assemblySource = "\ +section .text\n\ + global _start\n\ +\n\ +_start:\n\ +\n\ + xor eax, eax\n\ + lea edx, [rax+len]\n\ + mov al, 1\n\ + mov esi, msg\n\ + mov edi, eax\n\ + syscall\n\ +\n\ + xor edi, edi\n\ + lea eax, [rdi+60]\n\ + syscall\n\ +\n\ +section .rodata\n\ +\n\ +msg db 'hello, world', 0xa\n\ +len equ $ - msg\n\ +"; + +var bashSource = "echo \"hello, world\""; + +var basicSource = "PRINT \"hello, world\""; + +var cSource = "\ +#include