-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
40 lines (31 loc) · 759 Bytes
/
Copy pathoptions.js
File metadata and controls
40 lines (31 loc) · 759 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
34
35
36
37
38
39
40
const options = {
list: [],
index: 0,
selected: ''
}
function setOptions(newValue) {
options.list = newValue;
displayOptions();
}
function setIndex(newValue) {
options.index = newValue;
displayOptions();
}
function displayOptions() {
options.selected = options.list[options.index];
process.stdout.clearLine();
process.stdout.cursorTo(0);
for (let i = 0; i < options.list.length; i++) {
i === options.index ?
process.stdout.write(`\x1b[42m${options.list[i]}\x1b[0m`)
: process.stdout.write(options.list[i]);
if (i < options.list.length - 1) {
process.stdout.write(' | ');
}
}
}
module.exports = {
options,
setOptions,
setIndex,
}