on a608695 help sign in
56 lines 2.0 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
11module Main (main) where
13import Control.Monad.IO.Class (MonadIO)
14import Data.Function ((&))
15import Data.List.NonEmpty (NonEmpty)
16import Data.Word (Word8)
17import System.Environment (getArgs)
18import Streamly.Prelude (SerialT)
19import Streamly.Internal.Data.Array.Storable.Foreign (Array)
21import qualified Streamly.Unicode.Stream as Unicode
22import qualified Streamly.Internal.Data.Array.Storable.Foreign as Array
23import qualified Data.List.NonEmpty as NonEmpty
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#elif defined(CABAL_OS_WINDOWS)
30import qualified Streamly.Internal.FileSystem.Event.Windows as Event
31#else
32#error "FS Events not supported on this platform
33#endif
35-------------------------------------------------------------------------------
36-- Utilities
37-------------------------------------------------------------------------------
38toUtf8 :: MonadIO m => String -> m (Array Word8)
39toUtf8 = Array.fromStream . Unicode.encodeUtf8' . Stream.fromList
41-------------------------------------------------------------------------------
42-- Main
43-------------------------------------------------------------------------------
44watchPaths :: NonEmpty (Array Word8) -> SerialT IO Event.Event
45#if defined(CABAL_OS_LINUX)
46watchPaths = Event.watchPaths
47#else
48watchPaths = Event.watchTrees
49#endif
51main :: IO ()
52main = do
53 args <- getArgs
54 paths <- mapM toUtf8 args
55 watchPaths (NonEmpty.fromList paths)
56 & Stream.mapM_ (putStrLn . Event.showEvent)