From 1735b6201137d7d12537c76230dbfa0e5d61f9e1 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 25 Nov 2016 06:59:09 -0800 Subject: [PATCH] ui: oops, watch files only with --watch flag --- hledger-ui/Hledger/UI/Main.hs | 61 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index b48b98f36..8c214fbfd 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -149,35 +149,42 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do , appDraw = \ui -> sDraw (aScreen ui) ui } - -- start one or more background jobs reporting changes in the directories of our files - -- XXX misses quick successive saves (then refuses to reload manually) - -- withManagerConf defaultConfig{confDebounce=Debounce 1000} $ \mgr -> do - eventChan <- newChan - withManager $ \mgr -> do - dbg1IO "fsnotify using polling ?" $ isPollingManager mgr - files <- mapM canonicalizePath $ map fst $ jfiles j - let directories = nub $ sort $ map takeDirectory files - dbg1IO "files" files - dbg1IO "directories to watch" directories + if not (watch_ uopts') + then + void $ defaultMain brickapp ui - forM_ directories $ \d -> watchDir - mgr - d - -- predicate: ignore changes not involving our files - (\fev -> case fev of - Added f _ -> f `elem` files - Modified f _ -> f `elem` files - Removed f _ -> f `elem` files - ) - -- action: send event to app - (\fev -> do - -- return $ dbglog "fsnotify" $ showFSNEvent fev -- not working - dbg1IO "fsnotify" $ showFSNEvent fev - writeChan eventChan FileChange - ) + else + -- start one or more background jobs reporting changes in the directories of our files + -- XXX misses quick successive saves (still ? hard to reproduce now) + -- XXX then refuses to reload manually (should be fixed now ?) + -- withManagerConf defaultConfig{confDebounce=Debounce 1000} $ \mgr -> do + withManager $ \mgr -> do + dbg1IO "fsnotify using polling ?" $ isPollingManager mgr + files <- mapM canonicalizePath $ map fst $ jfiles j + let directories = nub $ sort $ map takeDirectory files + dbg1IO "files" files + dbg1IO "directories to watch" directories - -- start the brick app. Must be inside the withManager block. - void $ customMain (mkVty def) (Just eventChan) brickapp ui + eventChan <- newChan + + forM_ directories $ \d -> watchDir + mgr + d + -- predicate: ignore changes not involving our files + (\fev -> case fev of + Added f _ -> f `elem` files + Modified f _ -> f `elem` files + Removed f _ -> f `elem` files + ) + -- action: send event to app + (\fev -> do + -- return $ dbglog "fsnotify" $ showFSNEvent fev -- not working + dbg1IO "fsnotify" $ showFSNEvent fev + writeChan eventChan FileChange + ) + + -- must be inside the withManager block + void $ customMain (mkVty def) (Just eventChan) brickapp ui showFSNEvent (Added f _) = "Added " ++ show f showFSNEvent (Modified f _) = "Modified " ++ show f