-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.js
84 lines (72 loc) · 1.77 KB
/
timer.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const fs = require('fs')
const helper = require("./helper")
const blessed = require('blessed');
// Create a screen object.
let screen = blessed.screen({
smartCSR: true,
cursor: {
artificial: true,
shape: 'line',
blink: true,
color: 'default' // null for default
}
});
screen.title = 'my window title';
// Create a box perfectly centered horizontally and vertically.
let box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: '',
tags: true,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'black',
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
function getTimeRemaining() {
let endtime = helper.readJSON("./res/time.json");
let t = endtime - Date.now()
let now = Date.now()
return {
'total': t,
'days': Math.floor(t / (1000 * 60 * 60 * 24)),
'hours': Math.floor((t / (1000 * 60 * 60)) % 24),
'minutes': Math.floor((t / 1000 / 60) % 60),
'seconds': Math.floor((t / 1000) % 60)
};
}
function initializeClock(box, screen) {
let timeinterval = setInterval(function () {
let t = getTimeRemaining();
line = helper.readJSON("./res/message.json")
if (t.total > 0)
box.setContent("{center}{red-fg}Time{/red-fg}: " + t.minutes + "m " + t.seconds + "s{/center}")
else
box.setContent("{center}{red-fg}Temps écoulé{/red-fg}{/center}")
for (let i = 0+1; i < line.length+1; i++)
box.setLine(i, line[i-1]);
screen.render();
}, 1000);
}
// Append our box to the screen.
screen.append(box);
// Quit on Escape, q, or Control-C.
screen.key(['C-c'], function (ch, key) {
return process.exit(0);
});
// Focus our element.
box.focus();
// Render the screen.
screen.render();
initializeClock(box, screen)