Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add lightmode-settings and check if container is valid before deletion #1

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ app.ws('/ws/:repl_name', (ws, req) => {

ws.on('close', () => {
try {
if (!terminals[repl_name]) {
return;
}
let stop_container = pty.spawn('docker', ["rm", "-f", repl_name]);
stop_container.on('close', code => {
if (DEBUG) console.log("Stopped container "+repl_name);
Expand Down
28 changes: 28 additions & 0 deletions src/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,35 @@
d="M12 2.25a.75.75 0 0 1 .75.75v11.69l3.22-3.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 1 1 1.06-1.06l3.22 3.22V3a.75.75 0 0 1 .75-.75Zm-9 13.5a.75.75 0 0 1 .75.75v2.25a1.5 1.5 0 0 0 1.5 1.5h13.5a1.5 1.5 0 0 0 1.5-1.5V16.5a.75.75 0 0 1 1.5 0v2.25a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3V16.5a.75.75 0 0 1 .75-.75Z"
clip-rule="evenodd" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" id="settings">
<path stroke-linecap="round" stroke-linejoin="round"
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.325.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>

</div>
</div>



<div id="settingsModal" class="modal">

<div class="modal-content">
<span id="close">&times;</span>

<h1>Settings</h1>
<div>
Darkmode Editor:
<input type="checkbox" checked id="darkmode-editor">

<br>
Darkmode Terminal:
<input type="checkbox" checked id="darkmode-terminal">

</div>
</div>

</div>

<script src="/static/monaco-editor/min/vs/loader.js"></script>
Expand Down
83 changes: 80 additions & 3 deletions src/web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ require(['vs/editor/editor.main'], function () {
monaco.languages.setMonarchTokensProvider('Elm', window.elm_monarch);

// monaco-editor theme & colors
monaco.editor.defineTheme('dark-plus', {
monaco.editor.defineTheme('dark', {
base: 'vs-dark',
inherit: true,
rules: [
Expand All @@ -145,14 +145,25 @@ require(['vs/editor/editor.main'], function () {
colors: {},
});

monaco.editor.defineTheme('light', {
base: 'vs',
inherit: true,
rules: [
{ token: 'keyword', foreground: '#037ABA' },
{ token: 'type', foreground: '#BE5A09' },
{ token: 'function.name', foreground: '#044B86' },
],
colors: {},
});

// init editor
var editor = monaco.editor.create(document.getElementById('container'), {
fontSize: 18,
value: getEditorValue(),
language: 'Elm',
automaticLayout: true,
scrollBeyondLastLine: false,
theme: "dark-plus",
theme: localStorage.getItem("darkmode-editor") === 'false' ? "light" : "dark",
automaticLayout: true,
});

Expand All @@ -166,6 +177,30 @@ require(['vs/editor/editor.main'], function () {

// TERMINAL

terminaLightTheme = {
"foreground": "#383A42",
"background": "#FAFAFA",
"cursorColor": "#4F525D",
"selectionBackground": "#FFFFFF",
"black": "#383A42",
"red": "#E45649",
"green": "#50A14F",
"yellow": "#C18301",
"blue": "#0184BC",
"purple": "#A626A4",
"cyan": "#0997B3",
"white": "#FAFAFA",
"brightBlack": "#4F525D",
"brightRed": "#DF6C75",
"brightGreen": "#98C379",
"brightYellow": "#E4C07A",
"brightBlue": "#61AFEF",
"brightPurple": "#C577DD",
"brightCyan": "#56B5C1",
"brightWhite": "#FFFFFF",
"cursor": "#4F525D"
}

let term,
socketURL,
socket;
Expand All @@ -178,7 +213,7 @@ const createTerminal = () => {
fontFamily: "Menlo, Monaco, monospace",
cursorBlink: false
});

term.options.theme = localStorage.getItem("darkmode-terminal") === 'false' ? terminaLightTheme : {};
socketURL = ((location.protocol === 'https:') ? 'wss://' : 'ws://') + location.hostname + ((location.port) ? (':' + location.port) : '') + '/ws/';

term.open(terminalContainer);
Expand Down Expand Up @@ -260,3 +295,45 @@ if (repl) {
socket.send("import Main exposing (..)\n")
}, 2000);
}


var settingsModal = document.getElementById("settingsModal");

// When the user clicks on the settings button, open the modal
document.getElementById("settings").onclick = function () {
settingsModal.style.display = "block";
}

// When the user clicks on the close button, close the modal
document.getElementById("close").onclick = function () {
settingsModal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == settingsModal) {
settingsModal.style.display = "none";
}
}

document.querySelector('#darkmode-editor').checked = (localStorage.getItem('darkmode-editor') === 'true')
document.getElementById("darkmode-editor").addEventListener("change", function () {
if (this.checked) {
window.theEditor.updateOptions({ theme: "dark" });
localStorage.setItem("darkmode-editor", true);
} else {
window.theEditor.updateOptions({ theme: "light" });
localStorage.setItem("darkmode-editor", false);
}
});

document.querySelector('#darkmode-terminal').checked = (localStorage.getItem('darkmode-terminal') === 'true')
document.getElementById("darkmode-terminal").addEventListener("change", function () {
if (this.checked) {
term.options.theme = {};
localStorage.setItem("darkmode-terminal", true);
} else {
term.options.theme = terminaLightTheme;
localStorage.setItem("darkmode-terminal", false);
}
});
35 changes: 35 additions & 0 deletions src/web/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,38 @@ body {
resize: vertical;
overflow: auto;
}


.modal {
font-family: Consolas, "Courier New", monospace;
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
}

.modal-content {
background-color: #1f1f1f;
color: white;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}

#close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

#close:hover,
#close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}