summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--changelog.md2
-rw-r--r--doc/plugins.org8
-rw-r--r--src/Xmobar/Plugins/Monitors/Weather.hs15
3 files changed, 15 insertions, 10 deletions
diff --git a/changelog.md b/changelog.md
index fe61524..2e82e6e 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,7 +1,7 @@
## Version 0.49 (unreleased)
- New plugins: `ArchUpdates` and `Accordion` (thanks, Enrico Maria)
-
+- New template variable `weatherS` for `WeatherX`.
## Version 0.48.1 (May, 2024)
diff --git a/doc/plugins.org b/doc/plugins.org
index 7453d4b..21a9452 100644
--- a/doc/plugins.org
+++ b/doc/plugins.org
@@ -1268,9 +1268,11 @@
- Works in the same way as =Weather=, but takes an additional argument,
a list of pairs from sky conditions to their replacement (typically a
unicode string or an icon specification).
- - Use the variable =skyConditionS= to display the replacement of the
- corresponding sky condition. All other =Weather= template variables
- are available as well.
+ - Use the variable =skyConditionS= or =weatherS= to display the replacement of
+ the corresponding sky condition. =weatherS= uses the string returned by
+ =weather= to look up a replacement, and, if that one is not found, it
+ looks up the value of =skyConditionS=. All other =Weather= template
+ variables are available as well.
For example:
diff --git a/src/Xmobar/Plugins/Monitors/Weather.hs b/src/Xmobar/Plugins/Monitors/Weather.hs
index e71de10..a46bb4f 100644
--- a/src/Xmobar/Plugins/Monitors/Weather.hs
+++ b/src/Xmobar/Plugins/Monitors/Weather.hs
@@ -66,6 +66,7 @@ weatherConfig = mkMConfig
, "skyCondition"
, "skyConditionS"
, "weather"
+ , "weatherS"
, "tempC"
, "tempF"
, "dewPointC"
@@ -221,22 +222,24 @@ getData station = CE.catch
errHandler :: CE.SomeException -> IO String
errHandler _ = return "<Could not retrieve data>"
-formatSk :: Eq p => [(p, p)] -> p -> p
-formatSk ((a,b):sks) sk = if a == sk then b else formatSk sks sk
-formatSk [] sk = sk
+formatSk :: Eq p => [(p, p)] -> p -> p -> p
+formatSk ((a,b):sks) sk d = if a == sk then b else formatSk sks sk d
+formatSk [] _ d = d
formatWeather
:: WeatherOpts -- ^ Formatting options from the cfg file
-> [(String,String)] -- ^ 'SkyConditionS' for 'WeatherX'
-> [WeatherInfo] -- ^ The actual weather info
-> Monitor String
-formatWeather opts sks [WI st ss y m d h (WindInfo wc wa wm wk wkh wms) v sk we tC tF dC dF r p] =
+formatWeather opts sks
+ [WI st ss y m d h (WindInfo wc wa wm wk wkh wms) v sk we tC tF dC dF r p] =
do cel <- showWithColors show tC
far <- showWithColors show tF
- let sk' = formatSk sks (map toLower sk)
+ let sk' = formatSk sks (map toLower sk) ""
we' = showWeather (weatherString opts) we
+ we'' = formatSk sks (map toLower we') sk'
parseTemplate [st, ss, y, m, d, h, wc, wa, wm, wk, wkh
- , wms, v, sk, sk', we', cel, far
+ , wms, v, sk, sk', we', we'', cel, far
, show dC, show dF, show r , show p ]
formatWeather _ _ _ = getConfigValue naString