@@ -0,0 +1,61 @@
2+-- Module : Streamly.Test.FileSystem.Event
3+-- Copyright : (c) 2020 Composewell Technologies
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
10+-- Just report all events under the paths provided as arguments
12+module Main (main) where
14+import Control.Monad.IO.Class (MonadIO)
15+import Data.Function ((&))
16+import Data.List.NonEmpty (NonEmpty)
17+import Data.Word (Word8)
18+import Streamly.Internal.Memory.Array (Array)
19+import System.Environment (getArgs)
20+import Streamly (SerialT)
22+import qualified Data.List.NonEmpty as NonEmpty
23+import qualified Streamly.Data.Unicode.Stream as Unicode
24+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
25+#if defined(CABAL_OS_DARWIN)
26+import qualified Streamly.Internal.FileSystem.Event.Darwin as Event
27+#elif defined(CABAL_OS_LINUX)
28+import qualified Streamly.Internal.FileSystem.Event.Linux as Event
30+#error "FS Events not supported on this platform
32+import qualified Streamly.Internal.Memory.Array as Array
34+-------------------------------------------------------------------------------
36+-------------------------------------------------------------------------------
38+toUtf8 :: MonadIO m => String -> m (Array Word8)
39+toUtf8 = Array.fromStream . Unicode.encodeUtf8 . Stream.fromList
41+-------------------------------------------------------------------------------
43+-------------------------------------------------------------------------------
45+watchPaths :: NonEmpty (Array Word8) -> SerialT IO Event.Event
47+#if defined(CABAL_OS_DARWIN)
48+watchPaths = Event.watchTrees
49+#elif defined(CABAL_OS_LINUX)
50+watchPaths = Event.watchPaths
52+#error "Unsupported platform
58+ paths <- mapM toUtf8 args
60+ watchPaths (NonEmpty.fromList paths)
61+ & Stream.mapM_ (putStrLn . Event.showEvent)