Repository navigation
Expand file tree
/
Copy pathjsforth.html
More file actions
110 lines (103 loc) · 3.23 KB
/
Copy pathjsforth.html
File metadata and controls
110 lines (103 loc) · 3.23 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
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
<html>
<head>
<title>JS-Forth</title>
</head>
<body>
<h1><a id="hdr" href="https://github.com/CCurl/JS-Forth" target="_blank">??</a></h1>
<div style="display: flex; gap: 15px; align-items: flex-start;">
<!-- Left: Textboxes (vertical) -->
<div style="display: flex; flex-direction: column; gap: 10px;">
<!-- Input -->
<div>
<h2>Input (Select + Ctrl-Enter)</h2>
<textarea id="forth-hist" rows="16" cols="64"
onkeydown="if (event.ctrlKey && event.key==='Enter'){ execSelected(); }"></textarea>
</div>
<!-- Output -->
<div>
<h2>Output</h2>
<textarea id="forth-output" rows="16" cols="64" readonly></textarea>
</div>
<!-- Block -->
<div>
<h2>Block <pre id="blk-num" style="display: inline;">??</pre></h2>
<textarea id="forth-block" rows="16" cols="64" readonly></textarea>
</div>
</div>
<!-- Right: Canvas -->
<div style="display: flex; flex-direction: column; gap: 10px;">
<canvas id="the-canvas" width="800" height="400" style="border: 1px solid #666; display: block; image-rendering: pixelated; width: auto; height: auto; align-self: flex-start;"></canvas>
<!-- Command input -->
<div>
<label><b>Command:</b> </label>
<input type="text" id="forth-input" size="85" autofocus value="3 load go"
onkeydown="if (event.key==='Enter'){ runCommand(); }">
</div>
</div>
</div>
<script src="./jsforth.js"></script>
<script src="./graphics.js"></script>
<script src="./doom-o.js"></script>
<script src="./blocks.js"></script>
<script type="application/forth">
: version s" JS-Forth v2026.10.19" ; : cr 10 emit ;
version s" hdr" html!
( s" words" s" forth-hist" html! )
: banner version type ." - Chris Curl" cr cr ." Hello." cr ;
banner cr 1 load 0 list
</script>
<script>
// Initialize graphics and register graphics Forth words
let graphicsCanvasElement = document.getElementById('the-canvas');
if (graphicsCanvasElement) {
initGraphics(graphicsCanvasElement);
registerGraphicsWords();
}
</script>
<script>
function execSelected() {
var ta = document.getElementById('forth-hist');
var sel = ta.value.substring(ta.selectionStart, ta.selectionEnd);
if (sel) runForth(sel);
}
function runCommand() {
var inp = document.getElementById('forth-input');
var ta = document.getElementById('forth-hist');
ta.value += inp.value + '\n';
runForth(inp.value);
inp.value = '';
}
</script>
</body>
<style>
body {
font-family: monospace;
}
h2 {
text-align: left;
margin: 0;
}
pre {
display: inline;
margin: 0;
}
#forth-input {
height: 1.8em;
padding: 4px;
}
label {
font-size: 1.5em;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #1e1e1e;
color: #e0e0e0;
}
textarea, input {
background-color: #2d2d2d;
color: #e0e0e0;
border: 1px solid #444;
}
}
</style>
</html>