Show a 'Done.' indicator when exiting a loop to definitely reset the terminal colour

This commit is contained in:
Tom Sydney Kerckhove 2022-10-22 20:47:07 +02:00
parent 306d105111
commit 8c7f4f44af
2 changed files with 25 additions and 21 deletions

View File

@ -22,6 +22,9 @@ putTimedChunks terminalCapabilities chunks = do
let timeChunk = fore yellow $ chunk $ T.pack $ formatTime defaultTimeLocale "%H:%M:%S" now let timeChunk = fore yellow $ chunk $ T.pack $ formatTime defaultTimeLocale "%H:%M:%S" now
putChunksLocaleWith terminalCapabilities $ timeChunk : " " : chunks ++ ["\n"] putChunksLocaleWith terminalCapabilities $ timeChunk : " " : chunks ++ ["\n"]
putDone :: TerminalCapabilities -> IO ()
putDone terminalCapabilities = putTimedChunks terminalCapabilities [indicatorChunk "Done."]
indicatorChunk :: String -> Chunk indicatorChunk :: String -> Chunk
indicatorChunk = fore cyan . chunk . T.pack . printf "%-10s" indicatorChunk = fore cyan . chunk . T.pack . printf "%-10s"

View File

@ -39,27 +39,28 @@ runFeedbackLoop = do
here <- getCurrentDir here <- getCurrentDir
mStdinFiles <- getStdinFiles here mStdinFiles <- getStdinFiles here
terminalCapabilities <- getTermCaps terminalCapabilities <- getTermCaps
forever $ do let singleIteration = do
-- We show a 'preparing' chunk before we get the settings because sometimes -- We show a 'preparing' chunk before we get the settings because sometimes
-- getting the settings can take a while, for example in big repositories. -- getting the settings can take a while, for example in big repositories.
putTimedChunks terminalCapabilities [indicatorChunk "preparing"] putTimedChunks terminalCapabilities [indicatorChunk "Preparing"]
LoopSettings {..} <- getLoopSettings LoopSettings {..} <- getLoopSettings
-- 0.1 second debouncing, 0.001 was too little -- 0.1 second debouncing, 0.001 was too little
let conf = FS.defaultConfig {confDebounce = Debounce 0.1} let conf = FS.defaultConfig {confDebounce = Debounce 0.1}
FS.withManagerConf conf $ \watchManager -> do FS.withManagerConf conf $ \watchManager -> do
eventFilter <- mkEventFilter here mStdinFiles loopSettingFilterSettings eventFilter <- mkEventFilter here mStdinFiles loopSettingFilterSettings
eventChan <- newChan eventChan <- newChan
outputChan <- newChan outputChan <- newChan
stopListeningAction <- stopListeningAction <-
FS.watchTree FS.watchTree
watchManager watchManager
(fromAbsDir here) -- Where to watch (fromAbsDir here) -- Where to watch
eventFilter eventFilter
(writeChan eventChan) (writeChan eventChan)
race_ race_
(processWorker loopSettingRunSettings eventChan outputChan) (processWorker loopSettingRunSettings eventChan outputChan)
(outputWorker terminalCapabilities loopSettingOutputSettings outputChan) (outputWorker terminalCapabilities loopSettingOutputSettings outputChan)
stopListeningAction stopListeningAction
forever singleIteration `finally` putDone terminalCapabilities
#ifdef MIN_VERSION_safe_coloured_text_terminfo #ifdef MIN_VERSION_safe_coloured_text_terminfo
getTermCaps :: IO TerminalCapabilities getTermCaps :: IO TerminalCapabilities