ui: oops, watch files only with --watch flag

This commit is contained in:
Simon Michael 2016-11-25 06:59:09 -08:00
parent 8566dedc57
commit 1735b62011

View File

@ -149,35 +149,42 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do
, appDraw = \ui -> sDraw (aScreen ui) ui , appDraw = \ui -> sDraw (aScreen ui) ui
} }
-- start one or more background jobs reporting changes in the directories of our files if not (watch_ uopts')
-- XXX misses quick successive saves (then refuses to reload manually) then
-- withManagerConf defaultConfig{confDebounce=Debounce 1000} $ \mgr -> do void $ defaultMain brickapp ui
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
forM_ directories $ \d -> watchDir else
mgr -- start one or more background jobs reporting changes in the directories of our files
d -- XXX misses quick successive saves (still ? hard to reproduce now)
-- predicate: ignore changes not involving our files -- XXX then refuses to reload manually (should be fixed now ?)
(\fev -> case fev of -- withManagerConf defaultConfig{confDebounce=Debounce 1000} $ \mgr -> do
Added f _ -> f `elem` files withManager $ \mgr -> do
Modified f _ -> f `elem` files dbg1IO "fsnotify using polling ?" $ isPollingManager mgr
Removed f _ -> f `elem` files files <- mapM canonicalizePath $ map fst $ jfiles j
) let directories = nub $ sort $ map takeDirectory files
-- action: send event to app dbg1IO "files" files
(\fev -> do dbg1IO "directories to watch" directories
-- return $ dbglog "fsnotify" $ showFSNEvent fev -- not working
dbg1IO "fsnotify" $ showFSNEvent fev
writeChan eventChan FileChange
)
-- start the brick app. Must be inside the withManager block. eventChan <- newChan
void $ customMain (mkVty def) (Just eventChan) 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
)
-- must be inside the withManager block
void $ customMain (mkVty def) (Just eventChan) brickapp ui
showFSNEvent (Added f _) = "Added " ++ show f showFSNEvent (Added f _) = "Added " ++ show f
showFSNEvent (Modified f _) = "Modified " ++ show f showFSNEvent (Modified f _) = "Modified " ++ show f