@naanlang/naan 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +46 -0
- package/dist/env_web.js +431 -0
- package/dist/naan.min.js +73 -0
- package/frameworks/browser/browser.nlg +30 -0
- package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
- package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
- package/frameworks/browser/sworker.js +192 -0
- package/frameworks/browser/terminals.nlg +787 -0
- package/frameworks/browser/workers.nlg +386 -0
- package/frameworks/client/apiclient.nlg +183 -0
- package/frameworks/client/client.nlg +29 -0
- package/frameworks/client/psm_client.nlg +572 -0
- package/frameworks/common/common.nlg +464 -0
- package/frameworks/common/preferences.nlg +131 -0
- package/frameworks/common/repltools.nlg +100 -0
- package/frameworks/common/watching.nlg +97 -0
- package/frameworks/node/apiserver.nlg +399 -0
- package/frameworks/node/filesystem.nlg +1012 -0
- package/frameworks/node/gitter.nlg +234 -0
- package/frameworks/node/node.nlg +81 -0
- package/frameworks/node/psm_server.nlg +465 -0
- package/frameworks/node/worker.nlg +560 -0
- package/frameworks/project/build.nlg +1229 -0
- package/frameworks/project/jszip.js +30 -0
- package/frameworks/project/jszip.nlg +87 -0
- package/frameworks/project/proj_cliser.nlg +139 -0
- package/frameworks/project/proj_console.nlg +137 -0
- package/frameworks/project/proj_folder.nlg +143 -0
- package/frameworks/project/proj_lambda.nlg +137 -0
- package/frameworks/project/proj_static.nlg +138 -0
- package/frameworks/project/project.nlg +29 -0
- package/frameworks/project/projects.nlg +587 -0
- package/frameworks/project/uglifyjs.js +1 -0
- package/frameworks/project/uglifyjs.nlg +79 -0
- package/frameworks/running/debugcom.nlg +163 -0
- package/frameworks/running/debugnub.nlg +565 -0
- package/frameworks/running/debugutil.nlg +510 -0
- package/frameworks/running/executors.nlg +767 -0
- package/frameworks/running/running.nlg +151 -0
- package/frameworks/running/sourcecode.nlg +346 -0
- package/frameworks/running/taskexec.nlg +196 -0
- package/frameworks/storage/dbt_pouch.nlg +773 -0
- package/frameworks/storage/file_manager.nlg +772 -0
- package/frameworks/storage/psm.nlg +326 -0
- package/frameworks/storage/psm_dbtables.nlg +814 -0
- package/frameworks/storage/resources.nlg +445 -0
- package/frameworks/storage/storage.nlg +52 -0
- package/lib/browser/env_web.js +431 -0
- package/lib/browser/env_webworker.js +146 -0
- package/lib/browser/require.js +1653 -0
- package/lib/core/naanlib.js +73 -0
- package/lib/env_node.js +282 -0
- package/lib/env_nodeworker.js +165 -0
- package/lib/node_repl.js +25 -0
- package/lib/node_repl_init.nlg +52 -0
- package/package.json +13 -0
- package/plugins/gitClient/clientops.nlg +317 -0
- package/plugins/gitClient/gitClient.nlg +63 -0
- package/plugins/gitClient/gitutils.nlg +1331 -0
- package/plugins/gitClient/minimatch.js +945 -0
- package/plugins/gitClient/minimatch_license.txt +15 -0
- package/plugins/gitClient/minimatch_readme.md +208 -0
- package/plugins/nodeLib/nodeLib.nlg +26 -0
- package/plugins/nodeLib/node_cp.nlg +65 -0
- package/plugins/nodeLib/node_fs.nlg +137 -0
- package/plugins/nodeLib/node_https.nlg +172 -0
- package/plugins/nodeLib/node_util.nlg +180 -0
- package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
- package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
- package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
- package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
- package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
- package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
- package/plugins/serviceAws/aws_cognito.nlg +76 -0
- package/plugins/serviceAws/aws_dynamo.nlg +509 -0
- package/plugins/serviceAws/aws_lambda.nlg +95 -0
- package/plugins/serviceAws/aws_s3.nlg +134 -0
- package/plugins/serviceAws/aws_utils.nlg +86 -0
- package/plugins/serviceAws/dbt_aws.nlg +769 -0
- package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
- package/plugins/serviceAws/psm_aws.nlg +258 -0
- package/plugins/serviceAws/serviceAws.nlg +38 -0
- package/plugins/serviceGitHub/gitops.nlg +522 -0
- package/plugins/serviceGitHub/psm_github.nlg +205 -0
- package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
- package/plugins/serviceGitLab/gitops.nlg +528 -0
- package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
- package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
- package/test/harness.nlg +312 -0
- package/test/node_test.js +33 -0
- package/test/test_01_core.nlg +768 -0
- package/test/test_02_context.nlg +269 -0
- package/test/test_03_jsinterop.nlg +137 -0
- package/test/test_04_numerics.nlg +450 -0
- package/test/test_05_strings.nlg +63 -0
- package/test/test_06_lingoparse.nlg +500 -0
- package/test/test_07_lingo.nlg +623 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Naan for NPM version 1.0.0-1 is released under the MIT License:
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2022 Zulch Laboratories, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
**Naan**™
|
|
2
|
+
-----
|
|
3
|
+
|
|
4
|
+
Naan is an async-first software platform for rapid development.
|
|
5
|
+
|
|
6
|
+
#### Release:
|
|
7
|
+
Naan for NPM version 1.0.0-1
|
|
8
|
+
Copyright (c) 2017-2022 Zulch Laboratories, Inc.
|
|
9
|
+
|
|
10
|
+
#### Features
|
|
11
|
+
- **Naan** runs in NodeJS and web browsers using JavaScript
|
|
12
|
+
- Based on an asynchronous LISP-2 engine with persistent execution
|
|
13
|
+
- The default **Lingo**™ surface language provides familiar Algol-style braces syntax
|
|
14
|
+
- Concurrent operation without async or await declarations
|
|
15
|
+
- Provides tuples, objects, closures, macros, lexical and dynamic binding
|
|
16
|
+
- Module and package support with namespaces and write-protect isolation
|
|
17
|
+
- Preserves referential integrity when communicating among workers or hosts
|
|
18
|
+
- Plugin architecture enables alternate languages and functionality
|
|
19
|
+
- Custom language syntax can be added through simplified dialect extensions
|
|
20
|
+
- Integrates transparently with all exising JavaScript libraries
|
|
21
|
+
- Can save and reload running program state across page loads or lambda invocations
|
|
22
|
+
- Lightweight and efficient
|
|
23
|
+
|
|
24
|
+
#### Installation
|
|
25
|
+
|
|
26
|
+
Please ensure you have a recent version of [node.js](http://nodejs.org/)
|
|
27
|
+
|
|
28
|
+
For use everywhere as a command line app:
|
|
29
|
+
|
|
30
|
+
npm install naan -g
|
|
31
|
+
|
|
32
|
+
For use as a library in the current project:
|
|
33
|
+
|
|
34
|
+
npm install naan
|
|
35
|
+
|
|
36
|
+
#### Command line usage
|
|
37
|
+
|
|
38
|
+
naan
|
|
39
|
+
|
|
40
|
+
##### Dependencies:
|
|
41
|
+
We greatfully acknowlege these software packages used with Naan:
|
|
42
|
+
- [jszip.js](http://stuartk.com/jszip) - read and write zip files
|
|
43
|
+
- [NodeJS-path](https://nodejs.org/) - NodeJS path utilities
|
|
44
|
+
- [PouchDB](https://pouchdb.com/) - synchronizing database
|
|
45
|
+
- [SparkMD5](https://github.com/satazor/js-spark-md5) - browser MD5 library
|
|
46
|
+
- [UglifyJS](https://github.com/mishoo/UglifyJS) - JavaScript code minifier
|
package/dist/env_web.js
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* env_web.js
|
|
3
|
+
* Naanlib
|
|
4
|
+
*
|
|
5
|
+
* Host Naan in the Browser environment.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2017-2021 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Initialize
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
(function(exports){
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* NaanControllerWeb
|
|
24
|
+
*
|
|
25
|
+
* This JavaScript object manages a single Naan interpreter instance with the following services:
|
|
26
|
+
* 1. Load persistent state on startup, if available and allowed
|
|
27
|
+
* 2. Interpret query strings supplied when the host window was opened
|
|
28
|
+
* 3. Save state before the host window is closed.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
exports.NaanControllerWeb = function() {
|
|
33
|
+
|
|
34
|
+
"use strict";
|
|
35
|
+
/*jshint -W024 */
|
|
36
|
+
var undefined; // JavaScript should make this a keyword
|
|
37
|
+
|
|
38
|
+
//
|
|
39
|
+
// Persistent
|
|
40
|
+
//
|
|
41
|
+
|
|
42
|
+
var
|
|
43
|
+
kStateFirstVersion = 200, // increment when losing backwards compatbility
|
|
44
|
+
kStateCurrentVersion = 200; // increment when adding features
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
//
|
|
48
|
+
// Environment
|
|
49
|
+
//
|
|
50
|
+
|
|
51
|
+
var pageLoading = true; // assume we are loading the page
|
|
52
|
+
|
|
53
|
+
window.addEventListener("load", function (e) {
|
|
54
|
+
pageLoading = false;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
var querystrings = (function(a) {
|
|
58
|
+
if (a === "") return {};
|
|
59
|
+
var b = {};
|
|
60
|
+
for (var i = 0; i < a.length; ++i)
|
|
61
|
+
{
|
|
62
|
+
var p=a[i].split('=', 2);
|
|
63
|
+
if (p.length == 1)
|
|
64
|
+
b[p[0]] = "";
|
|
65
|
+
else
|
|
66
|
+
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
|
|
67
|
+
}
|
|
68
|
+
return b;
|
|
69
|
+
})(window.location.search.substr(1).split('&'));
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
//
|
|
73
|
+
// Initialization
|
|
74
|
+
//
|
|
75
|
+
|
|
76
|
+
var naanlib = new exports.Naanlib();
|
|
77
|
+
var contSelf = this; // this is us, for access within nested functions
|
|
78
|
+
exports.naancon = this; // access to this instance
|
|
79
|
+
contSelf.anaan = naanlib.js.n;
|
|
80
|
+
naanlib.js.t = contSelf;
|
|
81
|
+
var replstate; // latest known state of the REPL
|
|
82
|
+
var naanstate; // desired state for the interpreter
|
|
83
|
+
var replqueue; // text destined for terminal when opened
|
|
84
|
+
var termlist = []; // list of terminals currently attached
|
|
85
|
+
var prefs = { };
|
|
86
|
+
|
|
87
|
+
//
|
|
88
|
+
// termTextOut
|
|
89
|
+
//
|
|
90
|
+
// Output debug text/level to terminal.
|
|
91
|
+
//
|
|
92
|
+
|
|
93
|
+
naanlib.onText(termTextOut);
|
|
94
|
+
|
|
95
|
+
function termTextOut(text, level) {
|
|
96
|
+
if (!text)
|
|
97
|
+
return;
|
|
98
|
+
if (termlist.length === 0) {
|
|
99
|
+
console.log(text); // make sure we can see early errors
|
|
100
|
+
if (!replqueue)
|
|
101
|
+
replqueue = [];
|
|
102
|
+
replqueue.push({text:text, level:level});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
termlist.forEach(function(term) {
|
|
106
|
+
var msg;
|
|
107
|
+
if (level)
|
|
108
|
+
msg = {
|
|
109
|
+
id: "debugtext",
|
|
110
|
+
text: text,
|
|
111
|
+
level: level
|
|
112
|
+
};
|
|
113
|
+
else
|
|
114
|
+
msg = {
|
|
115
|
+
id: "textout",
|
|
116
|
+
text: text
|
|
117
|
+
};
|
|
118
|
+
term.OnMessage(msg);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//
|
|
124
|
+
// takePending
|
|
125
|
+
//
|
|
126
|
+
// Read any pending Naan output and send to terminal.
|
|
127
|
+
//
|
|
128
|
+
|
|
129
|
+
function takePending() {
|
|
130
|
+
var outputq = replqueue;
|
|
131
|
+
replqueue = false;
|
|
132
|
+
if (outputq)
|
|
133
|
+
outputq.reverse();
|
|
134
|
+
while (outputq && outputq.length > 0) {
|
|
135
|
+
var item = outputq.pop();
|
|
136
|
+
termTextOut(item.text, item.level);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
//==========================================================================
|
|
142
|
+
// New Terminal Interface
|
|
143
|
+
//--------------------------------------------------------------------------
|
|
144
|
+
|
|
145
|
+
//
|
|
146
|
+
// StateGet
|
|
147
|
+
//
|
|
148
|
+
// Report the saved state we are keeping for the terminal.
|
|
149
|
+
//
|
|
150
|
+
|
|
151
|
+
this.StateGet = function StateGet() {
|
|
152
|
+
if (termlist.length > 0)
|
|
153
|
+
replstate = termlist[0].StateSave(); // restore current buffer state to new terminal
|
|
154
|
+
return (replstate);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//
|
|
158
|
+
// Attach
|
|
159
|
+
//
|
|
160
|
+
// Attach a terminal to our interpreter and immediately start sending it messages.
|
|
161
|
+
//
|
|
162
|
+
|
|
163
|
+
this.Attach = function Attach(terminal) {
|
|
164
|
+
var repdex = termlist.indexOf(terminal);
|
|
165
|
+
if (repdex < 0)
|
|
166
|
+
termlist.push(terminal);
|
|
167
|
+
takePending(); // output all pending terminal messages
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
//
|
|
171
|
+
// Detach
|
|
172
|
+
//
|
|
173
|
+
// Detach the terminal from the interpreter.
|
|
174
|
+
//
|
|
175
|
+
|
|
176
|
+
this.Detach = function Detach(terminal) {
|
|
177
|
+
var repdex = termlist.indexOf(terminal);
|
|
178
|
+
if (repdex >= 0)
|
|
179
|
+
termlist.splice(repdex, 1);
|
|
180
|
+
if (termlist.length === 0)
|
|
181
|
+
replstate = terminal.StateSave(); // save ultimate repl state
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
//
|
|
185
|
+
// Interrupt
|
|
186
|
+
//
|
|
187
|
+
// Interrupt the interpreter in response to a user request.
|
|
188
|
+
//
|
|
189
|
+
|
|
190
|
+
this.Interrupt = function Interrupt(terminal) {
|
|
191
|
+
window.setTimeout(function () {
|
|
192
|
+
naanlib.escape();
|
|
193
|
+
}, 1);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
//
|
|
197
|
+
// Return
|
|
198
|
+
//
|
|
199
|
+
// Enter line of text to instance.
|
|
200
|
+
//
|
|
201
|
+
|
|
202
|
+
this.Return = function Return(text, terminal) {
|
|
203
|
+
termlist.forEach(function(term) {
|
|
204
|
+
if (term !== terminal)
|
|
205
|
+
term.OnMessage({ // send text to other terminals
|
|
206
|
+
id: "textout",
|
|
207
|
+
text: text + "\r\n"
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
window.setTimeout(function () {
|
|
211
|
+
naanlib.textLine(text)
|
|
212
|
+
}, 1);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
this.ReplyMessage = function ReplyMessage(data) { // "remote" -> "local"
|
|
216
|
+
termlist.forEach(function(term) {
|
|
217
|
+
if (term.OnMessageOut)
|
|
218
|
+
term.OnMessageOut(data);
|
|
219
|
+
});
|
|
220
|
+
return (data);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
var nideListener;
|
|
224
|
+
this.OnMessage = function OnMessage(proc) {
|
|
225
|
+
nideListener = proc;
|
|
226
|
+
return (proc);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
this.DispatchMessage = function DispatchMessage(data) { // "local" -> "remote"
|
|
230
|
+
if (nideListener)
|
|
231
|
+
setTimeout(function() {
|
|
232
|
+
nideListener(data)
|
|
233
|
+
}, 1);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.ReplyDebugger = function ReplyDebugger(data) { // "remote" -> "local"
|
|
237
|
+
termlist.forEach(function(term) {
|
|
238
|
+
if (term.OnDebugOut)
|
|
239
|
+
term.OnDebugOut(data);
|
|
240
|
+
});
|
|
241
|
+
return (data);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
var debugListener;
|
|
245
|
+
this.OnDebugger = function OnDebugger(proc) {
|
|
246
|
+
debugListener = proc;
|
|
247
|
+
return (proc);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
this.DispatchDebugger = function DispatchDebugger(data) { // "local" -> "remote"
|
|
251
|
+
if (debugListener)
|
|
252
|
+
setTimeout(function() {
|
|
253
|
+
debugListener(data)
|
|
254
|
+
}, 1);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//
|
|
258
|
+
// Status
|
|
259
|
+
//
|
|
260
|
+
// Report status to the terminal.
|
|
261
|
+
//
|
|
262
|
+
|
|
263
|
+
setInterval(function() {
|
|
264
|
+
var samples = naanlib.status(1);
|
|
265
|
+
if (samples.length > 0)
|
|
266
|
+
termlist.forEach(function(term) {
|
|
267
|
+
if (term.OnStatus)
|
|
268
|
+
term.OnStatus({ // send status dictionary without ID
|
|
269
|
+
sample: samples[0]
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}, 1000);
|
|
273
|
+
|
|
274
|
+
//
|
|
275
|
+
// Keystroke
|
|
276
|
+
//
|
|
277
|
+
// Enter keystroke to instance.
|
|
278
|
+
//
|
|
279
|
+
|
|
280
|
+
this.Keystroke = function Keystroke(text, keycode) {
|
|
281
|
+
console.log("Naan keystroke mode not implemented");
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
//
|
|
285
|
+
// Dimensions
|
|
286
|
+
//
|
|
287
|
+
// Report terminal dimensions to instance.
|
|
288
|
+
//
|
|
289
|
+
|
|
290
|
+
this.Dimensions = function Dimensions(rows, cols) {
|
|
291
|
+
console.log("Naan terminal dimensions now (" + rows + ", " + cols + ")");
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
//==========================================================================
|
|
296
|
+
// Host Environment
|
|
297
|
+
//--------------------------------------------------------------------------
|
|
298
|
+
|
|
299
|
+
//
|
|
300
|
+
// SavePref
|
|
301
|
+
//
|
|
302
|
+
// Save a persistent preference objectc that can be retrieved in the future.
|
|
303
|
+
//
|
|
304
|
+
|
|
305
|
+
this.SavePref = function SavePref(key, value) {
|
|
306
|
+
return (prefs[key] = value);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
//
|
|
310
|
+
// LoadPref
|
|
311
|
+
//
|
|
312
|
+
// Load a previously-saved preference object for future retrieval.
|
|
313
|
+
//
|
|
314
|
+
|
|
315
|
+
this.LoadPref = function LoadPref(key) {
|
|
316
|
+
return (prefs[key]);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
var saveEvent = new Event("NaanSave");
|
|
320
|
+
|
|
321
|
+
window.document.addEventListener("visibilitychange", function (e) {
|
|
322
|
+
if (window.document.visibilityState != "hidden")
|
|
323
|
+
return;
|
|
324
|
+
window.dispatchEvent(saveEvent);
|
|
325
|
+
saveLocal();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
window.addEventListener("pagehide", function (e) {
|
|
329
|
+
window.dispatchEvent(saveEvent);
|
|
330
|
+
saveLocal();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
window.addEventListener("unload", function (e) {
|
|
334
|
+
window.dispatchEvent(saveEvent);
|
|
335
|
+
saveLocal();
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
window.addEventListener("beforeunload", function (e) {
|
|
339
|
+
window.dispatchEvent(saveEvent);
|
|
340
|
+
saveLocal();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
function makeState() {
|
|
344
|
+
var statedoc = {};
|
|
345
|
+
statedoc.curversion = kStateCurrentVersion;
|
|
346
|
+
statedoc.firstver = kStateFirstVersion;
|
|
347
|
+
statedoc.licensee = "$Licensee$";
|
|
348
|
+
statedoc.verstring = "$Version$";
|
|
349
|
+
statedoc.date = new Date().toISOString();
|
|
350
|
+
statedoc.prefs = prefs;
|
|
351
|
+
statedoc.naan = naanlib.saveState(true); // true to optimize, which is a bit slower
|
|
352
|
+
termlist.forEach(function(term) {
|
|
353
|
+
if (!replstate || term.termwin)
|
|
354
|
+
replstate = term.StateSave(); // state with separate window, otherwise any state
|
|
355
|
+
})
|
|
356
|
+
if (replstate)
|
|
357
|
+
statedoc.replstate = replstate;
|
|
358
|
+
return (statedoc);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function loadState(statedoc) {
|
|
362
|
+
if (statedoc===undefined || statedoc.naan === undefined
|
|
363
|
+
|| statedoc.firstver > kStateCurrentVersion
|
|
364
|
+
|| statedoc.curversion < kStateFirstVersion
|
|
365
|
+
|| statedoc.licensee != "$Licensee$"
|
|
366
|
+
|| statedoc.verstring != "$Version$")
|
|
367
|
+
return (false);
|
|
368
|
+
naanstate = statedoc.naan;
|
|
369
|
+
replstate = statedoc.replstate; // get terminal state, if any
|
|
370
|
+
if (typeof(statedoc.prefs) == "object")
|
|
371
|
+
prefs = statedoc.prefs;
|
|
372
|
+
return (true);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function saveLocal() {
|
|
376
|
+
/*jshint sub:true */
|
|
377
|
+
if (querystrings["nosave"])
|
|
378
|
+
return (false);
|
|
379
|
+
var statedoc = makeState();
|
|
380
|
+
var statestr = JSON.stringify(statedoc);
|
|
381
|
+
try {
|
|
382
|
+
if ("localStorage" in window && window["localStorage"] !== null)
|
|
383
|
+
{
|
|
384
|
+
localStorage.removeItem("NaanState_Nide");
|
|
385
|
+
if (localStorage.setItem("NaanState_Nide", statestr) !== undefined)
|
|
386
|
+
return (true);
|
|
387
|
+
}
|
|
388
|
+
} catch(e) {
|
|
389
|
+
console.log("save state failed: " + "(" + e + ")");
|
|
390
|
+
}
|
|
391
|
+
return (false);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function loadLocal() {
|
|
395
|
+
try {
|
|
396
|
+
/*jshint sub:true */
|
|
397
|
+
if ("localStorage" in window && window["localStorage"] !== null)
|
|
398
|
+
{
|
|
399
|
+
var statestr = localStorage.getItem("NaanState_Nide");
|
|
400
|
+
if (statestr)
|
|
401
|
+
return (loadState(JSON.parse(statestr)));
|
|
402
|
+
}
|
|
403
|
+
} catch(e) {
|
|
404
|
+
termTextOut("load state failed: " + "(" + e + ")");
|
|
405
|
+
}
|
|
406
|
+
return (false);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/*jshint sub:true */
|
|
410
|
+
if (querystrings["restart"] || !loadLocal())
|
|
411
|
+
{ // don't load state or can't load state
|
|
412
|
+
naanlib.banner();
|
|
413
|
+
var hostpath = naanlib.js.r("path").dirname(window.location.href);
|
|
414
|
+
naanlib.start({
|
|
415
|
+
cmd: 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '"' + ');;\r\n'
|
|
416
|
+
});
|
|
417
|
+
} else {
|
|
418
|
+
if (!replstate) { // saved state but never opened a terminal
|
|
419
|
+
naanlib.banner();
|
|
420
|
+
naanlib.textLine("print();;\n");
|
|
421
|
+
}
|
|
422
|
+
naanlib.start({
|
|
423
|
+
state: naanstate
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/*jshint sub:true */
|
|
429
|
+
})(typeof exports === 'undefined'?(this.Naanlang?this.Naanlang:this.Naanlang={}) : exports);
|
|
430
|
+
|
|
431
|
+
new Naanlang.NaanControllerWeb();
|