-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoxe.html
151 lines (132 loc) · 4.6 KB
/
oxe.html
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stack OXE</title>
<!-- Bootstrap CSS -->
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
/>
!-- CodeMirrorのCSSをCDNから読み込む -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/codemirror.min.css"
/>
<!-- CodeMirrorのモード(JavaScript)をCDNから読み込む -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/mode/javascript/javascript.min.js"></script>
<!-- 必要に応じて、CodeMirrorの追加機能やテーマも読み込む -->
<!-- 例: Themeの追加 -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.7/theme/dracula.min.css"
/>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<script type="module">
import init, { run_stack } from "./pkg/web_stack.js";
init().then(() => {
window.run_stack = run_stack;
});
</script>
<script type="text/javascript">
let code;
let output;
let log;
document.addEventListener("DOMContentLoaded", function () {
output = document.getElementById("output");
log = document.getElementById("log");
let element = document.getElementById("code");
// CodeMirrorエディタの初期化
code = CodeMirror.fromTextArea(element, {
mode: "stack", // モードを指定(ここではJavaScript)
lineNumbers: true, // 行番号を表示
theme: "monokai", // テーマを指定(必要に応じて)
});
// CodeMirrorエディタの初期化
code.setValue(localStorage.getItem("code"));
});
function run() {
if (!window.run_stack) {
alert("WebAssembly has not finished loading. ");
return;
}
const result = window.run_stack(code.getValue());
output.value = result.output();
log.value = result.log();
}
document.addEventListener("input", function () {
localStorage.setItem("code", code.getValue());
});
</script>
<nav
style="background-color: #17288b; border-color: #17288bl"
class="navbar navbar-expand-lg navbar-dark fixed-top"
>
<a class="navbar-brand" href="/"
>Stack programming language - online execution environment
(OXE)</a
>
</nav>
<div id="main" class="bg-light">
<textarea id="code" rows="15"></textarea>
<button class="btn form-control btn-primary" onclick="run()">
Run
</button>
<div class="split">
<textarea id="output" readonly rows="15">
Standard output</textarea
>
<textarea id="log" readonly rows="15">Inside stack</textarea>
</div>
</div>
</body>
<style>
#main {
padding: 20px;
margin-top: 4vh;
}
.btn {
margin-top: 5px;
margin-bottom: 5px;
background-color: #17288b;
border-color: #17288b;
}
.split {
display: flex;
height: 200px;
}
.split textarea {
box-sizing: border-box;
resize: horizontal;
}
#log,
#output:focus {
outline: none;
}
#code {
background-color: white;
width: 100%;
margin-bottom: 10px;
padding: 10px;
}
.CodeMirror {
height: 50vh;
}
#code,
#output,
#log {
background-color: white;
width: 100%;
margin-bottom: 10px;
padding: 10px;
}
</style>
</html>