-
Notifications
You must be signed in to change notification settings - Fork 23
/
ide.html
115 lines (100 loc) · 2.81 KB
/
ide.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
<html>
<header>
<title>ESP8266 lisp IDE</title>
</header>
<script>
function jsonp_pp(data, name) {
var t = document.getElementById('def-' + name);
t.innerText = data;
}
function mkeditlink(f) {
return "<a onclick=\"pp('" + f + "', this);\" class='func-name'>" + f + "</a>";
}
function jsonp_list(data) {
var t = document.getElementById('list');
t.innerHTML = data.split(/\n/).sort().map(function(f){ return f ? ("<span>" + mkeditlink(f) + "</span>") : ""; }).join("\n");;
}
function jsonp_eval(data, exp) {
var t = document.getElementById('eval');
//t.innerText = data;
var d = document.createElement('div');
d.innerText = data;
// TODO: encode exp!
exp = exp || document.getElementById("einput").value;
d.insertAdjacentHTML('afterBegin', "lisp> " + exp + "<br>");
t.insertAdjacentElement('afterBegin', d);
}
function update(url) {
var s = document.createElement('script');
s.src = url;
document.head.appendChild(s);
s.onload = function() { s.remove(); };
s.onerror = function() { s.remove(); console.log("FAIL: " + url); };
}
</script>
<body spellcheck="false">
<style>
.term {
//word-wrap: break-word;
display: inline-block;
border: 2px solid black;
padding: 5px;
border-radius: 5px;
//background: black;
//color: #8AFF4F;
background: yellow;
font-weight: bold;
}
.func-name {
display: block;
background: gray;
color: white;
font-weight: bold;
padding: 3px;
margin: 2px;
padding-left: 10px;
position: relative;
width: 110%;
left: -10px;
}
</style>
<h1>ESP8266 lisp IDE</h1>
<div id='list'>
</div>
<br><button onclick='ide("list");'>list</button><br>
<h2>Eval</h2>
<input id='einput' length=60 columns=60 onkeydown="if (event.keyCode == 13 || event.keyCode == 10) doeval();">
<button onclick='doeval();'>eval</button><br>
<pre id='eval' class='term' style='background: white; display: block;'>
</pre>
<script>
function doeval() {
ide("eval?" + document.getElementById("einput").value);
}
function edit(elt) {
elt.onclick = undefined;
// TODO: doesn't work! http://stackoverflow.com/questions/5601431/spellcheck-false-on-contenteditable-elements
elt.contentEditable = 'true';
elt.spellcheck = 'false'; elt.focus(); elt.blur();
elt.style.background = 'pink';
var h = elt.previousSibling;
h.style.color = 'lime';
}
function pp(name, elt) {
var t = document.getElementById('def-' + name);
if (t) {
t.style.display = t.style.display == "none" ? "block" : "none";
return;
}
elt.insertAdjacentHTML("afterEnd", "<pre id='def-" + name +"' class='term' onclick='edit(this);'>FISH</pre>");
elt.style.background = 'black';
ide("pp?" + name);
// TODO: but first need to decode in lisp!!!
//ide("pp?" + encodeURIComponent(name));
}
function ide(path) {
update("http://localhost:8080/ide/" + path + "??" + (new Date()).valueOf());
}
</script>
</body>
</html>