tuidoro 0.0.2 → 0.1.0
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 +3 -6
- package/package.json +2 -2
- package/src/index.ts +3 -8
- package/src/logger.ts +5 -3
- package/src/timer.ts +0 -2
- package/src/utils.ts +10 -15
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TUIdoro
|
|
2
2
|
|
|
3
|
-
TUIdoro is a
|
|
3
|
+
TUIdoro is a minimal pomodoro timer that runs in your terminal.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
@@ -29,12 +29,9 @@ bun run build
|
|
|
29
29
|
|
|
30
30
|
## Configuration
|
|
31
31
|
|
|
32
|
-
The
|
|
32
|
+
The configuration file will be created on initial startup:
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
2. `~/.config/tuidoro/settings.json`
|
|
36
|
-
|
|
37
|
-
If the configuration file does not exist TUIdoro will launch with its [defaults](./config/settings.json).
|
|
34
|
+
`~/.config/tuidoro/settings.json`
|
|
38
35
|
|
|
39
36
|
## Contributing
|
|
40
37
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "0.1.0",
|
|
2
3
|
"name": "tuidoro",
|
|
3
|
-
"description": "A
|
|
4
|
+
"description": "A minimal pomodoro timer that runs in your terminal.",
|
|
4
5
|
"author": "b12o",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"pomodoro",
|
|
@@ -18,7 +19,6 @@
|
|
|
18
19
|
"engines": {
|
|
19
20
|
"bun": ">=1.3.0"
|
|
20
21
|
},
|
|
21
|
-
"version": "0.0.2",
|
|
22
22
|
"module": "src/index.ts",
|
|
23
23
|
"type": "module",
|
|
24
24
|
"bin": {
|
package/src/index.ts
CHANGED
|
@@ -4,18 +4,13 @@ import { createCliRenderer, RGBA } from "@opentui/core";
|
|
|
4
4
|
import { createLayout } from "./layout.js";
|
|
5
5
|
import { logger } from "./logger.js";
|
|
6
6
|
import { Timer } from "./timer.js";
|
|
7
|
-
import type {
|
|
8
|
-
import { loadConfig,
|
|
7
|
+
import type { TimerState } from "./types.js";
|
|
8
|
+
import { loadConfig, playSound } from "./utils.js";
|
|
9
9
|
|
|
10
10
|
//@ts-ignore -- this is a bun-specific file embed import that ts is not aware of
|
|
11
11
|
import toggleSound from "../assets/tuidoro_toggle.mp3" with { type: "file" };
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
config = loadConfig();
|
|
16
|
-
} catch {
|
|
17
|
-
config = loadDefaultConfig();
|
|
18
|
-
}
|
|
13
|
+
const config = await loadConfig();
|
|
19
14
|
|
|
20
15
|
const timer = new Timer(config);
|
|
21
16
|
|
package/src/logger.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { appendFileSync } from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
2
4
|
|
|
3
5
|
const levels = {
|
|
4
6
|
debug: 0,
|
|
@@ -8,11 +10,11 @@ const levels = {
|
|
|
8
10
|
};
|
|
9
11
|
|
|
10
12
|
type Level = keyof typeof levels;
|
|
11
|
-
const currentLevel: Level = (process.env.
|
|
13
|
+
const currentLevel: Level = (process.env.TUIDORO_LOG_LEVEL as Level) || "info";
|
|
12
14
|
|
|
13
15
|
function logToFile(msg: string) {
|
|
14
|
-
|
|
15
|
-
appendFileSync(
|
|
16
|
+
const logPath = path.join(os.tmpdir(), "tuidoro.log");
|
|
17
|
+
appendFileSync(logPath, `${msg}\n`);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export const logger = {
|
package/src/timer.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
validateBreakInterval,
|
|
8
8
|
validateHex,
|
|
9
9
|
validateWorkInterval,
|
|
10
|
-
getConfigPath,
|
|
11
10
|
} from "./utils.js";
|
|
12
11
|
|
|
13
12
|
//@ts-ignore -- this is a bun-specific file embed import that ts is not aware of
|
|
@@ -57,7 +56,6 @@ export class Timer {
|
|
|
57
56
|
this.isWork = true;
|
|
58
57
|
|
|
59
58
|
logger.debug("\n\n=================================\n");
|
|
60
|
-
logger.debug(`config path: ${getConfigPath()}`);
|
|
61
59
|
|
|
62
60
|
logger.debug("Initialized timer with following settings:");
|
|
63
61
|
logger.debug(`workduration (seconds): ${this.workDurationSeconds}`);
|
package/src/utils.ts
CHANGED
|
@@ -41,25 +41,20 @@ export function validateHex(hex: string) {
|
|
|
41
41
|
return /^#([0-9A-F]{3}){1,2}$/i.test(hex);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export function
|
|
45
|
-
|
|
44
|
+
export async function loadConfig(): Promise<PomodoroSettings> {
|
|
45
|
+
const configPath = path.join(
|
|
46
46
|
os.homedir(),
|
|
47
47
|
".config",
|
|
48
48
|
APP_NAME,
|
|
49
49
|
"settings.json",
|
|
50
50
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
try {
|
|
52
|
+
const rawInput = readFileSync(configPath, "utf8");
|
|
53
|
+
return JSON.parse(rawInput);
|
|
54
|
+
} catch {
|
|
55
|
+
if (!existsSync(configPath)) {
|
|
56
|
+
await Bun.write(configPath, JSON.stringify(defaultSettings, null, 2));
|
|
57
|
+
}
|
|
58
|
+
return defaultSettings;
|
|
54
59
|
}
|
|
55
|
-
return configPath;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function loadConfig(): PomodoroSettings {
|
|
59
|
-
const rawInput = readFileSync(getConfigPath(), "utf8");
|
|
60
|
-
return JSON.parse(rawInput);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function loadDefaultConfig(): PomodoroSettings {
|
|
64
|
-
return defaultSettings;
|
|
65
60
|
}
|