diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-20 07:31:41 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-20 07:31:41 -0600 |
| commit | ec8130cfe1a7390e9939b311c8db39907a3f7f44 (patch) | |
| tree | f126cd7f52051e91d95035b6b29def437d1cf5b0 | |
| parent | 30fe3ab230a66f98dd8ece253bf79c61c2fbf6e1 (diff) | |
| download | emacs-wttrin-ec8130cfe1a7390e9939b311c8db39907a3f7f44.tar.gz emacs-wttrin-ec8130cfe1a7390e9939b311c8db39907a3f7f44.zip | |
feat: mode-line: show hourglass placeholder before first weather fetch
Display ⏳ with "Fetching weather..." tooltip immediately when
mode-line mode starts, so the user sees wttrin is active before
the first API response arrives.
| -rw-r--r-- | tests/test-wttrin--mode-line-update-display.el | 69 | ||||
| -rw-r--r-- | wttrin.el | 17 |
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/test-wttrin--mode-line-update-display.el b/tests/test-wttrin--mode-line-update-display.el index 0bcb154..07ab73f 100644 --- a/tests/test-wttrin--mode-line-update-display.el +++ b/tests/test-wttrin--mode-line-update-display.el @@ -221,5 +221,74 @@ (should (equal wttrin--mode-line-tooltip-data "Paris: ☀️ +61°F Clear")))) (test-wttrin--mode-line-update-display-teardown))) +;;; -------------------------------------------------------------------------- +;;; wttrin--mode-line-set-placeholder +;;; -------------------------------------------------------------------------- + +;;; Normal Cases + +(ert-deftest test-wttrin--mode-line-set-placeholder-normal-sets-mode-line-string () + "Placeholder sets wttrin-mode-line-string to non-nil." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris")) + (wttrin--mode-line-set-placeholder) + (should wttrin-mode-line-string)) + (test-wttrin--mode-line-update-display-teardown))) + +(ert-deftest test-wttrin--mode-line-set-placeholder-normal-contains-hourglass () + "Placeholder displays hourglass emoji." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris") + (wttrin-mode-line-emoji-font nil)) + (wttrin--mode-line-set-placeholder) + (should (string-match-p "⏳" (substring-no-properties wttrin-mode-line-string)))) + (test-wttrin--mode-line-update-display-teardown))) + +(ert-deftest test-wttrin--mode-line-set-placeholder-normal-has-fetching-tooltip () + "Placeholder tooltip mentions fetching weather." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris")) + (wttrin--mode-line-set-placeholder) + (let ((tooltip (get-text-property 0 'help-echo wttrin-mode-line-string))) + (should (string-match-p "Fetching" tooltip)) + (should (string-match-p "Paris" tooltip)))) + (test-wttrin--mode-line-update-display-teardown))) + +(ert-deftest test-wttrin--mode-line-set-placeholder-normal-has-local-map () + "Placeholder has mouse interaction keymap." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris")) + (wttrin--mode-line-set-placeholder) + (should (eq (get-text-property 0 'local-map wttrin-mode-line-string) + wttrin--mode-line-map))) + (test-wttrin--mode-line-update-display-teardown))) + +(ert-deftest test-wttrin--mode-line-set-placeholder-normal-replaced-by-real-data () + "Placeholder is replaced when real weather data arrives." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris") + (wttrin-mode-line-emoji-font nil)) + (wttrin--mode-line-set-placeholder) + (should (string-match-p "⏳" (substring-no-properties wttrin-mode-line-string))) + (wttrin--mode-line-update-display "Paris: ☀️ +61°F Clear") + (should-not (string-match-p "⏳" (substring-no-properties wttrin-mode-line-string)))) + (test-wttrin--mode-line-update-display-teardown))) + +;;; Boundary Cases + +(ert-deftest test-wttrin--mode-line-set-placeholder-boundary-does-not-set-tooltip-data () + "Placeholder does not contaminate tooltip data variable." + (test-wttrin--mode-line-update-display-setup) + (unwind-protect + (let ((wttrin-favorite-location "Paris")) + (wttrin--mode-line-set-placeholder) + (should-not wttrin--mode-line-tooltip-data)) + (test-wttrin--mode-line-update-display-teardown))) + (provide 'test-wttrin--mode-line-update-display) ;;; test-wttrin--mode-line-update-display.el ends here @@ -573,6 +573,21 @@ Force-refresh cache and update tooltip without opening buffer." (let ((wttrin--force-refresh t)) (wttrin--mode-line-fetch-weather)))) +(defun wttrin--mode-line-set-placeholder () + "Set a placeholder icon in the mode-line while waiting for weather data." + (let ((icon (if wttrin-mode-line-emoji-font + (propertize "⏳" + 'face (list :family wttrin-mode-line-emoji-font + :height 1.0)) + "⏳"))) + (setq wttrin-mode-line-string + (propertize (concat " " icon) + 'help-echo (format "Fetching weather for %s..." + wttrin-favorite-location) + 'mouse-face 'mode-line-highlight + 'local-map wttrin--mode-line-map))) + (force-mode-line-update t)) + (defun wttrin--mode-line-start () "Start mode-line weather display and refresh timer." (when (featurep 'wttrin-debug) @@ -580,6 +595,8 @@ Force-refresh cache and update tooltip without opening buffer." wttrin-favorite-location wttrin-mode-line-refresh-interval)) (when wttrin-favorite-location + ;; Show placeholder immediately so user knows wttrin is active + (wttrin--mode-line-set-placeholder) ;; Delay initial fetch to allow network to initialize during startup (run-at-time wttrin-mode-line-startup-delay nil #'wttrin--mode-line-fetch-weather) ;; Set up refresh timer (starts after the interval from now) |
