@timmy6942025/cli-timer 1.1.5 → 1.1.7
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/README.md +9 -5
- package/package.json +1 -1
- package/src/index.js +54 -34
package/README.md
CHANGED
|
@@ -55,18 +55,16 @@ By default, timer and stopwatch output is centered in the terminal.
|
|
|
55
55
|
|
|
56
56
|
You can view and set the ASCII font style used for the timer and stopwatch display.
|
|
57
57
|
|
|
58
|
-
To list
|
|
58
|
+
To list timer-compatible fonts (recommended):
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
61
|
timer style
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
To list only timer-compatible fonts (fonts that render `00:00:00` visibly):
|
|
64
|
+
To list every figlet font:
|
|
67
65
|
|
|
68
66
|
```bash
|
|
69
|
-
timer style --
|
|
67
|
+
timer style --all
|
|
70
68
|
```
|
|
71
69
|
|
|
72
70
|
To set your preferred font:
|
|
@@ -107,6 +105,8 @@ This launches a Bubble Tea based screen where you can change:
|
|
|
107
105
|
- Restart key
|
|
108
106
|
- Exit key / exit alt key
|
|
109
107
|
|
|
108
|
+
The settings UI font picker now shows timer-compatible fonts only.
|
|
109
|
+
|
|
110
110
|
Controls in settings UI:
|
|
111
111
|
|
|
112
112
|
- `Enter`: select/toggle
|
|
@@ -116,3 +116,7 @@ Controls in settings UI:
|
|
|
116
116
|
- `Esc`/`q`: back/cancel
|
|
117
117
|
|
|
118
118
|
Note for macOS: If system notifications are inconsistent with built-in AppleScript notifications, install `terminal-notifier` (`brew install terminal-notifier`) for improved reliability.
|
|
119
|
+
|
|
120
|
+
Notification notes by platform:
|
|
121
|
+
- Windows: notifications depend on OS notification permissions and whether your desktop session allows toasts/balloons.
|
|
122
|
+
- Linux: notifications require a running desktop notification daemon (`notify-send` talks to that daemon over D-Bus).
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,7 +10,8 @@ const CONFIG_DIR = path.join(os.homedir(), ".cli-timer");
|
|
|
10
10
|
const CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
11
11
|
const SETTINGS_STATE_PATH = path.join(CONFIG_DIR, "settings-state.json");
|
|
12
12
|
const DEFAULT_FONT = "Standard";
|
|
13
|
-
const TIMER_SAMPLE_TEXT = "
|
|
13
|
+
const TIMER_SAMPLE_TEXT = "01:23:45";
|
|
14
|
+
const MIN_FIGLET_WIDTH = 120;
|
|
14
15
|
|
|
15
16
|
const MIN_TICK_RATE_MS = 50;
|
|
16
17
|
const MAX_TICK_RATE_MS = 1000;
|
|
@@ -86,12 +87,16 @@ function hasVisibleGlyphs(text) {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
function renderWithFont(text, fontName) {
|
|
90
|
+
const width = Number.isFinite(process.stdout.columns)
|
|
91
|
+
? Math.max(MIN_FIGLET_WIDTH, Math.floor(process.stdout.columns))
|
|
92
|
+
: MIN_FIGLET_WIDTH;
|
|
93
|
+
|
|
89
94
|
try {
|
|
90
95
|
return figlet.textSync(text, {
|
|
91
96
|
font: fontName,
|
|
92
97
|
horizontalLayout: "fitted",
|
|
93
98
|
verticalLayout: "default",
|
|
94
|
-
width
|
|
99
|
+
width,
|
|
95
100
|
whitespaceBreak: true
|
|
96
101
|
});
|
|
97
102
|
} catch (_error) {
|
|
@@ -611,26 +616,6 @@ function sendSystemNotification({ title, message }) {
|
|
|
611
616
|
const titlePs = escapePowerShellSingleQuotedString(safeTitle);
|
|
612
617
|
const messagePs = escapePowerShellSingleQuotedString(safeMessage);
|
|
613
618
|
|
|
614
|
-
const ps = [
|
|
615
|
-
"$ErrorActionPreference = 'Stop'",
|
|
616
|
-
"try {",
|
|
617
|
-
" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null",
|
|
618
|
-
" $template = [Windows.UI.Notifications.ToastTemplateType]::ToastText02",
|
|
619
|
-
" $xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($template)",
|
|
620
|
-
" $txt = $xml.GetElementsByTagName('text')",
|
|
621
|
-
` $txt.Item(0).AppendChild($xml.CreateTextNode('${titlePs}')) > $null`,
|
|
622
|
-
` $txt.Item(1).AppendChild($xml.CreateTextNode('${messagePs}')) > $null`,
|
|
623
|
-
" $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)",
|
|
624
|
-
" $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('cli-timer')",
|
|
625
|
-
" $notifier.Show($toast)",
|
|
626
|
-
"} catch { exit 1 }"
|
|
627
|
-
].join("; ");
|
|
628
|
-
|
|
629
|
-
const powershellArgs = ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Sta", "-Command", ps];
|
|
630
|
-
if (spawnOk("powershell", powershellArgs, { windowsHide: true })) {
|
|
631
|
-
return true;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
619
|
const balloon = [
|
|
635
620
|
"$ErrorActionPreference = 'Stop'",
|
|
636
621
|
"try {",
|
|
@@ -656,13 +641,47 @@ function sendSystemNotification({ title, message }) {
|
|
|
656
641
|
"-Command",
|
|
657
642
|
balloon
|
|
658
643
|
];
|
|
659
|
-
|
|
644
|
+
if (spawnOk("powershell", balloonArgs, { windowsHide: true })) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const ps = [
|
|
649
|
+
"$ErrorActionPreference = 'Stop'",
|
|
650
|
+
"try {",
|
|
651
|
+
" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null",
|
|
652
|
+
" $template = [Windows.UI.Notifications.ToastTemplateType]::ToastText02",
|
|
653
|
+
" $xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($template)",
|
|
654
|
+
" $txt = $xml.GetElementsByTagName('text')",
|
|
655
|
+
` $txt.Item(0).AppendChild($xml.CreateTextNode('${titlePs}')) > $null`,
|
|
656
|
+
` $txt.Item(1).AppendChild($xml.CreateTextNode('${messagePs}')) > $null`,
|
|
657
|
+
" $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)",
|
|
658
|
+
" $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('cli-timer')",
|
|
659
|
+
" $notifier.Show($toast)",
|
|
660
|
+
"} catch { exit 1 }"
|
|
661
|
+
].join("; ");
|
|
662
|
+
|
|
663
|
+
const powershellArgs = ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Sta", "-Command", ps];
|
|
664
|
+
if (spawnOk("powershell", powershellArgs, { windowsHide: true })) {
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
return false;
|
|
660
668
|
}
|
|
661
669
|
|
|
662
670
|
if (process.platform === "linux") {
|
|
663
671
|
if (spawnOk("termux-notification", ["--title", safeTitle, "--content", safeMessage])) {
|
|
664
672
|
return true;
|
|
665
673
|
}
|
|
674
|
+
if (
|
|
675
|
+
spawnOk("notify-send", [
|
|
676
|
+
"--app-name=cli-timer",
|
|
677
|
+
"--urgency=critical",
|
|
678
|
+
"--icon=dialog-information",
|
|
679
|
+
safeTitle,
|
|
680
|
+
safeMessage
|
|
681
|
+
])
|
|
682
|
+
) {
|
|
683
|
+
return true;
|
|
684
|
+
}
|
|
666
685
|
if (spawnOk("notify-send", [safeTitle, safeMessage])) {
|
|
667
686
|
return true;
|
|
668
687
|
}
|
|
@@ -959,7 +978,7 @@ function runSettingsUI() {
|
|
|
959
978
|
const state = {
|
|
960
979
|
configPath: CONFIG_PATH,
|
|
961
980
|
config: readConfig(),
|
|
962
|
-
fonts:
|
|
981
|
+
fonts: getTimerCompatibleFontsSlow()
|
|
963
982
|
};
|
|
964
983
|
|
|
965
984
|
fs.writeFileSync(SETTINGS_STATE_PATH, JSON.stringify(state), "utf8");
|
|
@@ -1026,7 +1045,7 @@ function printUsage() {
|
|
|
1026
1045
|
process.stdout.write(" Keybindings are customizable in `timer settings`.\n\n");
|
|
1027
1046
|
process.stdout.write("Font Styles\n");
|
|
1028
1047
|
process.stdout.write(" timer style\n");
|
|
1029
|
-
process.stdout.write(" timer style --
|
|
1048
|
+
process.stdout.write(" timer style --all\n");
|
|
1030
1049
|
process.stdout.write(" timer style <font>\n");
|
|
1031
1050
|
}
|
|
1032
1051
|
|
|
@@ -1048,28 +1067,29 @@ function runTimer(args) {
|
|
|
1048
1067
|
}
|
|
1049
1068
|
|
|
1050
1069
|
if (args[0] === "style") {
|
|
1051
|
-
if (args.length === 1 || (args.length === 2 && args[1] === "--
|
|
1070
|
+
if (args.length === 1 || (args.length === 2 && args[1] === "--compatible")) {
|
|
1071
|
+
process.stdout.write("Checking font compatibility for timer digits...\n\n");
|
|
1052
1072
|
const currentFont = getFontFromConfig();
|
|
1053
|
-
const fonts =
|
|
1073
|
+
const fonts = getTimerCompatibleFontsSlow();
|
|
1054
1074
|
process.stdout.write(`Current font: ${currentFont}\n\n`);
|
|
1055
|
-
process.stdout.write("
|
|
1075
|
+
process.stdout.write("Timer-compatible fonts:\n");
|
|
1056
1076
|
for (const font of fonts) {
|
|
1057
1077
|
process.stdout.write(`${font}\n`);
|
|
1058
1078
|
}
|
|
1059
|
-
process.stdout.write("\
|
|
1060
|
-
process.stdout.write("Use `timer style <font>` to validate and set safely.\n");
|
|
1079
|
+
process.stdout.write("\nUse `timer style --all` to list every figlet font.\n");
|
|
1061
1080
|
return;
|
|
1062
1081
|
}
|
|
1063
1082
|
|
|
1064
|
-
if (args.length === 2 && args[1] === "--
|
|
1065
|
-
process.stdout.write("Checking font compatibility for timer digits...\n\n");
|
|
1083
|
+
if (args.length === 2 && args[1] === "--all") {
|
|
1066
1084
|
const currentFont = getFontFromConfig();
|
|
1067
|
-
const fonts =
|
|
1085
|
+
const fonts = getAllFonts();
|
|
1068
1086
|
process.stdout.write(`Current font: ${currentFont}\n\n`);
|
|
1069
|
-
process.stdout.write("
|
|
1087
|
+
process.stdout.write("All fonts:\n");
|
|
1070
1088
|
for (const font of fonts) {
|
|
1071
1089
|
process.stdout.write(`${font}\n`);
|
|
1072
1090
|
}
|
|
1091
|
+
process.stdout.write("\nSome fonts do not support timer digits.\n");
|
|
1092
|
+
process.stdout.write("Use `timer style` for a safe compatible list.\n");
|
|
1073
1093
|
return;
|
|
1074
1094
|
}
|
|
1075
1095
|
|