diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 09:48:13 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 09:48:13 -0500 |
| commit | ec00dbe1c03527ec46a0faa20545a7acd382da84 (patch) | |
| tree | 268cd3af685677808654de3f775d60d7693c83ff | |
| parent | b83865a65eb744f6d36c1c672a4d83a59d6383f8 (diff) | |
| download | emacs-wttrin-ec00dbe1c03527ec46a0faa20545a7acd382da84.tar.gz emacs-wttrin-ec00dbe1c03527ec46a0faa20545a7acd382da84.zip | |
feat: add wttrin-display-options for wttr.in flag customization (closes #3)
wttr.in accepts single-character flags appended to the URL that control what the report looks like — no Follow line (F), narrow output (n), quiet mode (q), forecast horizon (0/1/2), console-glyph mode (d), and so on. Until now wttrin always used the same default report shape with no way to opt into these.
Added a `wttrin-display-options` defcustom that takes a string of concatenated flags, e.g. "0Fq" for current weather only with no Follow line and no header. The flags get appended to every request via `wttrin--build-url`. The defcustom defaults to nil so existing users see no change.
I excluded `A` and `T` from the recommended set in the docstring since wttrin needs ANSI output for the xterm-color rendering to produce the colored glyphs. The user could still pass them, but the docstring nudges them away.
Tests cover the normal cases (single, multi-flag, with and without unit system), the boundaries (nil and empty string both leave the URL unchanged from baseline, single character works), and a sanity check that the new flags slot in after the always-on `A`. Existing build-url tests stay green because they don't bind the new variable, and the default is nil.
Also added `.claude/` to .gitignore — the scheduled-tasks lockfile from local wakeup scheduling shouldn't be tracked.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.org | 11 | ||||
| -rw-r--r-- | tests/test-wttrin--build-url.el | 44 | ||||
| -rw-r--r-- | wttrin.el | 26 |
4 files changed, 81 insertions, 1 deletions
@@ -1,5 +1,6 @@ /todo.org /.ai/ +/.claude/ /.stignore /.eask/ /.coverage/ @@ -174,6 +174,17 @@ Wttrin's default is to select the unit system appropriate for the location you q (setq wttrin-unit-system nil) ;; the default of using units appropriate for the queried location. #+end_src +*** Display Options +wttr.in supports a handful of single-character flags that change what the report looks like. Concatenate them in =wttrin-display-options= and they'll be appended to every request: + +#+begin_src emacs-lisp + (setq wttrin-display-options "0Fq") ;; current weather only, no Follow line, no header + (setq wttrin-display-options "n") ;; narrow version (only day and night) + (setq wttrin-display-options nil) ;; default (all options off) +#+end_src + +The full list of flags is at https://wttr.in/:help. Skip =A= and =T= — wttrin manages ANSI output internally so the colored glyphs render correctly. + *** Cache Settings Wttrin caches weather data and refreshes it in the background. By default it refreshes every hour and keeps up to 50 entries. You can adjust both: diff --git a/tests/test-wttrin--build-url.el b/tests/test-wttrin--build-url.el index b19ede1..9bb514a 100644 --- a/tests/test-wttrin--build-url.el +++ b/tests/test-wttrin--build-url.el @@ -91,6 +91,50 @@ The @ symbol should be URL-encoded as %40." (should (string-prefix-p "https://wttr.in/" url)) (should (string-match-p "%40github\\.com" url))))) +;;; Display Options Cases + +(ert-deftest test-wttrin--build-url-normal-display-options-appended-after-A () + "Display options string is appended after the A flag." + (let ((wttrin-unit-system nil) + (wttrin-display-options "0Fq")) + (should (string= "https://wttr.in/Paris?A0Fq" + (wttrin--build-url "Paris"))))) + +(ert-deftest test-wttrin--build-url-normal-display-options-with-unit-system () + "Display options coexist with unit system, both inside the same query string." + (let ((wttrin-unit-system "m") + (wttrin-display-options "0F")) + (should (string= "https://wttr.in/Tokyo?mA0F" + (wttrin--build-url "Tokyo"))))) + +(ert-deftest test-wttrin--build-url-normal-display-options-narrow-quiet () + "Common combination: narrow + quiet." + (let ((wttrin-unit-system nil) + (wttrin-display-options "nq")) + (should (string= "https://wttr.in/SFO?Anq" + (wttrin--build-url "SFO"))))) + +(ert-deftest test-wttrin--build-url-boundary-display-options-nil-omits-flags () + "Nil display-options leaves URL unchanged from baseline." + (let ((wttrin-unit-system nil) + (wttrin-display-options nil)) + (should (string= "https://wttr.in/Paris?A" + (wttrin--build-url "Paris"))))) + +(ert-deftest test-wttrin--build-url-boundary-display-options-empty-string-omits-flags () + "Empty display-options string is treated like nil." + (let ((wttrin-unit-system nil) + (wttrin-display-options "")) + (should (string= "https://wttr.in/Paris?A" + (wttrin--build-url "Paris"))))) + +(ert-deftest test-wttrin--build-url-boundary-display-options-single-character () + "Single-character display-options works." + (let ((wttrin-unit-system nil) + (wttrin-display-options "F")) + (should (string= "https://wttr.in/London?AF" + (wttrin--build-url "London"))))) + ;;; Error Cases (ert-deftest test-wttrin--build-url-error-nil-query-signals-error () @@ -96,6 +96,29 @@ units (default)." :group 'wttrin :type 'string) +(defcustom wttrin-display-options nil + "wttr.in display option flags concatenated as a string. +Each character is a wttr.in flag, as documented at https://wttr.in/:help. +Common options: + + 0 only current weather (no forecast) + 1 current weather + today's forecast + 2 current weather + today's + tomorrow's forecast + d restrict output to standard console font glyphs + F do not show the \"Follow\" line + n narrow version (only day and night) + q quiet version (no \"Weather report\" text) + Q superquiet version (no \"Weather report\", no city name) + +Example: \"0Fq\" gives current weather only with no Follow line and no +header. Default nil means no extra options. + +Avoid \"A\" and \"T\" — wttrin manages ANSI output internally so the +xterm-color rendering produces the colored glyphs." + :group 'wttrin + :type '(choice (const :tag "None" nil) + (string :tag "Options"))) + (define-obsolete-variable-alias 'wttrin-cache-ttl 'wttrin-refresh-interval "0.3.0") @@ -271,7 +294,8 @@ Returns \"just now\" for <60s, \"X minutes ago\", \"X hours ago\", or \"X days a (concat "https://wttr.in/" (url-hexify-string query) (wttrin-additional-url-params) - "A")) + "A" + (or wttrin-display-options ""))) (defun wttrin--extract-http-status () "Return the HTTP status code from the current buffer, or nil. |
