-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (97 loc) · 2.2 KB
/
index.js
File metadata and controls
116 lines (97 loc) · 2.2 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use strict';
const blessed = require('blessed');
const contrib = require('blessed-contrib');
const csvParse = require('csv-parse/lib/sync');
const fs = require('fs');
if (!process.argv[2]) throw 'dame un archivo csv!!';
const filepath = process.argv[2];
const list = csvParse(fs.readFileSync(filepath), {
columns: true
});
// Create a screen object.
const screen = blessed.screen({
smartCSR: true
});
const logo = contrib.picture({
file: './logo.png',
cols: 25,
onReady() {
screen.render();
}
});
screen.append(logo);
// Create a box perfectly centered horizontally and vertically.
const box = blessed.box({
top: 'center',
left: 'center',
width: '50%',
height: '50%',
content: '{center}{black-bg}La timba de LaPlataJS{/black-bg}{/center}',
tags: true,
padding: 5,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'blue',
border: {
fg: '#f0f0f0'
}
}
});
const text = blessed.text({
top: 'center',
left: 'center',
parent: box,
style: {
bg: 'black',
fg: 'white'
}
});
// Append our box to the screen.
screen.append(box);
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
let speed = 1;
let block = false;
function start() {
const current = getRandom(0, list.length);
const winner = list[current];
if (speed > 200) {
box.style.bg = 'cyan';
box.setContent(
'{center}{black-bg}Tenemos un ganador!!{/black-bg}{/center}'
);
text.setContent(`${winner.Nombre} ${winner.Apellido}\n${winner.Email}`);
list.splice(current, 1);
screen.render();
speed = 1;
block = false;
return;
}
text.setContent(`${winner.Nombre} ${winner.Apellido}`);
screen.render();
speed += 5;
setTimeout(start, speed);
}
// If box is focused, handle `enter`/`return` and give us some more content.
box.key('enter', (ch, key) => {
if (block) return;
box.style.bg = 'blue';
text.setContent('Comenzando sorteo...');
screen.render();
block = true;
setTimeout(() => {
start();
}, 1500);
});
// Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], (ch, key) => {
return process.exit(0);
});
// Focus our element.
box.focus();
// Render the screen.
screen.render();