Skip to content

Commit 955edf4

Browse files
committed
Respect NO_COLOR flag.
1 parent da3c599 commit 955edf4

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/Terminal/Help.gren

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ import SemanticVersion
1818
type alias ConfirmConfig =
1919
{ stdout : Stream.Writable Bytes
2020
, stdin : Stream.Readable Bytes
21+
, useColor : Bool
2122
, interactive : Bool
2223
, question : PP.Document
2324
, defaultValue : Bool
2425
}
2526

2627

27-
-- TODO: respect NO_COLOR
2828
confirm : ConfirmConfig -> Task Stream.Error Bool
29-
confirm { stdout, stdin, interactive, question, defaultValue } =
29+
confirm { stdout, stdin, useColor, interactive, question, defaultValue } =
3030
if not interactive then
3131
Task.succeed defaultValue
3232

@@ -40,7 +40,7 @@ confirm { stdout, stdin, interactive, question, defaultValue } =
4040
" [y|N]: "
4141
in
4242
PP.block [ question, PP.text legend ]
43-
|> prettyPrint
43+
|> prettyPrint { useColor = useColor }
4444
|> Stream.Log.string stdout
4545
|> Task.andThen (\_ -> Stream.readBytesAsString stdin)
4646
|> Task.map
@@ -57,14 +57,19 @@ confirm { stdout, stdin, interactive, question, defaultValue } =
5757
)
5858

5959

60-
prettyPrint : PP.Document -> String
61-
prettyPrint doc =
60+
prettyPrint : { useColor : Bool } -> PP.Document -> String
61+
prettyPrint { useColor } doc =
6262
PP.toStringWithOptions
6363
{ maxColumns = 80
6464
, indentationSize = 4
6565
, newlineSeparator = "\n"
6666
}
67-
doc
67+
(if useColor then
68+
doc
69+
70+
else
71+
PP.stripColor doc
72+
)
6873

6974

7075
report : String -> Maybe Path -> PP.Document -> PP.Document

src/Terminal/Init.gren

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ run config =
7777
Terminal.Help.confirm
7878
{ stdout = config.stdout
7979
, stdin = config.stdin
80+
, useColor = config.useColor
8081
, interactive = config.interactive
8182
, question =
8283
PP.verticalBlock
@@ -105,7 +106,7 @@ run config =
105106
)
106107
|> Task.onError
107108
(\err ->
108-
Stream.Log.line config.stdout (displayError err)
109+
Stream.Log.line config.stdout (displayError { useColor = config.useColor } err)
109110
)
110111
|> Task.execute
111112

@@ -246,9 +247,9 @@ generateGrenJson config deps =
246247
)
247248

248249

249-
displayError : Error -> String
250-
displayError err =
251-
Terminal.Help.prettyPrint <|
250+
displayError : { useColor : Bool } -> Error -> String
251+
displayError printOpts err =
252+
Terminal.Help.prettyPrint printOpts <|
252253
when err is
253254
AlreadyInitialized ->
254255
Terminal.Help.report

src/Terminal/PackageInstall.gren

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ addPackage config { projectPath, outline } requestedPackage =
424424
Help.confirm
425425
{ stdout = config.stdout
426426
, stdin = config.stdin
427+
, useColor = config.useColor
427428
, interactive = config.interactive
428429
, question = plan
429430
, defaultValue = True

src/Terminal/PackageUninstall.gren

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ run config { projectPath, outline } requestedPackage =
127127
Help.confirm
128128
{ stdout = config.stdout
129129
, stdin = config.stdin
130+
, useColor = config.useColor
130131
, interactive = config.interactive
131132
, question = plan
132133
, defaultValue = True

0 commit comments

Comments
 (0)