-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
78 lines (58 loc) · 1.65 KB
/
index.html
File metadata and controls
78 lines (58 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>TJC Editor</title>
<style>
body { font-family: monospace; background:#111; color:#0f0; padding:20px; }
textarea { width:100%; height:300px; background:#000; color:#0f0; padding:10px; }
button { padding:10px; margin-top:10px; }
pre { background:#000; padding:10px; margin-top:10px; }
</style>
</head>
<body>
<h2>TJC Editor ⚡</h2>
<input type="file" id="fileInput"><br><br>
<textarea id="editor"></textarea><br>
<button onclick="runCode()">Run</button>
<pre id="output"></pre>
<script src="interpreter.js"></script>
<script>
let editor = document.getElementById("editor");
// 🔥 Auto-indent logic
editor.addEventListener("keydown", function(e) {
if (e.key === "Enter") {
e.preventDefault();
let lines = editor.value.split("\n");
let lastLine = lines[lines.length - 1];
let indent = (lastLine.match(/^\s*/) || [""])[0];
if (lastLine.trim().endsWith(":")) {
indent += " ";
}
if (lastLine.trim() === "#") {
indent = indent.slice(0, -4);
}
editor.value += "\n" + indent;
}
});
// 🔥 Run code
function runCode() {
let code = editor.value;
try {
let result = runTJC(code);
document.getElementById("output").textContent = result.join("\n");
} catch (e) {
document.getElementById("output").textContent = "Error: " + e.message;
}
}
// 🔥 Load .tjc file
document.getElementById("fileInput").addEventListener("change", function(e) {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = function(event) {
editor.value = event.target.result;
};
reader.readAsText(file);
});
</script>
</body>
</html>