@@ -4,7 +4,7 @@
44module Obelisk.Command.CLI where
55
66import Control.Monad.Catch (finally)
7−import Control.Monad.Reader (MonadIO, liftIO)
7+import Control.Monad.Reader (MonadIO, liftIO, reader)
88import Data.List (isInfixOf)
99import Data.Text (Text)
1010import qualified Data.Text as T
@@ -16,7 +16,7 @@ import System.IO (hFlush, hIsTerminalDevice)
1616import System.Console.ANSI
1717import System.Console.Questioner (dots1Spinner, stopIndicator)
1818
19−import Obelisk.App (MonadObelisk)
19+import Obelisk.App (MonadObelisk, _obelisk_verbose)
2020
2121-- TODO: This doesn't handle the put* line of functions below, in that: when we print anything while the
2222-- spinner is already running, it won't appear correctly in the terminal. The exception is `failWith` which
@@ -29,11 +29,15 @@ withSpinner
2929 -> m a -- ^ Action to run and wait for
3030 -> m a
3131withSpinner s e f = do
32+ verbose <- reader _obelisk_verbose
3233 isTerm <- liftIO $ hIsTerminalDevice stdout
33− -- When running in shell completion, disable the spinner. TODO: Do this using ReaderT and config.
34+ -- When running in shell completion, disable the spinner.
3435 inBashCompletion <- liftIO $ isInfixOf "completion" . unwords <$> getArgs
35− case not isTerm || inBashCompletion of
36− True -> f
36+ let spinnerDisabled = not isTerm || inBashCompletion || verbose
37+ case spinnerDisabled of
38+ True -> do
39+ putInfo $ T.pack s
40+ f
3741 False -> do
3842 spinner <- liftIO $ dots1Spinner (1000 * 200) s
3943 result <- finally f $ do
@@ -62,8 +66,8 @@ putInfo = liftIO . putMsg Level_Normal
6266putMsg :: MonadIO m => Level -> Text -> m ()
6367putMsg level s = liftIO $ do
6468 setColor level
65− T.putStrLn s
66− setSGR [Reset]
69+ finally (T.putStrLn s) $
70+ setSGR [Reset]
6771
6872setColor :: Level -> IO ()
6973setColor = \case