From 078734c1a310300c8121022103f1b4ca9bd1b5f2 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 23 Feb 2023 15:55:33 +0100 Subject: Added watch command --- src/Eval.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Eval.hs') diff --git a/src/Eval.hs b/src/Eval.hs index 5b0c9d0..95f0a34 100644 --- a/src/Eval.hs +++ b/src/Eval.hs @@ -4,6 +4,7 @@ module Eval ) where import Binary +import Control.Concurrent import Control.Exception import Control.Monad.State import qualified Control.Monad.State.Strict as StrictState @@ -13,6 +14,7 @@ import Data.Function ( on ) import Data.List import qualified Data.Map as M import Data.Maybe +import Data.Time.Clock import Helper import Parser import Paths_bruijn @@ -185,6 +187,16 @@ evalCommand inp s@(EnvState env@(Environment envDefs) conf cache) = \case $ M.union (_imported cache) (_imported cache') } pure $ EnvState (Environment $ M.union env' envDefs) conf cache'' -- import => _isRepl = False + Watch path -> + let + monitor mtime = do + threadDelay 100000 + full <- fullPath path + t <- getModificationTime full + if t > mtime + then putStrLn "reload" >> evalCommand inp s (Input full) >> monitor t + else monitor t + in getCurrentTime >>= monitor Import path namespace -> do -- TODO: Merge with Input (very similar) full <- fullPath path if full `elem` _evalPaths conf -- cgit v1.2.3