From a8da209ee5d0fe44b9d704b9fc7812e4a96c1888 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 1 May 2020 09:24:15 +0200 Subject: Flameshot.Internal.Process: monoidify Callbacks --- src/Flameshot/Internal/Process.hs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Flameshot/Internal/Process.hs') diff --git a/src/Flameshot/Internal/Process.hs b/src/Flameshot/Internal/Process.hs index 47220a3..e38a145 100644 --- a/src/Flameshot/Internal/Process.hs +++ b/src/Flameshot/Internal/Process.hs @@ -36,6 +36,40 @@ data Callbacks = Callbacks , onStart :: Pid -> IO () } +instance Semigroup Callbacks where + a <> b = + Callbacks + { onOutLine = \pid s -> do + onOutLine a pid s + onOutLine b pid s + + , onErrLine = \pid s -> do + onErrLine a pid s + onErrLine b pid s + + , onError = \pid err -> do + onError a pid err + onError b pid err + + , onExit = \pid status -> do + onExit a pid status + onExit b pid status + + , onStart = \pid -> do + onStart a pid + onStart b pid + } + +instance Monoid Callbacks where + mempty = + Callbacks + { onOutLine = \_pid _s -> return () + , onErrLine = \_pid _s -> return () + , onError = \_pid _err -> return () + , onExit = \_pid _status -> return () + , onStart = \_pid -> return () + } + run :: FilePath -> [String] -> Maybe FilePath -- cgit v1.2.3