diff options
| author | slotThe <soliditsallgood@mailbox.org> | 2021-05-24 14:20:32 +0200 | 
|---|---|---|
| committer | slotThe <soliditsallgood@mailbox.org> | 2021-05-24 14:20:32 +0200 | 
| commit | d51b9d5dd6537e5369e13a9a11ae98aeadce50dd (patch) | |
| tree | 7ab9153ed41bdd594a7bb70dc4fc71f59ed54e80 /src/Xmobar | |
| parent | b0119a495884bcba252d7e79265f5e01f17b41d1 (diff) | |
| download | xmobar-d51b9d5dd6537e5369e13a9a11ae98aeadce50dd.tar.gz xmobar-d51b9d5dd6537e5369e13a9a11ae98aeadce50dd.tar.bz2 | |
NotmuchMail: Manually implement Read instance
The automatically derived read instance expects the type to be given in
record syntax; this is not what most users want.  In order to simply
specify the type via
  Run NotmuchMail "mail" [MailItem "name" "" "tag:unread"] 3000
we have to write our own Read instance.
Related: https://github.com/jaor/xmobar/issues/547
Diffstat (limited to 'src/Xmobar')
| -rw-r--r-- | src/Xmobar/Plugins/NotmuchMail.hs | 17 | 
1 files changed, 15 insertions, 2 deletions
| diff --git a/src/Xmobar/Plugins/NotmuchMail.hs b/src/Xmobar/Plugins/NotmuchMail.hs index 3da170c..3604a11 100644 --- a/src/Xmobar/Plugins/NotmuchMail.hs +++ b/src/Xmobar/Plugins/NotmuchMail.hs @@ -39,6 +39,7 @@ import Control.Concurrent.Async (mapConcurrently)  import Data.Maybe (catMaybes)  import System.Exit (ExitCode(ExitSuccess))  import System.Process (readProcessWithExitCode) +import Text.Read (Lexeme(Ident), ReadPrec, lexP, parens, prec, readPrec, reset)  -- | A 'MailItem' is a name, an address, and a query to give to @notmuch@. @@ -48,7 +49,13 @@ data MailItem = MailItem                         --   the empty string to query all indexed mail instead    , query   :: String  -- ^ Query to give to @notmuch search@    } -  deriving (Read, Show) +  deriving (Show) + +instance Read MailItem where +  readPrec :: ReadPrec MailItem +  readPrec = parens . prec 11 $ do +    Ident "MailItem" <- lexP +    MailItem <$> reset readPrec <*> reset readPrec <*> reset readPrec  -- | A full mail configuration.  data NotmuchMail = NotmuchMail @@ -56,7 +63,13 @@ data NotmuchMail = NotmuchMail    , mailItems :: [MailItem]  -- ^ 'MailItem's to check    , nmRate    :: Int         -- ^ Update frequency (in deciseconds)    } -  deriving (Read, Show) +  deriving (Show) + +instance Read NotmuchMail where +  readPrec :: ReadPrec NotmuchMail +  readPrec = parens . prec 11 $ do +    Ident "NotmuchMail" <- lexP +    NotmuchMail <$> reset readPrec <*> reset readPrec <*> reset readPrec  -- | How to execute this plugin.  instance Exec NotmuchMail where | 
