Skip to content

Commit

Permalink
Improve color.ui config support
Browse files Browse the repository at this point in the history
- Query `Config` instead of `GlobalConfig` to respect per-repo and
  per-invocation configuration too.

- Support "never" (synonym for "false") and "always" values.
  • Loading branch information
mislav committed Dec 3, 2019
1 parent 96cedc7 commit 4b4843b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion commands/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,12 @@ func listLabels(cmd *Command, args *Args) {

func colorizeOutput(colorSet bool, when string) bool {
if !colorSet || when == "auto" {
if value, _ := git.GlobalConfig("color.ui"); value == "false" {
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" {
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 4b4843b

Please sign in to comment.