summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlexander 'ccntrq' Pankoff <ccntrq@screenri.de>2025-04-10 08:20:15 +0200
committerAlexander 'ccntrq' Pankoff <ccntrq@screenri.de>2025-04-14 16:21:30 +0200
commit82398b1603d139898be70af97ef9d59ba441bae0 (patch)
tree67e49854466cf540d54168f554bcc5c5c01c4cf2
parent3ac316ab1b468b97ef3230bd334a8b9b15fb80e1 (diff)
downloadxmobar-82398b1603d139898be70af97ef9d59ba441bae0.tar.gz
xmobar-82398b1603d139898be70af97ef9d59ba441bae0.tar.bz2
feat: add new PacmanUpdates plugin
the new PacmanUpdates plugin behaves similar to the ArchUpdates plugin while additionally allowing to pass in a custom error message for unknown pacman failures. The default error message of `pacman: Unknown cause of failure.` of the ArchUpdates plugin is too long for my taste. The ArchUpdates plugin was modified to delegate to the new PacmanUpdates plugin while providing the default error message and to show a deprecation notice in the zero updates case. The new name better represents the Plugin's compatibility with all pacman-based distributions, not just Arch. The docs have been updated to reflect the existence of the new plugin and to highlight the similarities between the ArchUpdates and PacmanUpdates plugins. The ArchUpdates plugin has been marked has deprecated there to.
-rw-r--r--changelog.md7
-rw-r--r--doc/plugins.org24
-rw-r--r--src/Xmobar.hs2
-rw-r--r--src/Xmobar/Plugins/ArchUpdates.hs53
-rw-r--r--src/Xmobar/Plugins/PacmanUpdates.hs43
-rw-r--r--xmobar.cabal1
6 files changed, 97 insertions, 33 deletions
diff --git a/changelog.md b/changelog.md
index 7f98bac..36f0c52 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,10 @@
+## Version 0.50 (unreleased)
+
+- New plugins: `PacmanUpdates`
+- `ArchUpdates` deprecated in favor of `PacmanUpdates`
+ - a deprecation notice will be shown to users of that plugin in the bar in
+ the zero updates case
+
## Version 0.49 (April, 2025)
- New plugins: `ArchUpdates` and `Accordion` (thanks, Enrico Maria)
diff --git a/doc/plugins.org b/doc/plugins.org
index 21a9452..6f474e1 100644
--- a/doc/plugins.org
+++ b/doc/plugins.org
@@ -1353,21 +1353,37 @@
the display of those numeric fields.
- Default template: =Up: <days>d <hours>h <minutes>m=
-*** =ArchUpdates (Zero, One, Many) Rate=
+*** =PacmanUpdates (Zero, One, Many, Error) Rate=
- - Aliases to =arch=
+ - Aliases to =pacman=
- =Zero=: a =String= to use when the system is up to date.
- =One=: a =String= to use when only one update is available.
- - =Many=: a =String= to use when several updates are available; it must contain
+ - =Many=: a =String= to use when several updates are available; it can contain
a =?= character as a placeholder for the number of updates.
+ - =Error=: a =String= to use when pacman fails for unkown reasons (e.g.
+ network error)
- Example:
#+begin_src haskell
ArchUpdates ("<fc=green>up to date</fc>",
"<fc=yellow>1 update</fc>,
- "<fc=red>? updates</fc>")
+ "<fc=red>? updates</fc>",
+ "<fc=red>!Pacman Error!</fc>")
600
#+end_src
+*** =ArchUpdates (Zero, One, Many) Rate=
+
+ - *This plugin is deprecated. Use =PacmanUpdates= instead.*
+ - Aliases to =arch=
+ - Same As:
+ #+begin_src haskell
+ PacmanUpdates (Zero,
+ One,
+ Many,
+ "pacman: Unknown cause of failure.")
+ Rate
+ #+end_src
+
*** =makeAccordion Tuning [Runnable]=
- Wraps other =Runnable= plugins and makes them all collapsible to a single string:
diff --git a/src/Xmobar.hs b/src/Xmobar.hs
index 5aa748a..664d86c 100644
--- a/src/Xmobar.hs
+++ b/src/Xmobar.hs
@@ -45,6 +45,7 @@ module Xmobar (xmobar
#endif
, module Xmobar.Plugins.NotmuchMail
, module Xmobar.Plugins.Monitors
+ , module Xmobar.Plugins.PacmanUpdates
, module Xmobar.Plugins.PipeReader
, module Xmobar.Plugins.MarqueePipeReader
, module Xmobar.Plugins.StdinReader
@@ -74,6 +75,7 @@ import Xmobar.Plugins.Mail
import Xmobar.Plugins.MBox
#endif
import Xmobar.Plugins.Monitors
+import Xmobar.Plugins.PacmanUpdates
import Xmobar.Plugins.PipeReader
import Xmobar.Plugins.StdinReader
import Xmobar.Plugins.MarqueePipeReader
diff --git a/src/Xmobar/Plugins/ArchUpdates.hs b/src/Xmobar/Plugins/ArchUpdates.hs
index f803d0f..0dcfd04 100644
--- a/src/Xmobar/Plugins/ArchUpdates.hs
+++ b/src/Xmobar/Plugins/ArchUpdates.hs
@@ -1,41 +1,36 @@
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
--- |
--- Module : Plugins.Monitors.ArchUpdates
--- Copyright : (c) 2024 Enrico Maria De Angelis
--- License : BSD-style (see LICENSE)
---
--- Maintainer : Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com>
--- Stability : unstable
--- Portability : unportable
---
--- An ArchLinux updates availablility plugin for Xmobar
---
+
-----------------------------------------------------------------------------
-module Xmobar.Plugins.ArchUpdates (ArchUpdates(..)) where
+{- |
+Module : Plugins.Monitors.ArchUpdates
+Copyright : (c) 2024 Enrico Maria De Angelis
+License : BSD-style (see LICENSE)
+
+Maintainer : Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com>
+Stability : unstable
+Portability : unportable
+
+An ArchLinux updates availablility plugin for Xmobar
+-}
+module Xmobar.Plugins.ArchUpdates (ArchUpdates (..)) where
-import System.Exit (ExitCode(..))
-import System.Process (readProcessWithExitCode)
-import Xmobar.Run.Exec
import Xmobar.Plugins.Command (Rate)
+import Xmobar.Plugins.PacmanUpdates (PacmanUpdates (PacmanUpdates))
+import Xmobar.Run.Exec
data ArchUpdates = ArchUpdates (String, String, String) Rate
deriving (Read, Show)
+intoPacmanUpdates :: ArchUpdates -> PacmanUpdates
+intoPacmanUpdates (ArchUpdates (z, o, m) r) =
+ PacmanUpdates (z <> deprecation, o, m, "pacman: Unknown cause of failure.") r
+ where
+ deprecation = " <fc=#ff0000>(<action=`xdg-open https://codeberg.org/xmobar/xmobar/pulls/723`>deprecated plugin, click here</action>)</fc>"
+
instance Exec ArchUpdates where
- alias (ArchUpdates _ _) = "arch"
- rate (ArchUpdates _ r) = r
- run (ArchUpdates (z, o, m) _) = do
- (exit, stdout, _) <- readProcessWithExitCode "checkupdates" [] ""
- return $ case exit of
- ExitFailure 2 -> z--ero updates
- ExitFailure 1 -> "pacman: Unknown cause of failure."
- ExitSuccess -> case length $ lines stdout of
- 0 -> impossible
- 1 -> o
- n -> m >>= \c -> if c == '?' then show n else pure c
- _ -> impossible
- where
- impossible = error "This is impossible based on pacman manpage"
+ alias = const "arch"
+ rate = rate . intoPacmanUpdates
+ run = run . intoPacmanUpdates
diff --git a/src/Xmobar/Plugins/PacmanUpdates.hs b/src/Xmobar/Plugins/PacmanUpdates.hs
new file mode 100644
index 0000000..1e8a8fc
--- /dev/null
+++ b/src/Xmobar/Plugins/PacmanUpdates.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE CPP #-}
+
+-----------------------------------------------------------------------------
+
+-----------------------------------------------------------------------------
+
+{- |
+Module : Plugins.Monitors.PacmanUpdates
+Copyright : (c) 2024 Enrico Maria De Angelis
+ , (c) 2025 Alexander Pankoff
+License : BSD-style (see LICENSE)
+
+Maintainer : Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com>
+Stability : unstable
+Portability : unportable
+
+A Pacman updates availablility plugin for Xmobar
+-}
+module Xmobar.Plugins.PacmanUpdates (PacmanUpdates (..)) where
+
+import System.Exit (ExitCode (..))
+import System.Process (readProcessWithExitCode)
+import Xmobar.Plugins.Command (Rate)
+import Xmobar.Run.Exec
+
+data PacmanUpdates = PacmanUpdates (String, String, String, String) Rate
+ deriving (Read, Show)
+
+instance Exec PacmanUpdates where
+ alias = const "pacman"
+ rate (PacmanUpdates _ r) = r
+ run (PacmanUpdates (z, o, m, e) _) = do
+ (exit, stdout, _) <- readProcessWithExitCode "checkupdates" [] ""
+ return $ case exit of
+ ExitFailure 2 -> z -- ero updates
+ ExitFailure 1 -> e
+ ExitSuccess -> case length $ lines stdout of
+ 0 -> impossible
+ 1 -> o
+ n -> m >>= \c -> if c == '?' then show n else pure c
+ _ -> impossible
+ where
+ impossible = error "This is impossible based on pacman manpage"
diff --git a/xmobar.cabal b/xmobar.cabal
index 6da7ea0..a413c29 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -158,6 +158,7 @@ library
Xmobar.Plugins.EWMH,
Xmobar.Plugins.HandleReader,
Xmobar.Plugins.QueueReader,
+ Xmobar.Plugins.PacmanUpdates,
Xmobar.Plugins.PipeReader,
Xmobar.Plugins.MarqueePipeReader,
Xmobar.Plugins.StdinReader,