Skip to content

Commit 0a5bc4c

Browse files
committed
add a dark mode
1 parent 327bba0 commit 0a5bc4c

5 files changed

Lines changed: 124 additions & 15 deletions

File tree

src/webpage/editor/line.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,30 @@ class Line {
3333
const spot = cursors[0] || 0;
3434
const parts = [...parseLine(this.str)];
3535
let j = 0;
36+
const theme = localStorage.getItem("theme") || ("light" as "dark") || "light";
37+
3638
for (const thing of parts) {
3739
let color: string;
3840

3941
//TODO undo hardcoding of values
4042
switch (thing.type) {
4143
case "invalidString":
4244
case "invalidChar":
43-
color = "red";
45+
color = theme === "light" ? "red" : "indianred";
4446
break;
4547
case "instruction":
46-
color = "blue";
48+
color = theme === "light" ? "blue" : "aqua";
4749
break;
4850
case "register":
49-
color = "red";
51+
color = theme === "light" ? "red" : "indianred";
5052
break;
5153
case "variable":
5254
color = "goldenrod";
5355
break;
5456
case "string":
5557
case "comment":
5658
case "char":
57-
color = "green";
59+
color = theme === "light" ? "green" : "greenyellow";
5860
break;
5961
case "directive":
6062
color = "magenta";
@@ -67,7 +69,7 @@ class Line {
6769
case "label":
6870
case "parentheses":
6971
case "unknown":
70-
color = "black";
72+
color = theme === "light" ? "black" : "white";
7173
}
7274
ctx.fillStyle = color;
7375
const split = thing.content.split(" ");

src/webpage/index.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ helpMenu.addButton(
273273
menu.append(title, tabs, body, close);
274274
menu.setAttribute("closedBy", "any");
275275
menu.showModal();
276+
menu.onclose = () => {
277+
menu.remove();
278+
};
276279
},
277280
);
278281

@@ -281,6 +284,48 @@ helpButton.textContent = I18n.help.help();
281284
actionRow.append(helpButton);
282285
helpMenu.bindContextmenu(helpButton, undefined, undefined, true);
283286

287+
const settingsButton = document.createElement("button");
288+
settingsButton.textContent = I18n.settings.settings();
289+
actionRow.append(settingsButton);
290+
let theme = localStorage.getItem("theme") || ("dark" as "light") || "dark";
291+
function updateTheme() {
292+
document.body.className = theme + "-theme";
293+
}
294+
updateTheme();
295+
settingsButton.onclick = () => {
296+
const menu = document.createElement("dialog");
297+
menu.classList.add("flexttb");
298+
const h1 = document.createElement("h1");
299+
h1.textContent = I18n.settings.settings();
300+
301+
const themeSpan = document.createElement("span");
302+
themeSpan.textContent = I18n.settings.theme.theme();
303+
304+
const themeSelect = document.createElement("select");
305+
const light = document.createElement("option");
306+
light.textContent = I18n.settings.theme.light();
307+
light.value = "light";
308+
const dark = document.createElement("option");
309+
dark.textContent = I18n.settings.theme.dark();
310+
dark.value = "dark";
311+
if (theme === "dark") dark.selected = true;
312+
themeSelect.value = theme;
313+
themeSelect.append(light, dark);
314+
themeSelect.onchange = () => {
315+
theme = themeSelect.value;
316+
localStorage.setItem("theme", theme);
317+
updateTheme();
318+
};
319+
320+
menu.append(h1, themeSpan, themeSelect);
321+
document.body.append(menu);
322+
menu.setAttribute("closedBy", "any");
323+
menu.showModal();
324+
menu.onclose = () => {
325+
menu.remove();
326+
};
327+
};
328+
284329
const area = document.getElementById("area") as HTMLElement;
285330
if (!area) throw Error("area not found");
286331
let editors: Editor[] = [];

src/webpage/style.css

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,70 @@ body {
88
overflow: hidden; /* avoid "bounce" */
99
-webkit-text-size-adjust: 100%;
1010
}
11+
.dark-theme {
12+
background: #1b1b1b;
13+
color: #ffffff;
14+
#mainRow {
15+
background: #333333;
16+
img {
17+
background: #5a5a5a;
18+
}
19+
}
20+
#actionRow {
21+
background: #373737;
22+
color: white;
23+
}
24+
button {
25+
background: #101010;
26+
color: white;
27+
}
28+
.tabStyle {
29+
button {
30+
background: #0d0d0d;
31+
}
32+
.selected {
33+
box-shadow: none;
34+
background: #090909;
35+
}
36+
button:hover {
37+
background: #3d3d3d;
38+
}
39+
}
40+
.projectList {
41+
button:nth-of-type(even) {
42+
background-color: rgb(46 46 46);
43+
}
44+
}
45+
.fileList {
46+
span {
47+
background: #0a0a0a;
48+
}
49+
}
50+
.regiTable {
51+
tr:first-child {
52+
background: #000000;
53+
text-align: center;
54+
}
55+
}
56+
tr:nth-of-type(even) {
57+
background-color: rgb(45 45 45);
58+
}
59+
tr:first-child {
60+
background: #000000;
61+
}
62+
.controls {
63+
background: #080808;
64+
}
65+
.LastUsed {
66+
background-color: #5b6529 !important;
67+
}
68+
.running {
69+
background-color: #5b6529;
70+
}
71+
tr:nth-of-type(even).running {
72+
background-color: #5b6529;
73+
}
74+
}
1175
.speedDiv {
1276
width: 200px;
1377
}

src/webpage/utils/utils.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
setTheme();
2-
export function setTheme() {
3-
let name = localStorage.getItem("theme");
4-
if (!name) {
5-
localStorage.setItem("theme", "Dark");
6-
name = "Dark";
7-
}
8-
document.body.className = name + "-theme";
9-
}
10-
111
class Directory {
122
static home = this.createHome();
133
handle: FileSystemDirectoryHandle;

translations/en.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@
316316
"addDescs":"sltiu t1, t2, 10 $1: If t2 is less than the immediate set t1 to 1 otherwise set it to 0 (unsigned)"
317317
}
318318
},
319+
"settings":{
320+
"settings":"Settings",
321+
"theme":{
322+
"theme":"Theme:",
323+
"light":"Light",
324+
"dark":"Dark"
325+
}
326+
},
319327
"directives":{
320328
"global":"Declare the listed label(s) as global to enable referencing from other files",
321329
"text":"Store items after this (Instructions) at next available text address",

0 commit comments

Comments
 (0)