diff --git a/CHANGELOG.md b/CHANGELOG.md index 89574ee62..5954b86a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +Bugfixes: +- Color output now works correctly or is disabled on Windows (#768, #749) + +Other improvements: +- Color output is now automatically disabled when output is redirected to a file. + Also respects a [`NO_COLOR`](https://no-color.org/) environment variable (#768) + ## [0.20.0] - 2021-04-07 Breaking changes (😱!!!): diff --git a/spago.cabal b/spago.cabal index b6b593254..58998d653 100644 --- a/spago.cabal +++ b/spago.cabal @@ -139,7 +139,8 @@ executable spago default-extensions: ApplicativeDo BangPatterns BinaryLiterals ConstraintKinds DataKinds DefaultSignatures DeriveDataTypeable DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable DerivingStrategies DoAndIfThenElse DuplicateRecordFields EmptyDataDecls ExistentialQuantification FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving InstanceSigs KindSignatures LambdaCase LiberalTypeSynonyms MonadFailDesugaring MultiParamTypeClasses MultiWayIf NamedFieldPuns NoImplicitPrelude NoMonomorphismRestriction OverloadedStrings PartialTypeSignatures PatternGuards PolyKinds QuantifiedConstraints RankNTypes RecordWildCards ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications TypeFamilies TypeSynonymInstances UndecidableInstances ViewPatterns ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wredundant-constraints -fprint-potential-instances -optP-Wno-nonportable-include-path build-depends: - base >=4.7 && <5 + ansi-terminal + , base >=4.7 && <5 , spago , text <1.3 , turtle diff --git a/src/Spago/RunEnv.hs b/src/Spago/RunEnv.hs index 27f1d09ce..dfb88cdbe 100644 --- a/src/Spago/RunEnv.hs +++ b/src/Spago/RunEnv.hs @@ -3,6 +3,7 @@ module Spago.RunEnv where import Spago.Prelude import Spago.Env +import System.Console.ANSI (hSupportsANSIWithoutEmulation) import qualified System.Environment as Env import qualified Distribution.System as OS import qualified RIO @@ -20,14 +21,19 @@ import qualified Spago.Purs as Purs -- and runs the app withEnv :: GlobalOptions -> RIO Env a -> IO a withEnv GlobalOptions{..} app = do + let logHandle = stderr let verbose = not globalQuiet && (globalVerbose || globalVeryVerbose) -- https://github.com/purescript/spago/issues/579 maybeTerm <- Env.lookupEnv "TERM" let termDumb = maybeTerm == Just "dumb" || maybeTerm == Just "win" - let useColor = globalUseColor && not termDumb + -- Check if the terminal supports color. On Windows 10, terminal colors are enabled + -- here as a side effect. Returns Nothing if output is redirected to a file. + supportsAnsi <- hSupportsANSIWithoutEmulation logHandle <&> (== Just True) + -- Also support NO_COLOR spec https://no-color.org/ + noColor <- Env.lookupEnv "NO_COLOR" <&> isJust + let useColor = globalUseColor && not termDumb && not noColor && supportsAnsi - let logHandle = stderr logOptions' <- logOptionsHandle logHandle verbose let logOptions = setLogUseTime globalVeryVerbose diff --git a/test/fixtures/alternate-config-missing.txt b/test/fixtures/alternate-config-missing.txt index 697896bfe..3301befec 100644 --- a/test/fixtures/alternate-config-missing.txt +++ b/test/fixtures/alternate-config-missing.txt @@ -1,5 +1,5 @@ -[error] Failed to read the config. Error was: -[error] There's no "test.dhall" in your current location. +[error] Failed to read the config. Error was: +[error] There's no "test.dhall" in your current location. If you already have a spago project you might be in the wrong subdirectory, -otherwise you might want to run `spago init` to initialize a new project. +otherwise you might want to run `spago init` to initialize a new project. diff --git a/test/fixtures/alternative2install-stderr.txt b/test/fixtures/alternative2install-stderr.txt index 042445b2c..13dce3a69 100644 --- a/test/fixtures/alternative2install-stderr.txt +++ b/test/fixtures/alternative2install-stderr.txt @@ -1,2 +1,2 @@ -[warn] Failed to add dependencies. You should have a record with the `dependencies` key for this to work. -[warn] Configuration file was not updated. +[warn] Failed to add dependencies. You should have a record with the `dependencies` key for this to work. +[warn] Configuration file was not updated. diff --git a/test/fixtures/bundle-stderr.txt b/test/fixtures/bundle-stderr.txt index e3297715d..323776feb 100644 --- a/test/fixtures/bundle-stderr.txt +++ b/test/fixtures/bundle-stderr.txt @@ -1 +1 @@ -[error] The `bundle` command has been replaced with `bundle-app`, so use that instead. +[error] The `bundle` command has been replaced with `bundle-app`, so use that instead. diff --git a/test/fixtures/check-direct-import-transitive-dependency.txt b/test/fixtures/check-direct-import-transitive-dependency.txt index cb5c8bf47..c2fba0310 100644 --- a/test/fixtures/check-direct-import-transitive-dependency.txt +++ b/test/fixtures/check-direct-import-transitive-dependency.txt @@ -1,8 +1,8 @@ purs compile: No files found using pattern: test/**/*.purs -[info] Build succeeded. -[warn] None of your project files import modules from some projects that are in the direct dependencies of your project. +[info] Build succeeded. +[warn] None of your project files import modules from some projects that are in the direct dependencies of your project. These dependencies are unused. To fix this warning, remove the following packages from the list of dependencies in your config: -- effect -[error] Some of your project files import modules from packages that are not in the direct dependencies of your project. +- effect +[error] Some of your project files import modules from packages that are not in the direct dependencies of your project. To fix this error add the following packages to the list of dependencies in your config: -- prelude +- prelude diff --git a/test/fixtures/check-unused-dependency.txt b/test/fixtures/check-unused-dependency.txt index efc1f0a19..ec3ede38b 100644 --- a/test/fixtures/check-unused-dependency.txt +++ b/test/fixtures/check-unused-dependency.txt @@ -1,5 +1,5 @@ purs compile: No files found using pattern: test/**/*.purs -[info] Build succeeded. -[warn] None of your project files import modules from some projects that are in the direct dependencies of your project. +[info] Build succeeded. +[warn] None of your project files import modules from some projects that are in the direct dependencies of your project. These dependencies are unused. To fix this warning, remove the following packages from the list of dependencies in your config: -- effect +- effect diff --git a/test/fixtures/circular-dependencies.txt b/test/fixtures/circular-dependencies.txt index f046829d6..7ccb16e87 100644 --- a/test/fixtures/circular-dependencies.txt +++ b/test/fixtures/circular-dependencies.txt @@ -1,3 +1,3 @@ -[error] The following packages have circular dependencies: -[error]  - a -[error]  - b +[error] The following packages have circular dependencies: +[error] - a +[error] - b diff --git a/test/fixtures/make-module-stderr.txt b/test/fixtures/make-module-stderr.txt index a3b5c514d..8773c5403 100644 --- a/test/fixtures/make-module-stderr.txt +++ b/test/fixtures/make-module-stderr.txt @@ -1 +1 @@ -[error] The `make-module` command has been replaced with `bundle-module`, so use that instead. +[error] The `make-module` command has been replaced with `bundle-module`, so use that instead. diff --git a/test/fixtures/missing-dependencies.txt b/test/fixtures/missing-dependencies.txt index 8437c06e1..ed420f8c5 100644 --- a/test/fixtures/missing-dependencies.txt +++ b/test/fixtures/missing-dependencies.txt @@ -1,3 +1,3 @@ -[error] The following packages do not exist in your package set: -[error]  - bar -[error]  - foo +[error] The following packages do not exist in your package set: +[error] - bar +[error] - foo diff --git a/test/fixtures/spago-install-existing-dep-stderr.txt b/test/fixtures/spago-install-existing-dep-stderr.txt index 9f90c969a..919d2475d 100644 --- a/test/fixtures/spago-install-existing-dep-stderr.txt +++ b/test/fixtures/spago-install-existing-dep-stderr.txt @@ -1 +1 @@ -[warn] Configuration file was not updated. +[warn] Configuration file was not updated. diff --git a/test/fixtures/spago-install-purescript-prefix-stderr.txt b/test/fixtures/spago-install-purescript-prefix-stderr.txt index 10978e11d..a8c266ded 100644 --- a/test/fixtures/spago-install-purescript-prefix-stderr.txt +++ b/test/fixtures/spago-install-purescript-prefix-stderr.txt @@ -1,6 +1,6 @@ -[info] The package 'purescript-newtype' was resolved to the 'newtype' package -[info] Installing 1 dependencies. -[info] Searching for packages cache metadata.. -[info] Recent packages cache metadata found, using it.. -[info] Installing "newtype" -[info] Installation complete. +[info] The package 'purescript-newtype' was resolved to the 'newtype' package +[info] Installing 1 dependencies. +[info] Searching for packages cache metadata.. +[info] Recent packages cache metadata found, using it.. +[info] Installing "newtype" +[info] Installation complete. diff --git a/test/fixtures/spago-test-not-found.txt b/test/fixtures/spago-test-not-found.txt index 3b90cedb9..b1b29f972 100644 --- a/test/fixtures/spago-test-not-found.txt +++ b/test/fixtures/spago-test-not-found.txt @@ -1 +1 @@ -[error] Module 'Test.Main' not found! Are you including it in your build? +[error] Module 'Test.Main' not found! Are you including it in your build? diff --git a/test/fixtures/test-output-stderr.txt b/test/fixtures/test-output-stderr.txt index fec95f3fe..42dbe58e3 100644 --- a/test/fixtures/test-output-stderr.txt +++ b/test/fixtures/test-output-stderr.txt @@ -1,2 +1,2 @@ -[info] Build succeeded. -[info] Tests succeeded. +[info] Build succeeded. +[info] Tests succeeded. diff --git a/test/fixtures/verify-set-failure-no-files.txt b/test/fixtures/verify-set-failure-no-files.txt index b64b04009..8b8c8aaed 100644 --- a/test/fixtures/verify-set-failure-no-files.txt +++ b/test/fixtures/verify-set-failure-no-files.txt @@ -1,6 +1,6 @@ -[error] Could not find a valid "spago.dhall" or "packages.dhall" -[error] Error was: -[error] There's no "spago.dhall" in your current location. +[error] Could not find a valid "spago.dhall" or "packages.dhall" +[error] Error was: +[error] There's no "spago.dhall" in your current location. If you already have a spago project you might be in the wrong subdirectory, -otherwise you might want to run `spago init` to initialize a new project. +otherwise you might want to run `spago init` to initialize a new project. diff --git a/test/fixtures/verify-set-success.txt b/test/fixtures/verify-set-success.txt index da4c14011..574d10786 100644 --- a/test/fixtures/verify-set-success.txt +++ b/test/fixtures/verify-set-success.txt @@ -1 +1 @@ -[error] Could not find a valid "spago.dhall" or "packages.dhall" +[error] Could not find a valid "spago.dhall" or "packages.dhall"