-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (41 loc) · 1.11 KB
/
app.js
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
global.WebSocket = require('websocket').w3cwebsocket
const readline = require('readline');
const Horizon = require('@horizon/client')
const horizon = Horizon();
const messages = horizon("messages");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var log = console.log;
console.log = function() {
rl.pause();
rl.output.write('\x1b[2K\r');
log.apply(console, Array.prototype.slice.call(arguments));
rl.resume();
rl._refreshLine();
}
rl.question('What is you name? \n', (name) => {
if (name) {
messages.limit(50).order("datetime").watch().subscribe((docs) => {
console.log('\033[2J');
docs.forEach((m)=>{
console.log( m.name +':', m.message)
})
})
sendMessage(name)
}
});
function sendMessage(name) {
rl.question('>', (message) => {
if (message) {
let m = {
message: message,
datetime: new Date(),
name: name
}
messages.store(m);
sendMessage(name)
}
});
}