@naanlang/naan 1.5.0 → 1.6.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 +2 -2
- package/README.md +2 -2
- package/bin/index.js +7 -3
- package/dist/env_web.js +162 -20
- package/dist/naan.min.js +5 -5
- package/frameworks/browser/https_request.nlg +2 -2
- package/frameworks/browser/sworker.js +28 -26
- package/frameworks/browser/terminals.nlg +329 -693
- package/frameworks/browser/worker.nlg +255 -0
- package/frameworks/browser/workers.nlg +5 -5
- package/frameworks/browser/ws_client.nlg +15 -10
- package/frameworks/client/apiclient.nlg +181 -9
- package/frameworks/client/relaycon.nlg +87 -161
- package/frameworks/common/events.nlg +101 -0
- package/frameworks/common/repltools.nlg +80 -1
- package/frameworks/node/apiserver.nlg +39 -246
- package/frameworks/node/filesystem.nlg +31 -6
- package/frameworks/node/http_request.nlg +34 -13
- package/frameworks/node/https_request.nlg +8 -3
- package/frameworks/node/node.nlg +2 -0
- package/frameworks/node/pty.nlg +346 -0
- package/frameworks/node/worker.nlg +409 -539
- package/frameworks/node/ws_client.nlg +2 -2
- package/frameworks/project/build.nlg +1 -1
- package/frameworks/project/projects.nlg +1 -1
- package/frameworks/running/debugnub.nlg +17 -4
- package/frameworks/running/executors.nlg +27 -274
- package/frameworks/running/instances.nlg +393 -0
- package/frameworks/running/remote_req.nlg +143 -0
- package/frameworks/running/remote_res.nlg +89 -0
- package/frameworks/running/taskexec.nlg +2 -2
- package/frameworks/service/imp.nlg +736 -0
- package/frameworks/service/model.nlg +71 -0
- package/frameworks/service/nubnode.nlg +105 -0
- package/frameworks/service/nubweb.nlg +106 -0
- package/frameworks/service/service.nlg +28 -0
- package/lib/browser/env_web.js +169 -27
- package/lib/browser/env_webworker.js +91 -4
- package/lib/core/naanlib.js +5 -5
- package/lib/env_node.js +184 -8
- package/lib/env_nodeworker.js +74 -1
- package/package.json +1 -1
- package/plugins/serviceNexara/speechrec.nlg +10 -6
- package/test/test_02_context.nlg +24 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* model.nlg
|
|
3
|
+
* Naanlib/frameworks/service
|
|
4
|
+
*
|
|
5
|
+
* Naan service model.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2023-2026 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* ServiceModel
|
|
16
|
+
*
|
|
17
|
+
* Model object for services, such as instance management. This is used to conceal architectural
|
|
18
|
+
* details from service users.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
closure ServiceModel(local model) {
|
|
23
|
+
global()
|
|
24
|
+
model = new(object, this)
|
|
25
|
+
model@\.class = new(object)
|
|
26
|
+
|
|
27
|
+
// add
|
|
28
|
+
//
|
|
29
|
+
// Add a location to our model with the specified name.
|
|
30
|
+
//
|
|
31
|
+
model@\.class.add = function add(name, local node) {
|
|
32
|
+
if !string(name) || name.trim() == ""
|
|
33
|
+
throw("ServiceModel.add: invalid name")
|
|
34
|
+
node = new(object)
|
|
35
|
+
node.id = name
|
|
36
|
+
node.parent = self
|
|
37
|
+
node@\.parent = self
|
|
38
|
+
self[name] = node
|
|
39
|
+
node
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// children
|
|
43
|
+
//
|
|
44
|
+
// List the ids of the children of the specified location, which is false for the root.
|
|
45
|
+
//
|
|
46
|
+
model@\.class.children = function children(parent) {
|
|
47
|
+
self.*.toarray.filter(function(id) { !id.startsWith(".") })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// finis
|
|
51
|
+
|
|
52
|
+
model
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* modelInit
|
|
58
|
+
*
|
|
59
|
+
* Initialize the component.
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
function modelInit(local manifest) {
|
|
64
|
+
manifest = `(ServiceModel, modelInit)
|
|
65
|
+
|
|
66
|
+
Naan.module.build(module.id, "model", function(modobj, compobj) {
|
|
67
|
+
require("./service.nlg")
|
|
68
|
+
compobj.manifest = manifest
|
|
69
|
+
modobj.exports.ServiceModel = ServiceModel
|
|
70
|
+
})
|
|
71
|
+
} ();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* nubnode.nlg
|
|
3
|
+
* Naanlib/frameworks/service
|
|
4
|
+
*
|
|
5
|
+
* Nub for node worker access to IMP.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* NodeWorkerNub
|
|
16
|
+
*
|
|
17
|
+
* NodeWorkerNub provides an IMP interface that runs on node workers. This allows the worker to
|
|
18
|
+
* communicate with the IMP network and the main thread. The worker IMP must be created before this.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
closure NodeWorkerNub(imp, options, local nownub) {
|
|
23
|
+
global(App,js)
|
|
24
|
+
if App.workerNub
|
|
25
|
+
return (App.workerNub) // singleton
|
|
26
|
+
|
|
27
|
+
options = merge({
|
|
28
|
+
name: "NodeWorkerNub"
|
|
29
|
+
type: "node-worker-nub"
|
|
30
|
+
}, options)
|
|
31
|
+
nownub = new(object, this)
|
|
32
|
+
nownub.instanceID = imp.us.instanceID || UUID()
|
|
33
|
+
nownub.dispatcher = require("naanlib:frameworks/running/taskexec.nlg").TaskDispatcher()
|
|
34
|
+
|
|
35
|
+
// impReceive
|
|
36
|
+
//
|
|
37
|
+
// Receive a remote request and reply to it.
|
|
38
|
+
//
|
|
39
|
+
nownub.impReceive = function impReceive(message, sourceID) {
|
|
40
|
+
if message.id == "targetin"
|
|
41
|
+
nownub.dispatcher(message.data, function(reply) {
|
|
42
|
+
nownub.sender(sourceID, {
|
|
43
|
+
id: "targetout",
|
|
44
|
+
data: reply
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// impUnknown
|
|
50
|
+
//
|
|
51
|
+
// Received an unknown destination notice from the other side.
|
|
52
|
+
//
|
|
53
|
+
nownub.impUnknown = function impUnknown(unknownID, sourceID, gateway) {
|
|
54
|
+
if !gateway
|
|
55
|
+
debuglog("NodeWorkerNub.impUnknownID:", unknownID, "sourceID:", sourceID)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// message event
|
|
59
|
+
//
|
|
60
|
+
// Incoming data.
|
|
61
|
+
//
|
|
62
|
+
js.t.msgPort.on("message", function(msg) {
|
|
63
|
+
if msg.id == "naan-imp-node"
|
|
64
|
+
nownub.impconn.dispatch(new(msg.data))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// register our connects *after* the receivers are configured above
|
|
68
|
+
|
|
69
|
+
nownub.sender = imp.register(nownub, {
|
|
70
|
+
name: options.name
|
|
71
|
+
type: options.type
|
|
72
|
+
meta: options.meta || undefined
|
|
73
|
+
instanceID: nownub.instanceID
|
|
74
|
+
services: [ "naan-node-worker" ]
|
|
75
|
+
})
|
|
76
|
+
nownub.impconn = imp.requester(function(data) {
|
|
77
|
+
js.t.msgPort.postMessage({ // send to main
|
|
78
|
+
id: "naan-imp-node",
|
|
79
|
+
data: data
|
|
80
|
+
})
|
|
81
|
+
list(false, { sent: true })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// finis
|
|
85
|
+
|
|
86
|
+
App.workerNub = nownub
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* nubnoInit
|
|
92
|
+
*
|
|
93
|
+
* Initialize the component.
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
function nubnoInit(local manifest) {
|
|
98
|
+
manifest = `(NodeWorkerNub, nubnoInit)
|
|
99
|
+
|
|
100
|
+
Naan.module.build(module.id, "nubnode", function(modobj, compobj) {
|
|
101
|
+
require("./service.nlg")
|
|
102
|
+
compobj.manifest = manifest
|
|
103
|
+
modobj.exports.NodeWorkerNub = NodeWorkerNub
|
|
104
|
+
})
|
|
105
|
+
} ();
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* nubweb.nlg
|
|
3
|
+
* Naanlib/frameworks/service
|
|
4
|
+
*
|
|
5
|
+
* Nub for web worker access to IMP.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* WebWorkerNub
|
|
16
|
+
*
|
|
17
|
+
* WebWorkerNub provides an IMP interface that runs on web workers. This allows the worker to
|
|
18
|
+
* communicate with the IMP network and the main thread. The worker IMP must be created before this.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
closure WebWorkerNub(imp, options, local wonub) {
|
|
23
|
+
global(App,js)
|
|
24
|
+
if App.workerNub
|
|
25
|
+
return (App.workerNub) // singleton
|
|
26
|
+
|
|
27
|
+
options = merge({
|
|
28
|
+
name: "WebWorkerNub"
|
|
29
|
+
type: "web-worker-nub"
|
|
30
|
+
}, options)
|
|
31
|
+
wonub = new(object, this)
|
|
32
|
+
wonub.instanceID = imp.us.instanceID || UUID()
|
|
33
|
+
wonub.dispatcher = require("naanlib:frameworks/running/taskexec.nlg").TaskDispatcher()
|
|
34
|
+
|
|
35
|
+
// impReceive
|
|
36
|
+
//
|
|
37
|
+
// Receive a remote request and reply to it.
|
|
38
|
+
//
|
|
39
|
+
wonub.impReceive = function impReceive(message, sourceID) {
|
|
40
|
+
if message.id == "targetin"
|
|
41
|
+
wonub.dispatcher(message.data, function(reply) {
|
|
42
|
+
wonub.sender(sourceID, {
|
|
43
|
+
id: "targetout",
|
|
44
|
+
data: reply
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// impUnknown
|
|
50
|
+
//
|
|
51
|
+
// Received an unknown destination notice from the other side.
|
|
52
|
+
//
|
|
53
|
+
wonub.impUnknown = function impUnknown(unknownID, sourceID, gateway) {
|
|
54
|
+
if !gateway
|
|
55
|
+
debuglog("WebWorkerNub.impUnknownID:", unknownID, "sourceID:", sourceID)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// message event
|
|
59
|
+
//
|
|
60
|
+
// Incoming data.
|
|
61
|
+
//
|
|
62
|
+
js.w.addEventListener("message", function message(e, local msg) {
|
|
63
|
+
msg = new(e.data)
|
|
64
|
+
if msg.scope == "naan-imp-web"
|
|
65
|
+
wonub.impconn.dispatch(msg.data)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// register our connects *after* the receivers are configured above
|
|
69
|
+
|
|
70
|
+
wonub.sender = imp.register(wonub, {
|
|
71
|
+
name: options.name
|
|
72
|
+
type: options.type
|
|
73
|
+
meta: options.meta || undefined
|
|
74
|
+
instanceID: wonub.instanceID
|
|
75
|
+
services: [ "naan-web-worker" ]
|
|
76
|
+
})
|
|
77
|
+
wonub.impconn = imp.requester(function(data) {
|
|
78
|
+
js.w.postMessage({ // send to main
|
|
79
|
+
scope: "naan-imp-web",
|
|
80
|
+
data: data
|
|
81
|
+
})
|
|
82
|
+
list(false, { sent: true })
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// finis
|
|
86
|
+
|
|
87
|
+
App.workerNub = wonub
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* nubweInit
|
|
93
|
+
*
|
|
94
|
+
* Initialize the component.
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
function nubweInit(local manifest) {
|
|
99
|
+
manifest = `(WebWorkerNub, nubweInit)
|
|
100
|
+
|
|
101
|
+
Naan.module.build(module.id, "nubweb", function(modobj, compobj) {
|
|
102
|
+
require("./service.nlg")
|
|
103
|
+
compobj.manifest = manifest
|
|
104
|
+
modobj.exports.WebWorkerNub = WebWorkerNub
|
|
105
|
+
})
|
|
106
|
+
} ();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* service.nlg
|
|
3
|
+
* Naanlib/frameworks/service
|
|
4
|
+
*
|
|
5
|
+
* Root component for services functionality.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* svcInit
|
|
16
|
+
*
|
|
17
|
+
* Initialize the service module.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function svcInit(local manifest) {
|
|
22
|
+
manifest = `(svcInit)
|
|
23
|
+
|
|
24
|
+
Naan.module.build(module.id, "service", function(modobj, compobj) {
|
|
25
|
+
require("../common/common.nlg").LiveImport()
|
|
26
|
+
compobj.manifest = manifest
|
|
27
|
+
})
|
|
28
|
+
} ();
|
package/lib/browser/env_web.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* column positioning: // // !
|
|
8
8
|
*
|
|
9
|
-
* Copyright (c) 2017-
|
|
9
|
+
* Copyright (c) 2017-2026 by Richard C. Zulch
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -69,6 +69,7 @@ exports.NaanControllerWeb = function() {
|
|
|
69
69
|
|
|
70
70
|
var naanlib = new exports.Naanlib();
|
|
71
71
|
var dontSaveUntilWorking; // true when state loaded, must be reset to save state again
|
|
72
|
+
var dontSave; // true to avoid saving, i.e. in debugger
|
|
72
73
|
var contSelf = this; // this is us, for access within nested functions
|
|
73
74
|
exports.naancon = this; // access to this instance
|
|
74
75
|
contSelf.anaan = naanlib.js.n;
|
|
@@ -93,8 +94,8 @@ exports.NaanControllerWeb = function() {
|
|
|
93
94
|
function termTextOut(text, level) {
|
|
94
95
|
if (!text)
|
|
95
96
|
return;
|
|
96
|
-
if (termlist.length === 0) {
|
|
97
|
-
console.log(text);
|
|
97
|
+
if (termlist.length === 0) { // make sure we can see early errors
|
|
98
|
+
console.log(text.replace(/(?:\x1B[@-Z\\-_]|\x1B\[[0-?]*[ -/]*[@-~])/g, ''));
|
|
98
99
|
if (!replqueue)
|
|
99
100
|
replqueue = [];
|
|
100
101
|
replqueue.push({text:text, level:level});
|
|
@@ -137,7 +138,7 @@ exports.NaanControllerWeb = function() {
|
|
|
137
138
|
|
|
138
139
|
|
|
139
140
|
//==========================================================================
|
|
140
|
-
//
|
|
141
|
+
// Direct Terminal Interface
|
|
141
142
|
//--------------------------------------------------------------------------
|
|
142
143
|
|
|
143
144
|
//
|
|
@@ -170,6 +171,7 @@ exports.NaanControllerWeb = function() {
|
|
|
170
171
|
if (repdex < 0)
|
|
171
172
|
termlist.push(terminal);
|
|
172
173
|
takePending(); // output all pending terminal messages
|
|
174
|
+
this.ioctl_event("term-attach", "");
|
|
173
175
|
};
|
|
174
176
|
|
|
175
177
|
//
|
|
@@ -184,6 +186,7 @@ exports.NaanControllerWeb = function() {
|
|
|
184
186
|
termlist.splice(repdex, 1);
|
|
185
187
|
if (termlist.length === 0)
|
|
186
188
|
replstate = terminal.StateSave(); // save ultimate repl state
|
|
189
|
+
this.ioctl_event("term-detach", "");
|
|
187
190
|
};
|
|
188
191
|
|
|
189
192
|
//
|
|
@@ -339,13 +342,14 @@ exports.NaanControllerWeb = function() {
|
|
|
339
342
|
function ConsoleDebugTerminal() {
|
|
340
343
|
var termSelf = this;
|
|
341
344
|
//
|
|
342
|
-
//
|
|
345
|
+
// OnMessage
|
|
343
346
|
//
|
|
344
347
|
this.OnMessage = function OnMessage(msg) {
|
|
348
|
+
var text = msg.text.replace(/(?:\x1B[@-Z\\-_]|\x1B\[[0-?]*[ -/]*[@-~])/g, '');
|
|
345
349
|
if (msg.id == "debugtext")
|
|
346
|
-
console.log("dbug-" + msg.level + " " +
|
|
350
|
+
console.log("dbug-" + msg.level + " " + text);
|
|
347
351
|
else if (msg.id == "textout")
|
|
348
|
-
console.log(
|
|
352
|
+
console.log(text);
|
|
349
353
|
};
|
|
350
354
|
//
|
|
351
355
|
// cmd
|
|
@@ -391,25 +395,31 @@ exports.NaanControllerWeb = function() {
|
|
|
391
395
|
exports.debug = debug;
|
|
392
396
|
|
|
393
397
|
//==========================================================================
|
|
394
|
-
//
|
|
398
|
+
// MessageTerminal
|
|
395
399
|
//--------------------------------------------------------------------------
|
|
396
400
|
|
|
397
|
-
function
|
|
401
|
+
function MessageTerminal(windest, origin)
|
|
398
402
|
{
|
|
399
403
|
var termSelf = this;
|
|
400
404
|
//
|
|
401
405
|
// listen for messages
|
|
402
406
|
//
|
|
403
407
|
window.addEventListener("message", function (event) {
|
|
404
|
-
if (event.origin !==
|
|
408
|
+
if (origin && event.origin !== origin)
|
|
405
409
|
return; // only talk with our peers
|
|
406
410
|
var msg = event.data;
|
|
411
|
+
if (msg.scope != "naan-env-web")
|
|
412
|
+
return;
|
|
407
413
|
if (msg.id == "interrupt")
|
|
408
414
|
contSelf.Interrupt();
|
|
409
415
|
else if (msg.id == "keyline")
|
|
410
416
|
contSelf.Return(msg.text, termSelf); // keyboard text from terminal
|
|
411
|
-
else if (msg.id == "
|
|
412
|
-
|
|
417
|
+
else if (msg.id == "typed")
|
|
418
|
+
echoTyped(msg.text);
|
|
419
|
+
else if (msg.id == "attached")
|
|
420
|
+
contSelf.Attach(messageTerm); // start using the terminal
|
|
421
|
+
else if (msg.id == "detached")
|
|
422
|
+
contSelf.Detach(messageTerm); // done using the terminal
|
|
413
423
|
else if (msg.id == "import")
|
|
414
424
|
{ // for workers
|
|
415
425
|
}
|
|
@@ -423,13 +433,16 @@ exports.NaanControllerWeb = function() {
|
|
|
423
433
|
if (debugListener)
|
|
424
434
|
debugListener(msg.data); // target received a message
|
|
425
435
|
}
|
|
436
|
+
else if (msg.id == "ioctl-event")
|
|
437
|
+
contSelf.ioctl_event(msg.msg, msg.arg);
|
|
426
438
|
});
|
|
427
439
|
|
|
428
440
|
//
|
|
429
441
|
// report messages back to opener
|
|
430
442
|
//
|
|
431
443
|
termSelf.OnMessage = function OnMessage(msg) {
|
|
432
|
-
|
|
444
|
+
msg.scope = "naan-env-web";
|
|
445
|
+
windest.postMessage(msg, origin);
|
|
433
446
|
return (msg);
|
|
434
447
|
};
|
|
435
448
|
|
|
@@ -437,7 +450,7 @@ exports.NaanControllerWeb = function() {
|
|
|
437
450
|
// report messages back to opener
|
|
438
451
|
//
|
|
439
452
|
termSelf.OnMessageOut = function OnMessageOut(data) {
|
|
440
|
-
var msg = {
|
|
453
|
+
var msg = { // target is sending debug data
|
|
441
454
|
id: "targetout",
|
|
442
455
|
data: data
|
|
443
456
|
};
|
|
@@ -448,7 +461,7 @@ exports.NaanControllerWeb = function() {
|
|
|
448
461
|
// report debug messages back to opener
|
|
449
462
|
//
|
|
450
463
|
termSelf.OnDebugOut = function OnDebugOut(data) {
|
|
451
|
-
var msg = {
|
|
464
|
+
var msg = { // target is sending debug data
|
|
452
465
|
id: "debugout",
|
|
453
466
|
data: data
|
|
454
467
|
};
|
|
@@ -459,14 +472,129 @@ exports.NaanControllerWeb = function() {
|
|
|
459
472
|
// report status back to opener
|
|
460
473
|
//
|
|
461
474
|
termSelf.OnStatus = function OnStatus(status) {
|
|
462
|
-
var msg = {
|
|
475
|
+
var msg = { // target is sending debug data
|
|
463
476
|
id: "status",
|
|
464
477
|
status: status
|
|
465
478
|
};
|
|
466
479
|
return (termSelf.OnMessage(msg));
|
|
467
480
|
};
|
|
481
|
+
|
|
482
|
+
//
|
|
483
|
+
// stub to ignore call
|
|
484
|
+
//
|
|
485
|
+
termSelf.StateSave = function StateSave() {
|
|
486
|
+
return (false);
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
//
|
|
490
|
+
// send ioctl back to terminal
|
|
491
|
+
//
|
|
492
|
+
termSelf.ioctl = function ioctl(op, arg) {
|
|
493
|
+
var msg = {
|
|
494
|
+
id: "ioctl",
|
|
495
|
+
op: op,
|
|
496
|
+
arg: arg
|
|
497
|
+
};
|
|
498
|
+
return (termSelf.OnMessage(msg));
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
listen_all.push(function(imsg, arg) {
|
|
502
|
+
var msg = { // target is sending ioctl event
|
|
503
|
+
id: "ioctl_event",
|
|
504
|
+
msg: imsg,
|
|
505
|
+
arg: arg
|
|
506
|
+
};
|
|
507
|
+
return (termSelf.OnMessage(msg));
|
|
508
|
+
});
|
|
468
509
|
}
|
|
469
510
|
|
|
511
|
+
//==========================================================================
|
|
512
|
+
// ioctl terminal control
|
|
513
|
+
//--------------------------------------------------------------------------
|
|
514
|
+
|
|
515
|
+
var listen_all = [];
|
|
516
|
+
var listeners = { };
|
|
517
|
+
var ioctl_callback;
|
|
518
|
+
|
|
519
|
+
//
|
|
520
|
+
// ioctl_open
|
|
521
|
+
//
|
|
522
|
+
// A terminal controller is now open on our instance.
|
|
523
|
+
//
|
|
524
|
+
|
|
525
|
+
this.ioctl_open = function ioctl_open(callback) {
|
|
526
|
+
ioctl_callback = callback;
|
|
527
|
+
return (true);
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
//
|
|
531
|
+
// ioctl_close
|
|
532
|
+
//
|
|
533
|
+
// The terminal controller is no longer open on our instance.
|
|
534
|
+
//
|
|
535
|
+
|
|
536
|
+
this.ioctl_close = function ioctl_close() {
|
|
537
|
+
ioctl_callback = false;
|
|
538
|
+
return (true);
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
//
|
|
542
|
+
// ioctl_event
|
|
543
|
+
//
|
|
544
|
+
// Events incoming from terminal.
|
|
545
|
+
//
|
|
546
|
+
|
|
547
|
+
this.ioctl_event = function ioctl_event(msg, arg) {
|
|
548
|
+
listen_all.forEach(function(proc) {
|
|
549
|
+
proc(msg, arg);
|
|
550
|
+
});
|
|
551
|
+
if (listeners[msg])
|
|
552
|
+
listeners[msg].forEach(function(proc) {
|
|
553
|
+
proc(msg, arg);
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
//
|
|
558
|
+
// ioctl_add_listener
|
|
559
|
+
// ioctl_remove_listener
|
|
560
|
+
//
|
|
561
|
+
// Add a listener for a terminal event.
|
|
562
|
+
//
|
|
563
|
+
|
|
564
|
+
this.ioctl_add_listener = function ioctl_add_listener(msg, proc) {
|
|
565
|
+
if (typeof(msg) != "string" || typeof(proc) != "function")
|
|
566
|
+
return (false);
|
|
567
|
+
this.ioctl_remove_listener(msg, proc);
|
|
568
|
+
if (!listeners[msg])
|
|
569
|
+
listeners[msg] = [];
|
|
570
|
+
listeners[msg].push(proc);
|
|
571
|
+
return (true);
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
this.ioctl_remove_listener = function ioctl_remove_listener(msg, proc) {
|
|
575
|
+
if (typeof(msg) != "string" || typeof(proc) != "function")
|
|
576
|
+
return (false);
|
|
577
|
+
if (listeners[msg]) {
|
|
578
|
+
var index = listeners[msg].indexOf(proc);
|
|
579
|
+
if (index >= 0)
|
|
580
|
+
listeners[msg].splice(index, 1);
|
|
581
|
+
}
|
|
582
|
+
return (true);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
//
|
|
586
|
+
// ioctl
|
|
587
|
+
//
|
|
588
|
+
// Control of terminals (and their controller.)
|
|
589
|
+
//
|
|
590
|
+
|
|
591
|
+
this.ioctl = function ioctl(op, arg) {
|
|
592
|
+
if (ioctl_callback)
|
|
593
|
+
ioctl_callback(op, arg);
|
|
594
|
+
messageTerm.ioctl(op, arg);
|
|
595
|
+
return (true);
|
|
596
|
+
};
|
|
597
|
+
|
|
470
598
|
//==========================================================================
|
|
471
599
|
// Host Environment
|
|
472
600
|
//--------------------------------------------------------------------------
|
|
@@ -501,6 +629,16 @@ exports.NaanControllerWeb = function() {
|
|
|
501
629
|
dontSaveUntilWorking = false;
|
|
502
630
|
};
|
|
503
631
|
|
|
632
|
+
//
|
|
633
|
+
// Saving
|
|
634
|
+
//
|
|
635
|
+
// Turn state saving on or off; on by default.
|
|
636
|
+
//
|
|
637
|
+
|
|
638
|
+
this.Saving = function Saving(onOff) {
|
|
639
|
+
dontSave = !onOff;
|
|
640
|
+
};
|
|
641
|
+
|
|
504
642
|
window.document.addEventListener("visibilitychange", function (e) {
|
|
505
643
|
virtualVisibilityChange();
|
|
506
644
|
if (window.document.visibilityState == "hidden") {
|
|
@@ -514,7 +652,7 @@ exports.NaanControllerWeb = function() {
|
|
|
514
652
|
statedoc.curversion = kStateCurrentVersion;
|
|
515
653
|
statedoc.firstver = kStateFirstVersion;
|
|
516
654
|
statedoc.licensee = "MIT-License";
|
|
517
|
-
statedoc.verstring = "1.
|
|
655
|
+
statedoc.verstring = "1.6.0+1";
|
|
518
656
|
statedoc.date = new Date().toISOString();
|
|
519
657
|
statedoc.prefs = prefs;
|
|
520
658
|
statedoc.naan = naanlib.saveState(false); // true to optimize, which is a bit slower
|
|
@@ -532,7 +670,7 @@ exports.NaanControllerWeb = function() {
|
|
|
532
670
|
|| statedoc.firstver > kStateCurrentVersion
|
|
533
671
|
|| statedoc.curversion < kStateFirstVersion
|
|
534
672
|
|| statedoc.licensee != "MIT-License"
|
|
535
|
-
|| statedoc.verstring != "1.
|
|
673
|
+
|| statedoc.verstring != "1.6.0+1"
|
|
536
674
|
|| !(naanstate = statedoc.naan))
|
|
537
675
|
{
|
|
538
676
|
localStorage.removeItem("NaanState_Hosted");
|
|
@@ -550,8 +688,12 @@ exports.NaanControllerWeb = function() {
|
|
|
550
688
|
localStorage.removeItem("NaanState_Hosted");
|
|
551
689
|
return (false);
|
|
552
690
|
}
|
|
691
|
+
if (dontSave)
|
|
692
|
+
return (false); // not saving right now
|
|
553
693
|
if ("nosave" in querystrings)
|
|
554
694
|
return (false);
|
|
695
|
+
if (window.opener)
|
|
696
|
+
return (false); // don't save running under NaanIDE
|
|
555
697
|
var statedoc = makeState();
|
|
556
698
|
var statestr = JSON.stringify(statedoc);
|
|
557
699
|
try {
|
|
@@ -591,7 +733,7 @@ exports.NaanControllerWeb = function() {
|
|
|
591
733
|
op: "VsiteOpen",
|
|
592
734
|
name: vsiteName,
|
|
593
735
|
naancont: contSelf,
|
|
594
|
-
title: vsiteName + " 1.
|
|
736
|
+
title: vsiteName + " 1.6.0+1"
|
|
595
737
|
});
|
|
596
738
|
}
|
|
597
739
|
} catch (e) {
|
|
@@ -605,7 +747,7 @@ exports.NaanControllerWeb = function() {
|
|
|
605
747
|
op: "VsiteClose",
|
|
606
748
|
name: vsiteName,
|
|
607
749
|
naancont: contSelf,
|
|
608
|
-
title: vsiteName + " 1.
|
|
750
|
+
title: vsiteName + " 1.6.0+1"
|
|
609
751
|
});
|
|
610
752
|
termTextOut("\x1b[90m\x1b[3m".concat("\nwindow closed", "\x1b[0m\n"));
|
|
611
753
|
}
|
|
@@ -621,7 +763,7 @@ exports.NaanControllerWeb = function() {
|
|
|
621
763
|
op: "VsiteVisibilityChange",
|
|
622
764
|
name: vsiteName,
|
|
623
765
|
naancont: contSelf,
|
|
624
|
-
title: vsiteName + " 1.
|
|
766
|
+
title: vsiteName + " 1.6.0+1",
|
|
625
767
|
hidden: window.document.visibilityState == "hidden",
|
|
626
768
|
window: window
|
|
627
769
|
});
|
|
@@ -636,8 +778,8 @@ exports.NaanControllerWeb = function() {
|
|
|
636
778
|
naanlib.banner();
|
|
637
779
|
var hostpath = window.location.origin.concat(naanlib.js.r("path").dirname(window.location.pathname));
|
|
638
780
|
naanlib.start({
|
|
639
|
-
cmd: 'App.version = "1.
|
|
640
|
-
+ 'App.cache = "
|
|
781
|
+
cmd: 'App.version = "1.6.0+1";;\r\n'
|
|
782
|
+
+ 'App.cache = "b39f039cddbcaf1570ae6008ea3bbeb6";;\r\n'
|
|
641
783
|
+ 'Naan.module.requireQuery({ naanver: App.cache });;\r\n'
|
|
642
784
|
+ 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '", { naanver: App.cache });;\r\n'
|
|
643
785
|
});
|
|
@@ -655,11 +797,11 @@ exports.NaanControllerWeb = function() {
|
|
|
655
797
|
|
|
656
798
|
if (window.opener) {
|
|
657
799
|
virtualOpen();
|
|
658
|
-
var term = new CloneDebugTerminal();
|
|
659
|
-
term.OnMessage({
|
|
660
|
-
id: "loaded"
|
|
661
|
-
});
|
|
662
800
|
}
|
|
801
|
+
var messageTerm = new MessageTerminal(window, window.origin);
|
|
802
|
+
messageTerm.OnMessage({
|
|
803
|
+
id: "loaded"
|
|
804
|
+
});
|
|
663
805
|
};
|
|
664
806
|
|
|
665
807
|
/*jshint sub:true */
|