forked from brettz9/dialog-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-dialog-node.js
More file actions
52 lines (43 loc) · 1.7 KB
/
Copy pathtest-dialog-node.js
File metadata and controls
52 lines (43 loc) · 1.7 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
'use strict';
const dialogNode = require('../dialog-node');
const os = require('os');
const events = require('events');
const callback = function(exitCode, retVal, stderr){
console.log("exitCode = ", exitCode);
console.log("return value = <" + retVal + ">");
console.log("stderr = ", stderr);
console.log(os.EOL);
eventEmitter.emit('nextCall');
};
// loop through all dialogs and exit. Since dialog-node is non-modal or non blocking
// We are handling the execution in our own little pseudo event queue
const eventEmitter = new events.EventEmitter();
let ptr = 0;
const eventQueue = [
{ cmd:dialogNode.info,
args:["This dialog closes in 3 seconds", "timeout", 3, callback] },
{ cmd:dialogNode.warn,
args:["Your bank accounts just got wiped!", "Bank Account", 0, callback] },
{ cmd:dialogNode.error,
args:["Found only Windows", "Proper OS missing", 0, callback] },
{ cmd:dialogNode.question,
args:["Do you really want me to launch this rocket ?", "Launch control", 0, callback] },
{ cmd:dialogNode.entry,
args:["Dear user, what do you like about me ?", "Opinion", 0, callback] },
{ cmd:dialogNode.calendar,
args:["Date of the birth of the Universe", "The beginning", 0, callback] },
{ cmd:dialogNode.fileselect,
args:["Which file do you want to send to your boss ?", "Resignation letter", 0, callback] },
{ cmd:dialogNode.info,
args:["The end...", "Last Dialog", 3, callback] },
{ cmd:process.exit,
args:[] }
];
const evalNextFunction = function(){
/* const evalFun = */ eventQueue[ptr].cmd.apply(dialogNode, eventQueue[ptr].args);
ptr++;
}
console.log("starting test-dialog-node ...");
eventEmitter.on('nextCall', evalNextFunction);
evalNextFunction();
console.log("... test-dialog-node finished");