mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #3090 from jcs/no_color
Tty: if NO_COLOR env var is present, disable color
This commit is contained in:
commit
b3f0e571f4
@ -199,6 +199,9 @@ can take several different forms:
|
|||||||
If set, Homebrew will not auto-update before running `brew install`,
|
If set, Homebrew will not auto-update before running `brew install`,
|
||||||
`brew upgrade` or `brew tap`.
|
`brew upgrade` or `brew tap`.
|
||||||
|
|
||||||
|
* `HOMEBREW_NO_COLOR`:
|
||||||
|
If set, Homebrew will not print text with color added.
|
||||||
|
|
||||||
* `HOMEBREW_NO_EMOJI`:
|
* `HOMEBREW_NO_EMOJI`:
|
||||||
If set, Homebrew will not print the `HOMEBREW_INSTALL_BADGE` on a
|
If set, Homebrew will not print the `HOMEBREW_INSTALL_BADGE` on a
|
||||||
successful build.
|
successful build.
|
||||||
|
@ -75,6 +75,7 @@ describe Hbc::DSL, :cask do
|
|||||||
|
|
||||||
it "may use deprecated DSL version hash syntax" do
|
it "may use deprecated DSL version hash syntax" do
|
||||||
allow(ENV).to receive(:[]).with("HOMEBREW_DEVELOPER").and_return(nil)
|
allow(ENV).to receive(:[]).with("HOMEBREW_DEVELOPER").and_return(nil)
|
||||||
|
allow(ENV).to receive(:[]).with("HOMEBREW_NO_COLOR").and_return(nil)
|
||||||
|
|
||||||
expect(cask.token).to eq("with-dsl-version")
|
expect(cask.token).to eq("with-dsl-version")
|
||||||
expect(cask.url.to_s).to eq("http://example.com/TestCask.dmg")
|
expect(cask.url.to_s).to eq("http://example.com/TestCask.dmg")
|
||||||
|
@ -53,7 +53,7 @@ describe Tty do
|
|||||||
allow($stdout).to receive(:tty?).and_return(true)
|
allow($stdout).to receive(:tty?).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an empty string for all colors" do
|
it "returns ANSI escape codes for colors" do
|
||||||
expect(subject.to_s).to eq("")
|
expect(subject.to_s).to eq("")
|
||||||
expect(subject.red.to_s).to eq("\033[31m")
|
expect(subject.red.to_s).to eq("\033[31m")
|
||||||
expect(subject.green.to_s).to eq("\033[32m")
|
expect(subject.green.to_s).to eq("\033[32m")
|
||||||
@ -63,5 +63,17 @@ describe Tty do
|
|||||||
expect(subject.cyan.to_s).to eq("\033[36m")
|
expect(subject.cyan.to_s).to eq("\033[36m")
|
||||||
expect(subject.default.to_s).to eq("\033[39m")
|
expect(subject.default.to_s).to eq("\033[39m")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns an empty string for all colors when HOMEBREW_NO_COLOR is set" do
|
||||||
|
ENV["HOMEBREW_NO_COLOR"] = "1"
|
||||||
|
expect(subject.to_s).to eq("")
|
||||||
|
expect(subject.red.to_s).to eq("")
|
||||||
|
expect(subject.green.to_s).to eq("")
|
||||||
|
expect(subject.yellow.to_s).to eq("")
|
||||||
|
expect(subject.blue.to_s).to eq("")
|
||||||
|
expect(subject.magenta.to_s).to eq("")
|
||||||
|
expect(subject.cyan.to_s).to eq("")
|
||||||
|
expect(subject.default.to_s).to eq("")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,7 +59,9 @@ module Tty
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
return "" unless $stdout.tty?
|
if ENV["HOMEBREW_NO_COLOR"] || !$stdout.tty?
|
||||||
|
return ""
|
||||||
|
end
|
||||||
current_escape_sequence
|
current_escape_sequence
|
||||||
ensure
|
ensure
|
||||||
reset_escape_sequence!
|
reset_escape_sequence!
|
||||||
|
2
bin/brew
2
bin/brew
@ -47,7 +47,7 @@ HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
|
|||||||
# Whitelist and copy to HOMEBREW_* all variables previously mentioned in
|
# Whitelist and copy to HOMEBREW_* all variables previously mentioned in
|
||||||
# manpage or used elsewhere by Homebrew.
|
# manpage or used elsewhere by Homebrew.
|
||||||
for VAR in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY BINTRAY_USER BINTRAY_KEY \
|
for VAR in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY BINTRAY_USER BINTRAY_KEY \
|
||||||
BROWSER EDITOR GIT PATH VISUAL \
|
BROWSER EDITOR GIT NO_COLOR PATH VISUAL \
|
||||||
GITHUB_USER GITHUB_PASSWORD GITHUB_TOKEN
|
GITHUB_USER GITHUB_PASSWORD GITHUB_TOKEN
|
||||||
do
|
do
|
||||||
# Skip if variable value is empty.
|
# Skip if variable value is empty.
|
||||||
|
@ -1037,6 +1037,9 @@ can take several different forms:
|
|||||||
If set, Homebrew will not auto-update before running `brew install`,
|
If set, Homebrew will not auto-update before running `brew install`,
|
||||||
`brew upgrade` or `brew tap`.
|
`brew upgrade` or `brew tap`.
|
||||||
|
|
||||||
|
* `HOMEBREW_NO_COLOR`:
|
||||||
|
If set, Homebrew will not print text with color added.
|
||||||
|
|
||||||
* `HOMEBREW_NO_EMOJI`:
|
* `HOMEBREW_NO_EMOJI`:
|
||||||
If set, Homebrew will not print the `HOMEBREW_INSTALL_BADGE` on a
|
If set, Homebrew will not print the `HOMEBREW_INSTALL_BADGE` on a
|
||||||
successful build.
|
successful build.
|
||||||
|
@ -1059,6 +1059,10 @@ If set, Homebrew will not send analytics\. See: \fIhttps://docs\.brew\.sh/Analyt
|
|||||||
If set, Homebrew will not auto\-update before running \fBbrew install\fR, \fBbrew upgrade\fR or \fBbrew tap\fR\.
|
If set, Homebrew will not auto\-update before running \fBbrew install\fR, \fBbrew upgrade\fR or \fBbrew tap\fR\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
|
\fBHOMEBREW_NO_COLOR\fR
|
||||||
|
If set, Homebrew will not print text with color added\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
\fBHOMEBREW_NO_EMOJI\fR
|
\fBHOMEBREW_NO_EMOJI\fR
|
||||||
If set, Homebrew will not print the \fBHOMEBREW_INSTALL_BADGE\fR on a successful build\.
|
If set, Homebrew will not print the \fBHOMEBREW_INSTALL_BADGE\fR on a successful build\.
|
||||||
.
|
.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user