@timmy6942025/cli-timer 1.1.15 → 1.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +38 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -91,6 +91,22 @@ function exitAlternateScreen() {
|
|
|
91
91
|
process.stdout.write("\x1b[?1049l");
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
function disableLineWrap() {
|
|
95
|
+
process.stdout.write("\x1b[?7l");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function enableLineWrap() {
|
|
99
|
+
process.stdout.write("\x1b[?7h");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function enableMouseCapture() {
|
|
103
|
+
process.stdout.write("\x1b[?1000h\x1b[?1006h");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function disableMouseCapture() {
|
|
107
|
+
process.stdout.write("\x1b[?1000l\x1b[?1006l");
|
|
108
|
+
}
|
|
109
|
+
|
|
94
110
|
function formatHms(totalSeconds) {
|
|
95
111
|
const hours = Math.floor(totalSeconds / 3600);
|
|
96
112
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
@@ -578,6 +594,13 @@ function toDisplayLines(text) {
|
|
|
578
594
|
return lines.length > 0 ? lines : [""];
|
|
579
595
|
}
|
|
580
596
|
|
|
597
|
+
function writeFrameLines(lines) {
|
|
598
|
+
const safeLines = Array.isArray(lines) && lines.length > 0 ? lines : [""];
|
|
599
|
+
const terminalHeight = process.stdout.rows || safeLines.length;
|
|
600
|
+
const visibleLines = safeLines.slice(0, Math.max(1, terminalHeight));
|
|
601
|
+
process.stdout.write(visibleLines.join("\n"));
|
|
602
|
+
}
|
|
603
|
+
|
|
581
604
|
function writeCenteredBlock(lines) {
|
|
582
605
|
const safeLines = lines.length > 0 ? lines : [""];
|
|
583
606
|
const terminalWidth = process.stdout.columns || 120;
|
|
@@ -593,8 +616,7 @@ function writeCenteredBlock(lines) {
|
|
|
593
616
|
output += "\n".repeat(padTop);
|
|
594
617
|
}
|
|
595
618
|
output += safeLines.map((line) => `${leftPrefix}${line}`).join("\n");
|
|
596
|
-
output
|
|
597
|
-
process.stdout.write(output);
|
|
619
|
+
writeFrameLines(toDisplayLines(output));
|
|
598
620
|
}
|
|
599
621
|
|
|
600
622
|
function writeCenteredBlockWithTop(topLines, centerLines) {
|
|
@@ -617,8 +639,7 @@ function writeCenteredBlockWithTop(topLines, centerLines) {
|
|
|
617
639
|
output += "\n".repeat(padTop);
|
|
618
640
|
}
|
|
619
641
|
output += safeCenter.map((line) => `${leftPrefix}${line}`).join("\n");
|
|
620
|
-
output
|
|
621
|
-
process.stdout.write(output);
|
|
642
|
+
writeFrameLines(toDisplayLines(output));
|
|
622
643
|
}
|
|
623
644
|
|
|
624
645
|
function drawFrame({ mode, seconds, paused, config, done }) {
|
|
@@ -654,7 +675,7 @@ function drawFrame({ mode, seconds, paused, config, done }) {
|
|
|
654
675
|
writeCenteredBlockWithTop(topLines, centerLines);
|
|
655
676
|
} else {
|
|
656
677
|
const lines = [...topLines, ...centerLines];
|
|
657
|
-
|
|
678
|
+
writeFrameLines(lines);
|
|
658
679
|
}
|
|
659
680
|
}
|
|
660
681
|
|
|
@@ -967,6 +988,8 @@ function runClock({ mode, initialSeconds, config }) {
|
|
|
967
988
|
let lastDrawState = "";
|
|
968
989
|
let hasExited = false;
|
|
969
990
|
let didEnterAlternateScreen = false;
|
|
991
|
+
let didDisableLineWrap = false;
|
|
992
|
+
let didEnableMouseCapture = false;
|
|
970
993
|
|
|
971
994
|
const stdin = process.stdin;
|
|
972
995
|
|
|
@@ -1062,6 +1085,12 @@ function runClock({ mode, initialSeconds, config }) {
|
|
|
1062
1085
|
}
|
|
1063
1086
|
stdin.pause();
|
|
1064
1087
|
showCursor();
|
|
1088
|
+
if (didEnableMouseCapture) {
|
|
1089
|
+
disableMouseCapture();
|
|
1090
|
+
}
|
|
1091
|
+
if (didDisableLineWrap) {
|
|
1092
|
+
enableLineWrap();
|
|
1093
|
+
}
|
|
1065
1094
|
if (didEnterAlternateScreen) {
|
|
1066
1095
|
exitAlternateScreen();
|
|
1067
1096
|
} else {
|
|
@@ -1127,6 +1156,10 @@ function runClock({ mode, initialSeconds, config }) {
|
|
|
1127
1156
|
stdin.on("data", onKeypress);
|
|
1128
1157
|
enterAlternateScreen();
|
|
1129
1158
|
didEnterAlternateScreen = true;
|
|
1159
|
+
disableLineWrap();
|
|
1160
|
+
didDisableLineWrap = true;
|
|
1161
|
+
enableMouseCapture();
|
|
1162
|
+
didEnableMouseCapture = true;
|
|
1130
1163
|
hideCursor();
|
|
1131
1164
|
|
|
1132
1165
|
draw(true);
|