Skip to content

Commit a6225e0

Browse files
committed
Implement test_show_habit_tracking_popup_saves_record to verify that selecting habits saves the correct record.
Implement test_show_habit_tracking_popup_cancel_does_not_save to ensure that canceling the popup does not create a record. - Utilize monkeypatching to mock file paths and user input for testing.
1 parent 18d608e commit a6225e0

File tree

14 files changed

+2917
-44
lines changed

14 files changed

+2917
-44
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ A simple, persistent way to manage your daily schedule.
1717
<td>
1818
<img src="assets/rmd_view.gif" alt="View Schedule" width="100%">
1919
</td>
20+
<td>
21+
<img src="assets/rmd_alert.gif" alt="Alert Example" width="100%">
22+
</td>
23+
<td>
24+
<img src="assets/emergency.png" alt="Alert Example" width="100%">
25+
</td>
2026
</tr>
2127
</table>
2228

@@ -90,7 +96,7 @@ alias reminder="$HOME/schedule_management/reminder"
9096
| | `reminder rm "task"` / `rm <id>` | Remove task by name or ID |
9197
| **Deadlines** | `reminder ddl` | Show deadlines with urgency status |
9298
| | `reminder ddl add "name" "MM.DD"` | Add or update a deadline |
93-
| **Habits** | `reminder track <ids...>` | Log completed habit IDs for today |
99+
| **Habits** | `reminder track [ids...]` | Log completed habits for today (opens a prompt if no IDs) |
94100

95101
> For detailed usage, refer to the [CLI Overview](https://sergiudm.github.io/schedule-everything/docs/cli/overview).
96102
@@ -105,8 +111,13 @@ reminder ddl add "Project Launch" "12.25"
105111

106112
# Track habits 1 and 2 as done for today
107113
reminder track 1 2
114+
115+
# Or use the prompt window (no IDs)
116+
reminder track
108117
```
109118

119+
Habit prompts can also be scheduled automatically via `config/settings.toml` (`[tasks].habit_prompt = "HH:MM"`).
120+
110121
---
111122

112123
## 🗺️ Roadmap
@@ -134,4 +145,4 @@ reminder track 1 2
134145

135146
## 📄 License
136147

137-
Distributed under the **MIT License**. See [LICENSE](LICENSE).
148+
Distributed under the **MIT License**. See [LICENSE](LICENSE).

README_zh.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,20 @@ alias reminder="$HOME/schedule_management/reminder"
9292
| | `reminder rm "任务"` / `rm <id>` | 按名称或 ID 删除任务 |
9393
| **截止日期** | `reminder ddl` | 显示截止日期及紧急状态 |
9494
| | `reminder ddl add "名称" "MM.DD"` | 添加或更新截止日期 |
95-
| **习惯** | `reminder track <ids...>` | 记录今天完成的习惯 ID |
95+
| **习惯** | `reminder track [ids...]` | 记录今天完成的习惯(不传 ID 会弹出窗口) |
9696

9797
### 使用示例
9898

9999
```bash
100100
# 添加高优先级任务
101101
reminder add "完成报告" 9
102+
103+
# 记录习惯(不需要输入 ID,会弹出窗口)
104+
reminder track
102105
```
103106

107+
也可以在 `config/settings.toml` 里设置自动弹窗时间:`[tasks].habit_prompt = "HH:MM"`
108+
104109
---
105110

106111
## 📄 为什么选择 TOML?
@@ -149,4 +154,4 @@ TOML 语法简洁清晰,无需处理 JSON 的括号或 YAML 的缩进问题,
149154

150155
## 📄 许可证
151156

152-
本项目采用 **MIT 许可证** 发布。详情请参见 [LICENSE](LICENSE) 文件。
157+
本项目采用 **MIT 许可证** 发布。详情请参见 [LICENSE](LICENSE) 文件。

assets/emergency.png

1.75 MB
Loading

config/habits_template.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Habit Tracking Configuration Template
22
# Define your daily habits here. Each habit has an ID and description.
3-
# Use `reminder track <id1> <id2> ...` to mark which habits you completed today.
3+
# Use `reminder track` to answer in a prompt window, or `reminder track <id1> <id2> ...` for CLI usage.
44

55
[habits]
66
# Format: habit_id = "Description"

config/settings_template.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ exercise = "运动时间到 🏃‍♂️!活动活动身体吧!"
2020

2121
[tasks]
2222
daily_urgent = ["08:31", "14:01", "17:31", "21:31"]
23+
ddl_urgent = ["08:32", "14:02", "17:32", "22:32"]
2324
daily_summary = "23:35"
25+
habit_prompt = "23:50"
2426
weekly_review = "sunday 20:00"
2527
monthly_review = "1 20:00"
2628

plans/habit_tracking_plan.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Implementation Plan: Sequential Habit Tracking
2+
3+
## Objective
4+
Change the habit tracking mechanism from a single checklist ("pop all at once") to a sequential series of questions ("one by one"). Improve the UI to look "more descent" using native macOS dialogs with clear formatting.
5+
6+
## Analysis
7+
- **Current Behavior**: Uses `choose from list` (via `choose_multiple` in `utils.py`) to show all habits in one window.
8+
- **Target Behavior**: Iterate through habits and ask yes/no questions for each.
9+
- **UI Improvement**: Use `display dialog` with the "note" icon (or similar) and distinct buttons for "Yes", "No", and "Stop".
10+
11+
## Proposed Changes
12+
13+
### 1. `src/schedule_management/utils.py`
14+
- Add a new helper function `ask_yes_no(question: str, title: str) -> bool | None`.
15+
- **macOS Implementation**:
16+
- Use `display dialog`.
17+
- **Prompt**: The habit question (e.g., "Did you read today?").
18+
- **Title**: "Habit Tracker (X/Y)" to show progress.
19+
- **Buttons**: `{"Stop", "No", "Yes"}`.
20+
- **Default Button**: "Yes".
21+
- **Cancel Button**: "Stop".
22+
- **Icon**: `note` (Standard, clean icon).
23+
- **Return**:
24+
- `True` for "Yes".
25+
- `False` for "No".
26+
- `None` for "Stop" (Cancel).
27+
28+
### 2. `src/schedule_management/reminder_macos.py`
29+
- Modify `show_habit_tracking_popup(now)`:
30+
- Load habits and sort them.
31+
- Initialize `completed_ids = []`.
32+
- Iterate through the sorted habits.
33+
- For each habit:
34+
- Construct a progress title (e.g., "Habit 1 of 5").
35+
- Call `ask_yes_no` with the habit question.
36+
- If result is `True`: Add habit ID to `completed_ids`.
37+
- If result is `False`: Continue to next.
38+
- If result is `None` (Stop): Break the loop early (saving completed ones so far).
39+
- Save the record of completed habits.
40+
41+
### 3. `src/schedule_management/reminder.py`
42+
- Modify `_prompt_completed_habits(habits)`:
43+
- Implement the same sequential logic as above to ensure the CLI command `reminder track` follows the same flow when in interactive mode.
44+
- Reuse the `ask_yes_no` utility.
45+
46+
## Code Mode Plan
47+
1. **Update `src/schedule_management/utils.py`**:
48+
- Add `ask_yes_no_macos`.
49+
- Update `ask_yes_no` dispatcher.
50+
51+
2. **Update `src/schedule_management/reminder_macos.py`**:
52+
- Rewrite `show_habit_tracking_popup` to loop through habits using `ask_yes_no`.
53+
54+
3. **Update `src/schedule_management/reminder.py`**:
55+
- Rewrite `_prompt_completed_habits` to use the sequential loop.
56+
57+
4. **Verification**:
58+
- Verify that closing the dialog or clicking "Stop" cleanly exits.
59+
- Verify that "Yes" and "No" are recorded correctly.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "schedule-management"
7-
version = "0.3.4"
7+
version = "0.4.0"
88
description = "A TOML based scheduling tool"
99
readme = "README.md"
1010
requires-python = ">=3.12"

0 commit comments

Comments
 (0)