on master help sign in
Merge pull request #56 from obsidiansystems/sr-disable-spinner

Disable spinner when not interactive

commitca19585210d142717d52be62501784c44840c9b6 authorRyan Trinkle <ryan.trinkle@gmail.com> dateThu 7 Jun 2018, 12:50 (8 years ago) parent4e116e038afc39
1 file changed+10−9
lib/cliapp/src/Obelisk/CliApp/Spinner.hs+10−9
lib/cliapp/src/Obelisk/CliApp/Spinner.hs+10−9
@@ -8,14 +8,14 @@ import Control.Concurrent (killThread, threadDelay)
88import Control.Monad (forM_, (>=>))
99import Control.Monad.Catch (MonadMask, mask, onException)
1010import Control.Monad.IO.Class
11−import Control.Monad.Log (logMessage)
11+import Control.Monad.Log (Severity (..), logMessage)
1212import Control.Monad.Reader (MonadIO)
1313import Data.IORef
1414import qualified Data.List as L
1515import Data.Text (Text)
1616import System.Console.ANSI (Color (Blue, Cyan, Green, Red))
1717
18−import Obelisk.CliApp.Logging (allowUserToMakeLoggingVerbose, fork)
18+import Obelisk.CliApp.Logging (allowUserToMakeLoggingVerbose, fork, putLog)
1919import Obelisk.CliApp.TerminalString (TerminalString (..), enquiryCode)
2020import Obelisk.CliApp.Types (Cli, CliConfig (..), HasCliConfig, Output (..), getCliConfig)
2121
@@ -23,22 +23,23 @@ import Obelisk.CliApp.Types (Cli, CliConfig (..), HasCliConfig, Output (..), get
2323withSpinner
2424 :: (MonadIO m, MonadMask m, Cli m, HasCliConfig m)
2525 => Text -> m a -> m a
26−withSpinner s = bracket' start cleanup . const
26+withSpinner s f = do
27+ noSpinner <- _cliConfig_noSpinner <$> getCliConfig
28+ if noSpinner
29+ then putLog Notice s >> f
30+ else bracket' run cleanup $ const f
2731 where
28− start = do
29− tids <- run
30− tid <- fork $ allowUserToMakeLoggingVerbose enquiryCode
31− pure $ tid : tids
3232 run = do
3333 -- Add this log to the spinner stack
3434 stack <- _cliConfig_spinnerStack <$> getCliConfig
3535 wasEmpty <- liftIO $ atomicModifyIORef' stack $ \old -> (TerminalString_Normal s : old, null old)
3636 if wasEmpty
3737 then do -- Fork a thread to manage output of anything on the stack
38− tid <- fork $ runSpinner spinner $ \c -> do
38+ ctrleThread <- fork $ allowUserToMakeLoggingVerbose enquiryCode
39+ spinnerThread <- fork $ runSpinner spinner $ \c -> do
3940 logs <- liftIO $ concatStack c <$> readIORef stack
4041 logMessage $ Output_Overwrite logs
41− pure [tid]
42+ pure [ctrleThread, spinnerThread]
4243 else pure []
4344 cleanup failed tids = do
4445 stack <- _cliConfig_spinnerStack <$> getCliConfig