-
Notifications
You must be signed in to change notification settings - Fork 1
π¨ Palette: Add visual progress bar to CLI timer #116
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 2024-05-22 - Helpful CLI Prompts | ||
| **Learning:** Even in CLI tools, users often get stuck on authentication steps (Tokens/IDs). Providing direct URLs or location hints in the prompt text significantly reduces friction compared to forcing users to consult external docs. | ||
| **Action:** When prompting for credentials in CLI tools, always include a "Where to find this" hint or direct URL. | ||
|
|
||
| ## 2024-05-23 - CLI Progress Bars | ||
| **Learning:** Using clear-line ANSI codes (`\033[K`) is significantly more robust than space-padding for overwriting CLI lines, especially when line lengths vary between updates. Visual progress bars (e.g., `[ββββ]`) provide better psychological feedback for waiting periods than simple countdowns. | ||
| **Action:** Use `\033[K` for dynamic CLI updates and favor visual bars for waits > 5 seconds. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
|
|
||
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing module docstring Warning test
Missing module docstring
Check warningCode scanning / Pylint (reported by Codacy) Missing module docstring Warning test
Missing module docstring
|
||
| import sys | ||
| from unittest.mock import MagicMock | ||
| import main | ||
|
|
||
| def test_countdown_timer_visuals(monkeypatch): | ||
| """Verify that countdown_timer writes a progress bar to stderr.""" | ||
| # Force colors on | ||
| monkeypatch.setattr(main, "USE_COLORS", True) | ||
|
|
||
| # Mock stderr | ||
| mock_stderr = MagicMock() | ||
| monkeypatch.setattr(sys, "stderr", mock_stderr) | ||
|
|
||
| # Mock time.sleep to run instantly | ||
| monkeypatch.setattr(main.time, "sleep", MagicMock()) | ||
|
|
||
| main.countdown_timer(3, "Test") | ||
|
|
||
| # Check calls | ||
| writes = [args[0] for args, _ in mock_stderr.write.call_args_list] | ||
| combined_output = "".join(writes) | ||
|
|
||
| # Check for progress bar chars | ||
| assert "β" in combined_output | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert "β" in combined_output | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert "Test" in combined_output | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert "Done!" in combined_output | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| # Check for ANSI clear line code | ||
| assert "\033[K" in combined_output | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Check noticeCode scanning / Bandit (reported by Codacy) Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| def test_countdown_timer_no_colors(monkeypatch): | ||
| """Verify that countdown_timer sleeps without writing to stderr if NO_COLOR.""" | ||
| monkeypatch.setattr(main, "USE_COLORS", False) | ||
| mock_stderr = MagicMock() | ||
| monkeypatch.setattr(sys, "stderr", mock_stderr) | ||
| mock_sleep = MagicMock() | ||
| monkeypatch.setattr(main.time, "sleep", mock_sleep) | ||
|
|
||
| main.countdown_timer(3, "Test") | ||
|
|
||
| # Should not write to stderr | ||
| mock_stderr.write.assert_not_called() | ||
| # Should call sleep exactly once with full seconds | ||
| mock_sleep.assert_called_once_with(3) | ||
Check warning
Code scanning / Prospector (reported by Codacy)
Black listed name "bar" (blacklisted-name) Warning