-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathterminal.js
More file actions
33 lines (26 loc) · 739 Bytes
/
Copy pathterminal.js
File metadata and controls
33 lines (26 loc) · 739 Bytes
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
const readline = require('readline');
class Terminal {
constructor() {
this._readline = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
this._callbacks = {
'out': []
};
this._readline.on('line', line => {
for(const callback of this._callbacks['out'])
callback(line);
});
}
on(type, callback) {
if(this._callbacks[type] === undefined)
throw new Error('Undefined Terminal.on type.');
this._callbacks[type].push(callback);
}
write(line) {
console.log(line);
}
}
module.exports = Terminal;