on master help sign in
Add VERBOSE env to disable the spinner

Run obelisk as: VERBOSE=True ob run This will disable the spinner.

commitc35b66ee22d5bb40fae125ead032c44621df4b53 authorSridhar Ratnakumar <srid@srid.ca> dateThu 10 May 2018, 18:41 (8 years ago) parent3d0188e
3 files changed+18−12
lib/command/src/Obelisk/App.hs+2−1 lib/command/src/Obelisk/Command.hs+5−4 lib/command/src/Obelisk/Command/CLI.hs+11−7
lib/command/src/Obelisk/App.hs+2−1
@@ -9,7 +9,8 @@ import Control.Monad.Reader (MonadIO, MonadReader)
99
1010-- TODO: Add configuration for logging, etc. here.
1111data Obelisk = Obelisk
12− { _obelisk_version :: String
12+ { _obelisk_verbose :: Bool
1313 }
14+ deriving (Eq, Show)
1415
1516type MonadObelisk m = (MonadReader Obelisk m, MonadIO m, MonadMask m)
lib/command/src/Obelisk/Command.hs+5−4
@@ -1,9 +1,8 @@
1−{-# LANGUAGE DeriveGeneric #-}
21{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
42{-# LANGUAGE LambdaCase #-}
53{-# LANGUAGE MultiParamTypeClasses #-}
64{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE ScopedTypeVariables #-}
76{-# LANGUAGE StaticPointers #-}
87{-# LANGUAGE TypeApplications #-}
98module Obelisk.Command where
@@ -171,8 +170,10 @@ parserPrefs = defaultPrefs
171170
172171main :: IO ()
173172main = do
174− let obeliskConfig = Obelisk "0.1"
175173 myArgs <- getArgs
174+ -- We are not passing this as cli argument (--verbose) because run-static-io does not
175+ -- pass along the cli arguments to recursive obelisks.
176+ obeliskConfig <- Obelisk . maybe False read <$> lookupEnv "VERBOSE"
176177 --TODO: We'd like to actually use the parser to determine whether to hand off,
177178 --but in the case where this implementation of 'ob' doesn't support all
178179 --arguments being passed along, this could fail. For now, we don't bother
@@ -183,7 +184,7 @@ main = do
183184 False -> return ()
184185 True -> putWarning "--no-handoff should only be passed once and as the first argument; ignoring"
185186 runReaderT (ob $ _args_command args') obeliskConfig
186− handoffAndGo as = flip runReaderT obeliskConfig (findProjectObeliskCommand ".") >>= \case
187+ handoffAndGo as = runReaderT (findProjectObeliskCommand ".") obeliskConfig >>= \case
187188 Nothing -> go as -- If not in a project, just run ourselves
188189 Just impl -> do
189190 -- Invoke the real implementation, using --no-handoff to prevent infinite recursion
lib/command/src/Obelisk/Command/CLI.hs+11−7
@@ -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