Skip to content

Commit

Permalink
Merge pull request #2378 from mariusae/color
Browse files Browse the repository at this point in the history
commands: consult global color.ui setting when --color=auto
  • Loading branch information
mislav authored Dec 3, 2019
2 parents e1247cc + 4b4843b commit 1244ec2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions commands/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ func listLabels(cmd *Command, args *Args) {

func colorizeOutput(colorSet bool, when string) bool {
if !colorSet || when == "auto" {
colorConfig, _ := git.Config("color.ui")
switch colorConfig {
case "false", "never":
return false
case "always":
return true
}
return ui.IsTerminal(os.Stdout)
} else if when == "never" {
return false
Expand Down
18 changes: 17 additions & 1 deletion features/pr-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,29 @@ Feature: hub pr list
}
"""
When I successfully run `hub pr list --format "%I %pC %pS %Creset%n" --color`
Then the output should contain exactly:
Then its output should contain exactly:
"""
999 \e[37m draft \e[m
102 \e[32m open \e[m
42 \e[35m merged \e[m
8 \e[31m closed \e[m\n
"""
When I successfully run `hub -c color.ui=always pr list --format "%I %pC %pS %Creset%n"`
Then its output should contain exactly:
"""
999 \e[37m draft \e[m
102 \e[32m open \e[m
42 \e[35m merged \e[m
8 \e[31m closed \e[m\n
"""
When I successfully run `hub -c color.ui=false pr list --format "%I %pC%pS%Creset%n" --color=auto`
Then its output should contain exactly:
"""
999 draft
102 open
42 merged
8 closed\n
"""

Scenario: Sort by number of comments ascending
Given the GitHub API server:
Expand Down
25 changes: 25 additions & 0 deletions features/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,28 @@
contents.gsub!(/[0-9a-f]{7} \(Hub, \d seconds? ago\)/, "SHA1SHA (Hub, 0 seconds ago)")
File.open(file, "w") { |f| f.write(contents) }
end

Then(/^its (output|stderr|stdout) should( not)? contain( exactly)?:$/) do |channel, negated, exactly, expected|
matcher = case channel.to_sym
when :output
:have_output
when :stderr
:have_output_on_stderr
when :stdout
:have_output_on_stdout
end

commands = [last_command_started]

output_string_matcher = if exactly
:an_output_string_being_eq
else
:an_output_string_including
end

if negated
expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected))
else
expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected))
end
end

0 comments on commit 1244ec2

Please sign in to comment.