-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster.js
More file actions
39 lines (31 loc) · 1.1 KB
/
Copy pathmaster.js
File metadata and controls
39 lines (31 loc) · 1.1 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
/**
* Handles user interaction and calls route accordingly to it
*/
// system imports
var READLINE = require('readline');
// local imports
var MESSAGE = require(__dirname + '/utils/message.js'),
ROUTES = require(__dirname + '/routes/routes'),
CONFIG = require(__dirname + '/conf/appConf.js'),
GAME_STATE = require(__dirname + '/utils/gameState.js');
// creating a command line interface for interaction with user
var inputInterface = READLINE.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'OHAI> '
});
// startup message for user
console.log(MESSAGE.STARTUP_MESSAGE);
// attaching the listeners to our input interface's line event
inputInterface.on('line', (line) => {
// calling routes
ROUTES(line.trim(), CONFIG, GAME_STATE);
// reset prompt marker to new line
inputInterface.prompt();
});
// listener when input stream receives a <ctrl>-C input
inputInterface.on('SIGINT', () => {
inputInterface.question('Are you sure you want to exit app? ', (answer) => {
if (answer.match(/^y(es)?$/i)) inputInterface.pause();
});
});