forked from keksiqc/ctrld-sync
-
Notifications
You must be signed in to change notification settings - Fork 1
π¨ Palette: Improve CLI Feedback & Formatting #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c97570b
feat: improve CLI UX with duration formatting and interactive countdowns
google-labs-jules[bot] c0c254a
Update main.py
abhimehro ddfea4d
Update main.py
abhimehro e6966f6
Address PR #190 review feedback: improve duration formatting, countdoβ¦
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.13 | ||
| 3.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Tests for the format_duration function.""" | ||
|
|
||
| import main | ||
|
|
||
|
|
||
| def test_format_duration_sub_minute(): | ||
| """Test format_duration with durations less than 60 seconds.""" | ||
| # Exact values | ||
| assert main.format_duration(0) == "0s" | ||
| assert main.format_duration(5) == "5s" | ||
| assert main.format_duration(42) == "42s" | ||
| assert main.format_duration(59) == "59s" | ||
|
|
||
| # Rounding behavior for sub-minute values | ||
| assert main.format_duration(5.4) == "5s" # Rounds down | ||
| assert main.format_duration(5.5) == "6s" # Rounds up (banker's rounding to even) | ||
| assert main.format_duration(59.4) == "59s" # Rounds down | ||
| assert main.format_duration(59.5) == "1m 00s" # Rounds to 60 -> shows as 1m 00s | ||
| assert main.format_duration(59.95) == "1m 00s" # Edge case: rounds to 60 -> 1m 00s | ||
|
|
||
|
|
||
| def test_format_duration_exact_minutes(): | ||
| """Test format_duration with exact minute values.""" | ||
| assert main.format_duration(60) == "1m 00s" | ||
| assert main.format_duration(120) == "2m 00s" | ||
| assert main.format_duration(300) == "5m 00s" | ||
| assert main.format_duration(3600) == "60m 00s" | ||
|
|
||
|
|
||
| def test_format_duration_mixed(): | ||
| """Test format_duration with minutes and seconds.""" | ||
| assert main.format_duration(65) == "1m 05s" | ||
| assert main.format_duration(125) == "2m 05s" | ||
| assert main.format_duration(185) == "3m 05s" | ||
| assert main.format_duration(305.5) == "5m 06s" # Rounds to 306 seconds = 5m 06s | ||
|
|
||
|
|
||
| def test_format_duration_rounding_boundaries(): | ||
| """Test format_duration rounding behavior at boundaries. | ||
|
|
||
| These boundary tests protect against the issue mentioned in the PR review | ||
| where 59.95s would show as "60.0s" instead of "1m 00s" due to truncation. | ||
| By rounding first, we get consistent behavior: values that round to 60+ | ||
| seconds are displayed in minutes format for clarity. | ||
| """ | ||
| # Just under a minute: should round down and stay in seconds | ||
| assert main.format_duration(59.4) == "59s" | ||
|
|
||
| # Halfway to next second at boundary: rounds to 60 -> shown as minutes | ||
| assert main.format_duration(59.5) == "1m 00s" | ||
|
|
||
| # Very close to a minute: rounds to 60 -> shown as 1m 00s (clearer than "60s") | ||
| assert main.format_duration(59.95) == "1m 00s" | ||
|
|
||
| # Just over a minute: should be in minutes format | ||
| assert main.format_duration(60.1) == "1m 00s" | ||
| assert main.format_duration(60.5) == "1m 00s" # Banker's rounding: rounds to 60 (even) | ||
| assert main.format_duration(61.5) == "1m 02s" # Banker's rounding: rounds to 62 (even) | ||
|
|
||
| # Edge cases around 2 minutes | ||
| assert main.format_duration(119.4) == "1m 59s" # Rounds down | ||
| assert main.format_duration(119.5) == "2m 00s" # Rounds up | ||
| assert main.format_duration(125.9) == "2m 06s" # Example from PR review | ||
|
|
||
|
|
||
| def test_format_duration_large_values(): | ||
| """Test format_duration with large durations.""" | ||
| assert main.format_duration(3661) == "61m 01s" | ||
| assert main.format_duration(7200) == "120m 00s" | ||
| assert main.format_duration(7325.7) == "122m 06s" # 7326 seconds = 122m 06s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this call uses
countdown_timer(), note that the current implementation writes\r...{remaining}s...without clearing the line each tick. Whenremainingdrops from 10β9 (or 100β99), terminals can show leftover characters from the previous, longer line. Consider updatingcountdown_timer()to clear the line on every update (e.g., prefix each frame with\r\033[K, similar torender_progress_bar).