Skip to content

Commit 7b72c51

Browse files
committed
Autodetect whether running in terminal
1 parent 706736a commit 7b72c51

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/Main.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import qualified Stack.Upload as Upload
5555
import System.Environment (getArgs, getProgName)
5656
import System.Exit
5757
import System.FilePath (searchPathSeparator)
58-
import System.IO (stderr)
58+
import System.IO (hIsTerminalDevice, stderr, stdout)
5959
import System.Process.Read
6060

6161
-- | Commandline dispatcher.
@@ -66,6 +66,7 @@ main =
6666
tryRunPlugin plugins
6767
progName <- getProgName
6868
args <- getArgs
69+
isTerminal <- hIsTerminalDevice stdout
6970
execExtraHelp args
7071
dockerHelpOptName
7172
(Docker.dockerOptsParser True)
@@ -76,7 +77,8 @@ main =
7677
versionString'
7778
"stack - The Haskell Tool Stack"
7879
""
79-
(extraHelpOption progName (Docker.dockerCmdName ++ "*") dockerHelpOptName <*> globalOpts)
80+
(extraHelpOption progName (Docker.dockerCmdName ++ "*") dockerHelpOptName <*>
81+
globalOpts isTerminal)
8082
(do addCommand "build"
8183
"Build the project(s) in this directory/configuration"
8284
(buildCmd DoNothing)
@@ -681,13 +683,13 @@ dockerCleanupOpts =
681683
toDescr = map (\c -> if c == '-' then ' ' else c)
682684

683685
-- | Parser for global command-line options.
684-
globalOpts :: Parser GlobalOpts
685-
globalOpts =
686+
globalOpts :: Bool -> Parser GlobalOpts
687+
globalOpts defaultTerminal =
686688
GlobalOpts <$> logLevelOpt <*>
687689
configOptsParser False <*>
688690
optional resolverParser <*>
689691
flag
690-
True
692+
defaultTerminal
691693
False
692694
(long "no-terminal" <>
693695
help

0 commit comments

Comments
 (0)