Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix colors on Windows (#749) #768

Merged
merged 2 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (😱!!!):
Expand Down
3 changes: 2 additions & 1 deletion spago.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/Spago/RunEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/alternate-config-missing.txt
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions test/fixtures/alternative2install-stderr.txt
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion test/fixtures/bundle-stderr.txt
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions test/fixtures/check-direct-import-transitive-dependency.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/fixtures/check-unused-dependency.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/fixtures/circular-dependencies.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/fixtures/make-module-stderr.txt
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions test/fixtures/missing-dependencies.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/fixtures/spago-install-existing-dep-stderr.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[warn] Configuration file was not updated.
[warn] Configuration file was not updated.
12 changes: 6 additions & 6 deletions test/fixtures/spago-install-purescript-prefix-stderr.txt
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion test/fixtures/spago-test-not-found.txt
Original file line number Diff line number Diff line change
@@ -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?
4 changes: 2 additions & 2 deletions test/fixtures/test-output-stderr.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[info] Build succeeded.
[info] Tests succeeded.
[info] Build succeeded.
[info] Tests succeeded.
8 changes: 4 additions & 4 deletions test/fixtures/verify-set-failure-no-files.txt
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion test/fixtures/verify-set-success.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[error] Could not find a valid "spago.dhall" or "packages.dhall"
[error] Could not find a valid "spago.dhall" or "packages.dhall"