1
0
Fork 0

Improve task notifications

This commit is contained in:
Malte Brandy 2020-01-12 02:11:43 +01:00
parent 1a09ebd4f1
commit c827c2727a
No known key found for this signature in database
GPG key ID: 226A2D41EF5378C9
2 changed files with 24 additions and 9 deletions

View file

@ -6,16 +6,26 @@
home.file = let home.file = let
functions = '' functions = ''
printMap :: HashMap Text (These Value Value) -> String printMap :: HashMap Text (These Value Value) -> String
printMap = \m -> intercalate "\n" . fmap (\(k,v) -> case v of printMap = intercalate "\n" . fmap printPair . ClassyPrelude.filter filterPairs . HM.toList
This old -> [i|-#{k}: #{printValue old}|] filterPairs = \(k,_) -> k `notElem` ["uuid","entry","modified"]
That new -> [i|+#{k}: #{printValue new}|] printPair = \(k,v) -> case v of
These old new -> [i|-#{k}: #{printValue old}\n+#{k}: #{printValue new}|]) $ ClassyPrelude.filter (\(k,_) -> k `notElem` ["uuid","entry","modified"]) $ HM.toList m This old -> [i|#{k}: -#{printValue old}|]
That new -> [i|#{k}: +#{printValue new}|]
These old new -> printDiff k old new
printDiff :: Text -> Value -> Value -> String
printDiff k (Array before) (Array after) = let
old = (V.toList before) List.\\ (V.toList after)
new = (V.toList after) List.\\ (V.toList before)
in
[i|#{k}: #{intercalate ", " ((('-':) . printValue <$> old) ++ (('+':) . printValue <$> new))}|]
printDiff k old new = [i|#{k}: +#{printValue new} -#{printValue old}|]
printValue = \case printValue = \case
String a -> a String (unpack -> a) -> if | Just (d :: UTCTime) <- parseTimeM False defaultTimeLocale "%Y%m%dT%H%M%SZ" a -> show d
Number a -> pack $ show a | otherwise -> a
Array a -> pack $ show a Number a -> show a
Object a -> pack $ show $ HM.toList a Array (fmap printValue -> a) -> intercalate "\n" a
Bool a -> pack $ show a Object a -> show $ HM.toList a
Bool a -> show a
Null -> "null" Null -> "null"
''; '';
inherit (import ../lib) writeHaskellScript unstable; inherit (import ../lib) writeHaskellScript unstable;
@ -31,6 +41,9 @@
"Control.Monad" "Control.Monad"
"Data.These" "Data.These"
"Data.HashMap.Strict as HM" "Data.HashMap.Strict as HM"
"Data.Time"
"qualified Data.Vector as V"
"qualified Data.List as List"
]; ];
on-modify = writeHaskellScript { on-modify = writeHaskellScript {
inherit imports libraries; inherit imports libraries;

View file

@ -57,6 +57,8 @@ rec {
{-# LANGUAGE ExtendedDefaultRules #-} {-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Shh import Shh
import qualified Prelude import qualified Prelude