-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatOutput.js
43 lines (34 loc) · 1.24 KB
/
formatOutput.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
import chars_5 from "./ascii.js";
function formatOutput(timeLeft, terminalWidth, terminalHeight) {
const totalSeconds = Math.floor(timeLeft / 1000);
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
let txt = ""
if (hours > 0) {
txt = `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`
} else if (minutes > 0) {
txt = `${minutes}:${seconds.toString().padStart(2, "0")}`
} else {
txt = `${seconds}`
}
// For now, only 1 or 5 height ascii output is supported
if (terminalHeight > 7) {
let converted = ["", "", "", "", ""];
for (let i = 0; i < txt.length; i++) {
const char = txt[i];
const charIndex = char === ":" ? 10 : parseInt(char);
const asciiChar = chars_5[charIndex];
const asciiLines = asciiChar.split("\n");
for (let j = 0; j < 5; j++) {
converted[j] += asciiLines[j] + " ";
}
}
if (converted[0].length > terminalWidth) {
return txt;
}
return converted.join("\n");
}
return txt;
}
export default formatOutput