tuidoro 0.0.2 → 0.1.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # TUIdoro
2
2
 
3
- TUIdoro is a sleek pomodoro timer that runs in your terminal.
3
+ TUIdoro is a minimal pomodoro timer that runs in your terminal.
4
4
 
5
5
  ![screenshot](./assets/screenshot1.png)
6
6
 
@@ -29,12 +29,9 @@ bun run build
29
29
 
30
30
  ## Configuration
31
31
 
32
- The priority for reading the configuration is as follows:
32
+ The configuration file will be created on initial startup:
33
33
 
34
- 1. `$TUIDORO_SETTINGS_PATH` environment variable
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.1",
2
3
  "name": "tuidoro",
3
- "description": "A sleek pomodoro timer that runs in your terminal.",
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 { PomodoroSettings, TimerState } from "./types.js";
8
- import { loadConfig, loadDefaultConfig, playSound } from "./utils.js";
7
+ import type { TimerState } from "./types.js";
8
+ import { loadConfig, playSound, isAudioAvailable } 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
- let config: PomodoroSettings;
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
 
@@ -28,6 +23,7 @@ let zenModeEnabled = config.zenMode ?? false;
28
23
 
29
24
  const {
30
25
  root,
26
+ audioAvailableContainer,
31
27
  captionContainer,
32
28
  captionText,
33
29
  timeContainer,
@@ -48,6 +44,7 @@ renderer.root.add(root);
48
44
  // initial render
49
45
  timeText.color = RGBA.fromHex(timer.activeColor);
50
46
  showHideElements();
47
+ audioAvailableContainer.visible = config.sound && !isAudioAvailable();
51
48
 
52
49
  // 250ms in order to respond fairly quickly to timer.ts updates without
53
50
  // unnecessarily re-rendering UI
package/src/layout.ts CHANGED
@@ -37,6 +37,15 @@ export function createLayout(renderer: CliRenderer, initialData: InitialData) {
37
37
  fg: RGBA.fromHex(offWhite),
38
38
  });
39
39
 
40
+ const audioAvailableText = new TextRenderable(renderer, {
41
+ id: "audioAvailable",
42
+ content:
43
+ "Can't play audio ('paplay' not installed).\
44
+ Disable 'sound' in your config or install paplay to remove this notice.",
45
+ justifyContent: "center",
46
+ fg: RGBA.fromHex(offWhite),
47
+ });
48
+
40
49
  const separator = new TextRenderable(renderer, {
41
50
  content: "_________________________________________",
42
51
  fg: RGBA.fromHex(gray),
@@ -66,6 +75,12 @@ export function createLayout(renderer: CliRenderer, initialData: InitialData) {
66
75
  fg: RGBA.fromHex(offWhite),
67
76
  });
68
77
 
78
+ const audioAvailableContainer = new BoxRenderable(renderer, {
79
+ id: "audioAvailableContainer",
80
+ border: true,
81
+ });
82
+ audioAvailableContainer.add(audioAvailableText);
83
+
69
84
  const captionContainer = new BoxRenderable(renderer, {
70
85
  id: "captionContainer",
71
86
  alignItems: "center",
@@ -119,6 +134,7 @@ export function createLayout(renderer: CliRenderer, initialData: InitialData) {
119
134
  alignItems: "center",
120
135
  justifyContent: "center",
121
136
  },
137
+ audioAvailableContainer,
122
138
  captionContainer,
123
139
  timeContainer,
124
140
  pomodoriContainer,
@@ -129,6 +145,7 @@ export function createLayout(renderer: CliRenderer, initialData: InitialData) {
129
145
 
130
146
  return {
131
147
  root,
148
+ audioAvailableContainer,
132
149
  captionContainer,
133
150
  captionText,
134
151
  timeContainer,
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.LOG_LEVEL as Level) || "info";
13
+ const currentLevel: Level = (process.env.TUIDORO_LOG_LEVEL as Level) || "info";
12
14
 
13
15
  function logToFile(msg: string) {
14
- // tuidoro is located in project root.
15
- appendFileSync("tuidoro.log", `${msg}\n`);
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}`);
@@ -178,6 +176,7 @@ export class Timer {
178
176
  this.caption = WORK_CAPTION;
179
177
  }
180
178
  notifyMessage = this.caption;
181
- notifyMessage.length > 0 && Bun.spawn(["notify-send", notifyMessage]);
179
+ if (notifyMessage.length)
180
+ Bun.spawn(["notify-send", notifyMessage], { stderr: "ignore" });
182
181
  }
183
182
  }
package/src/utils.ts CHANGED
@@ -41,25 +41,24 @@ export function validateHex(hex: string) {
41
41
  return /^#([0-9A-F]{3}){1,2}$/i.test(hex);
42
42
  }
43
43
 
44
- export function getConfigPath() {
45
- let configPath = path.join(
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
- const envPath = process.env.TUIDORO_SETTINGS_PATH;
52
- if (envPath && existsSync(envPath)) {
53
- configPath = envPath;
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
60
  }
57
61
 
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;
62
+ export function isAudioAvailable() {
63
+ return Bun.which("paplay") !== null;
65
64
  }