-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclips_client.html
271 lines (242 loc) · 8 KB
/
clips_client.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Revision since version 0.0.3: work/jaxmate_client
.. added class="math" to MathDiv
.. set .math color
.. @text off (default jxmt_text_output=false;)
.. npm install jquery-ui
+ jquery-ui@1.12.1 / added 1 package in 1.809s
.. todo: use 'npm root' -> env var
.. Using template literals (check browsers)
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
.. jxmt_scale=110 ; -- scaling MathJax
.. server: input.write('#! --enable jaxmate\n');
input.write('let __jaxmate__=true;\n');
-->
<!-- @STYLE SECTION -->
<!-- external css file
<link rel="stylesheet" type="text/css" href="default.css">
-->
<style>
html, body {
background-color: white;
color: black;
font-family: monospace;
margin: 0;
padding: 0;
margin-bottom: 25px;
}
/* The console container element */
/*#console {
height: 400px;
width: 750px;
position:relative;
background-color: black;
border: 2px solid #CCC;
margin: 0 auto;
margin-top: 50px;
}
*/
/* The inner console element. */
.jqconsole {
padding: 10px;
}
/* The cursor. */
.jqconsole-cursor {
background-color: gray;
}
/* The cursor color when the console looses focus. */
.jqconsole-blurred .jqconsole-cursor {
background-color: #666;
}
/* The current prompt text color */
.jqconsole-prompt {
color: #00f;
}
/* The command history */
.jqconsole-old-prompt {
color: #b00;
font-weight: normal;
}
/* The text color when in input mode. */
.jqconsole-input {
color: #d00;
}
/* Previously entered input. */
.jqconsole-old-input {
color: #b00;
font-weight: normal;
}
/* The text color of the text output. */
.jqconsole-output {
color: blue;
}
/* mathjax output (jxmt_div_prefix='MathDiv')*/
.math {
color: #00a;
}
</style>
<!-- SCRIPT CONFIG VARS -->
<script>
jxmt_start_msg="CLIPS-JaxMaTe v1.0.1 (type @help)\n\n\n";
jxmt_prompt="> ";
jxmt_cfg_prefix="@";
jxmt_div_prefix='MathDiv';
jxmt_text_output=false;
jxmt_mathjax_output=true;
jxmt_socket_io='http://localhost:3010';
jxmt_scale=110;
jxmt_help_text=`
Finish input operation ............... Enter
Multiline ............................. Shift+Enter
History ............................... Up/Down
Zoom +/- .............................. Ctrl+Plus/Minus
MathJax settings ...................... Mouse+RClick
Console text on/off ................... @text on/off
MathJax output on/off ................. @mathjax on/off
Show history .......................... @history
Dump content .......................... @dump
Clear (! history+screen) .............. @clear
CLIPS help ............................ @client-help
CLIPS version ......................... version;
** see https://github.com/nilqed/jaxmate_CLIPS for more.
\n`;
jxmt_client_help=`<p>The link below will open a new window/tab:
<a href="https://nilqed.github.io/clips_jaxmate/index.html"
target="_blank">CLIPS - Basic Programming Guide</a>
<br>`;
// Do not change this!
// Same constants must be defined in xyz_server.js
const emit_output = 'jaxmate_output';
const socket_eval = 'jaxmate_eval';
</script>
<!-- @SCRIPT MATHJAX CONFIG -->
<!-- http://docs.mathjax.org/en/latest/configuration.html -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax:{inlineMath:[['$','$']]},
CommonHTML: { linebreaks: { automatic: true }, scale: jxmt_scale },
"HTML-CSS": { linebreaks: { automatic: true }, fonts: ["TeX"], scale: 130},
SVG: { linebreaks: { automatic: true } }});
</script>
<!-- @SCRIPT MATHJAX CDN
<script
src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/
latest.js?config=TeX-AMS-MML_HTMLorMML' async>
</script>
Changed: TeX-AMS-MML_HTMLorMML -> TeX-AMS_CHTML
-->
<title>JaxMate Client</title>
</head>
<body>
<!-- @DIV CONSOLE -->
<div id="console"></div>
<!-- -->
<script src="/static/socket.io-client/dist/socket.io.js"></script>
<script src="/static/jquery/dist/jquery.js"></script>
<script src="/static/jq-console/lib/jqconsole.js"></script>
<script src="/static/mathjax/MathJax.js?config=TeX-AMS_CHTML" async></script>
<!-- script src="/static/jquery-ui/ui/widget.js"></script -->
<script>
var socket = io(jxmt_socket_io);
socket.on('connect', function(){socket.emit('do something',{})});
socket.on('myevent', function(data){});
socket.on('disconnect', function(){});
</script>
<!-- @SCRIPT START -->
<script>
$(function () {
var jqconsole = $('#console').jqconsole(jxmt_start_msg, jxmt_prompt);
var idc=0; // div id counter
var out={id:"",data:""}; // data format
function jxmt_cfg_handler (cmd) {
//jqconsole.SetPromptLabel('cfg> ');
//jqconsole.Write("cfg\n", 'jqconsole-output');
//if (s=="@text off") {jxmt_text_output=false;};
//if (s=="@text on") {jxmt_text_output=true;};
//if (s=="@mathjax off") {jxmt_mathjax_output=false;};
//if (s=="@mathjax on") {jxmt_mathjax_output=true;};
//if (s=="@quit") {jqconsole.SetPromptLabel(jxmt_prompt);};
switch(cmd) {
case "@text off":
jxmt_text_output=false;
break;
case "@text on":
jxmt_text_output=true;
break;
case "@mathjax off":
jxmt_mathjax_output=false;
break;
case "@mathjax on":
jxmt_mathjax_output=true;
break;
case "@history":
var history = jqconsole.GetHistory();
jqconsole.Write(history);
jqconsole.Write('\n');
var i;
for (i = 0; i < history.length; i++) {
jqconsole.Write(i.toString()+' : '+history[i]+'\n');
};
break;
case "@dump":
jqconsole.Write(jqconsole.Dump());
jqconsole.Write('\n');
break;
case "@clear":
jqconsole.Clear();
break;
case "@help":
//window.open("https://github.com/nilqed", "_blank",
//"toolbar=no,menubar=no, top=500,left=500,width=400,height=400");
jqconsole.Write(jxmt_help_text, 'jqconsole-output');
break;
case "@client-help":
//'<div class="jaxmatecleint">JaxMate Client</div>';
jqconsole.Append($(jxmt_client_help));
break;
//default
default:
jqconsole.Write("No such command ...\n", 'jqconsole-output');
}
};
// Output coming from server (after emission of 'socket_eval')
socket.on(emit_output, function(out){
if (jxmt_text_output)
{
jqconsole.Write(out.data + '\n', 'jqconsole-output');
};
if (jxmt_mathjax_output)
{
document.getElementById(out.id).innerHTML=out.data;
MathJax.Hub.Queue(["Typeset",MathJax.Hub,out.id]);
};
//https://www.w3schools.com/jsref/met_element_scrollintoview.asp
document.getElementById(out.id).scrollIntoView(); //cool
});
var startPrompt = function () {
// Start the prompt with history enabled.
jqconsole.Prompt(true, function (input) {
// Output srvdata with the class jqconsole-output.
// div counter
var divID=jxmt_div_prefix + idc;
// cfg_handler
if (input.startsWith(jxmt_cfg_prefix))
{jxmt_cfg_handler(input);startPrompt();}
else
{
socket.emit(socket_eval,{id:divID,data:input}); // socket emit -> send input
//jqconsole.Write(out.data + '\n', 'jqconsole-output');
jqconsole.Append($('<div id=' + divID + ' class="math"></div>'));
//MathJax.Hub.Queue(["Typeset",MathJax.Hub,divID]);
idc++;
// Restart the prompt.
startPrompt();};
});
};
startPrompt();
});
</script>
</body>
</html>