-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Cross platform library for file creation, modification, and deletion
--   notification. This library builds upon existing libraries for
--   platform-specific Windows, Mac, and Linux filesystem event
--   notification.
@package fsnotify
@version 0.4.4.0


-- | This library does not currently report changes made to directories,
--   only files within watched directories.
--   
--   Minimal example:
--   
--   <pre>
--   {-# LANGUAGE OverloadedStrings #-} -- for FilePath literals
--   
--   import System.FSNotify
--   import Control.Concurrent (threadDelay)
--   import Control.Monad (forever)
--   
--   main =
--     withManager $ \mgr -&gt; do
--       -- start a watching job (in the background)
--       watchDir
--         mgr          -- manager
--         "."          -- directory to watch
--         (const True) -- predicate
--         print        -- action
--   
--       -- sleep forever (until interrupted)
--       forever $ threadDelay 1000000
--   </pre>
module System.FSNotify

-- | A file event reported by a file watcher. Each event contains the
--   canonical path for the file and a timestamp guaranteed to be after the
--   event occurred (timestamps represent current time when FSEvents
--   receives it from the OS and/or platform-specific Haskell modules).
data Event
Added :: FilePath -> UTCTime -> EventIsDirectory -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory
Modified :: FilePath -> UTCTime -> EventIsDirectory -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory
ModifiedAttributes :: FilePath -> UTCTime -> EventIsDirectory -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory
Removed :: FilePath -> UTCTime -> EventIsDirectory -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory

-- | Note: Linux-only
WatchedDirectoryRemoved :: FilePath -> UTCTime -> EventIsDirectory -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory

-- | Note: Linux-only
CloseWrite :: FilePath -> UTCTime -> EventIsDirectory -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory

-- | Note: Linux-only
Unknown :: FilePath -> UTCTime -> EventIsDirectory -> String -> Event
[eventPath] :: Event -> FilePath
[eventTime] :: Event -> UTCTime
[eventIsDirectory] :: Event -> EventIsDirectory
[eventString] :: Event -> String
data EventIsDirectory
IsFile :: EventIsDirectory
IsDirectory :: EventIsDirectory
type EventChannel = Chan Event

-- | An action to be performed in response to an event.
type Action = Event -> IO ()

-- | A predicate used to determine whether to act on an event.
type ActionPredicate = Event -> Bool

-- | Watch manager. You need one in order to create watching jobs.
data WatchManager

-- | Perform an IO action with a WatchManager in place. Tear down the
--   WatchManager after the action is complete.
withManager :: (WatchManager -> IO a) -> IO a

-- | Start a file watch manager. Directories can only be watched when they
--   are managed by a started watch manager. When finished watching. you
--   must release resources via <a>stopManager</a>. It is preferrable if
--   possible to use <a>withManager</a> to handle this automatically.
startManager :: IO WatchManager

-- | Stop a file watch manager. Stopping a watch manager will immediately
--   stop watching for files and free resources.
stopManager :: WatchManager -> IO ()

-- | Default configuration
--   
--   <ul>
--   <li>Uses OS watch mode (if possible) and single thread.</li>
--   </ul>
defaultConfig :: WatchConfig

-- | Watch configuration.
data WatchConfig

-- | Watch mode to use.
confWatchMode :: WatchConfig -> WatchMode

-- | Threading mode to use.
confThreadingMode :: WatchConfig -> ThreadingMode

-- | Called when a handler throws an exception.
confOnHandlerException :: WatchConfig -> SomeException -> IO ()

-- | Method of watching for changes.
data WatchMode
WatchModePoll :: Int -> WatchMode

-- | Polling interval in microseconds.
[watchModePollInterval] :: WatchMode -> Int

-- | Use OS-specific mechanisms to be notified of changes (inotify on
--   Linux, FSEvents on OSX, etc.). Not currently available on e.g. *BSD
--   and Wasm/WASI.
WatchModeOS :: WatchMode
data ThreadingMode

-- | Use a single thread for the entire <tt>Manager</tt>. Event handler
--   callbacks will run sequentially.
SingleThread :: ThreadingMode

-- | Use a single thread for each watch (i.e. each call to
--   <tt>watchDir</tt>, <tt>watchTree</tt>, etc.). Callbacks within a watch
--   will run sequentially but callbacks from different watches may be
--   interleaved.
ThreadPerWatch :: ThreadingMode

-- | Launch a separate thread for every event handler.
ThreadPerEvent :: ThreadingMode

-- | Like <a>withManager</a>, but configurable.
withManagerConf :: WatchConfig -> (WatchManager -> IO a) -> IO a

-- | Like <a>startManager</a>, but configurable.
startManagerConf :: WatchConfig -> IO WatchManager

-- | An action that cancels a watching/listening job.
type StopListening = IO ()

-- | Watch the immediate contents of a directory by committing an Action
--   for each event. Watching the immediate contents of a directory will
--   only report events associated with files within the specified
--   directory, and not files within its subdirectories.
watchDir :: WatchManager -> FilePath -> ActionPredicate -> Action -> IO StopListening

-- | Watch the immediate contents of a directory by streaming events to a
--   Chan. Watching the immediate contents of a directory will only report
--   events associated with files within the specified directory, and not
--   files within its subdirectories.
watchDirChan :: WatchManager -> FilePath -> ActionPredicate -> EventChannel -> IO StopListening

-- | Watch all the contents of a directory by committing an Action for each
--   event. Watching all the contents of a directory will report events
--   associated with files within the specified directory and its
--   subdirectories.
watchTree :: WatchManager -> FilePath -> ActionPredicate -> Action -> IO StopListening

-- | Watch all the contents of a directory by streaming events to a Chan.
--   Watching all the contents of a directory will report events associated
--   with files within the specified directory and its subdirectories.
watchTreeChan :: WatchManager -> FilePath -> ActionPredicate -> EventChannel -> IO StopListening


-- | Some additional functions on top of <a>System.FSNotify</a>.
--   
--   Example of compiling scss files with compass
--   
--   <pre>
--   compass :: WatchManager -&gt; FilePath -&gt; m ()
--   compass man dir = do
--    putStrLn $ "compass " ++ encodeString dir
--    treeExtExists man dir "scss" $ fp -&gt;
--      when ("deploy" <a>notElem</a> splitDirectories fp) $ do
--       let d = encodeString $ head (splitDirectories rel)
--       system "cd " ++ d ++ "&amp;&amp; bundle exec compass compile"
--    return ()
--   </pre>
module System.FSNotify.Devel

-- | In the given directory tree, watch for any events for files with the
--   given file extension
treeExtAny :: WatchManager -> FilePath -> Text -> (FilePath -> IO ()) -> IO StopListening

-- | In the given directory tree, watch for any <a>Added</a> and
--   <a>Modified</a> events (but ignore <a>Removed</a> events) for files
--   with the given file extension
treeExtExists :: WatchManager -> FilePath -> Text -> (FilePath -> IO ()) -> IO StopListening

-- | Turn a <a>FilePath</a> callback into an <a>Event</a> callback that
--   ignores the <a>Event</a> type and timestamp
doAllEvents :: Monad m => (FilePath -> m ()) -> Event -> m ()

-- | Turn a <a>FilePath</a> predicate into an <a>Event</a> predicate that
--   accepts any event types
allEvents :: (FilePath -> Bool) -> Event -> Bool

-- | Turn a <a>FilePath</a> predicate into an <a>Event</a> predicate that
--   accepts only <a>Added</a>, <a>Modified</a>, and
--   <a>ModifiedAttributes</a> event types
existsEvents :: (FilePath -> Bool) -> Event -> Bool
