on beabbcc help sign in
61 lines 1.9 kB history raw
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
12module Main (main) where
14import Control.Monad.IO.Class (MonadIO)
15import Data.Function ((&))
16import Data.List.NonEmpty (NonEmpty)
17import Data.Word (Word8)
18import Streamly.Internal.Data.Array.Storable.Foreign (Array)
19import System.Environment (getArgs)
20import Streamly.Prelude (SerialT)
22import qualified Data.List.NonEmpty as NonEmpty
23import qualified Streamly.Unicode.Stream as Unicode
24import qualified Streamly.Internal.Data.Stream.IsStream as Stream
25#if defined(CABAL_OS_DARWIN)
26import qualified Streamly.Internal.FileSystem.Event.Darwin as Event
27#elif defined(CABAL_OS_LINUX)
28import qualified Streamly.Internal.FileSystem.Event.Linux as Event
29#else
30#error "FS Events not supported on this platform
31#endif
32import qualified Streamly.Internal.Data.Array.Storable.Foreign as Array
34-------------------------------------------------------------------------------
35-- Utilities
36-------------------------------------------------------------------------------
38toUtf8 :: MonadIO m => String -> m (Array Word8)
39toUtf8 = Array.fromStream . Unicode.encodeUtf8' . Stream.fromList
41-------------------------------------------------------------------------------
42-- Main
43-------------------------------------------------------------------------------
45watchPaths :: NonEmpty (Array Word8) -> SerialT IO Event.Event
47#if defined(CABAL_OS_DARWIN)
48watchPaths = Event.watchTrees
49#elif defined(CABAL_OS_LINUX)
50watchPaths = Event.watchPaths
51#else
52#error "Unsupported platform
53#endif
55main :: IO ()
56main = do
57 args <- getArgs
58 paths <- mapM toUtf8 args
60 watchPaths (NonEmpty.fromList paths)
61 & Stream.mapM_ (putStrLn . Event.showEvent)