on de680fb help sign in
59 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-------------------------------------------------------------------------------
39toUtf8 :: MonadIO m => String -> m (Array Word8)
40toUtf8 = Array.fromStream . Unicode.encodeUtf8' . Stream.fromList
42-------------------------------------------------------------------------------
43-- Main
44-------------------------------------------------------------------------------
46watchPaths :: NonEmpty (Array Word8) -> SerialT IO Event.Event
47#if defined(CABAL_OS_LINUX)
48watchPaths = Event.watchPaths
49#else
50watchPaths = Event.watchTrees
51#endif
53main :: IO ()
54main = do
55 args <- getArgs
56 paths <- mapM toUtf8 args
58 watchPaths (NonEmpty.fromList paths)
59 & Stream.mapM_ (putStrLn . Event.showEvent)