@@ -0,0 +1,61 @@
1+-- |
2+-- Module : Streamly.Test.FileSystem.Event
3+-- Copyright : (c) 2020 Composewell Technologies
4+--
5+-- License : BSD3
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+--
10+-- Just report all events under the paths provided as arguments
11+
12+module Main (main) where
13+
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)
21+
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
29+#else
30+#error "FS Events not supported on this platform
31+#endif
32+import qualified Streamly.Internal.Memory.Array as Array
33+
34+-------------------------------------------------------------------------------
35+-- Utilities
36+-------------------------------------------------------------------------------
37+
38+toUtf8 :: MonadIO m => String -> m (Array Word8)
39+toUtf8 = Array.fromStream . Unicode.encodeUtf8 . Stream.fromList
40+
41+-------------------------------------------------------------------------------
42+-- Main
43+-------------------------------------------------------------------------------
44+
45+watchPaths :: NonEmpty (Array Word8) -> SerialT IO Event.Event
46+
47+#if defined(CABAL_OS_DARWIN)
48+watchPaths = Event.watchTrees
49+#elif defined(CABAL_OS_LINUX)
50+watchPaths = Event.watchPaths
51+#else
52+#error "Unsupported platform
53+#endif
54+
55+main :: IO ()
56+main = do
57+ args <- getArgs
58+ paths <- mapM toUtf8 args
59+
60+ watchPaths (NonEmpty.fromList paths)
61+ & Stream.mapM_ (putStrLn . Event.showEvent)