Skip to content

Commit

Permalink
no color change where no ansi code is used at all
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Mathur <[email protected]>
  • Loading branch information
Nik08 committed May 19, 2021
1 parent f9659bf commit 209948d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/inspec/base_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def self.help(*args)
puts " Patents: chef.io/patents\n\n"
end

def self.format_platform_info(params: {}, indent: 0, color: 39)
def self.format_platform_info(params: {}, indent: 0, color: 39, enable_color: true)
str = ""
params.each do |item, info|
data = info
Expand All @@ -192,7 +192,7 @@ def self.format_platform_info(params: {}, indent: 0, color: 39)
# Do not output fields of data is missing ('unknown' is fine)
next if data.nil?

data = "\e[1m\e[#{color}m#{data}\e[0m"
data = "\e[1m\e[#{color}m#{data}\e[0m" if enable_color
str << format("#{" " * indent}%-10s %s\n", item.to_s.capitalize + ":", data)
end
str
Expand Down
4 changes: 1 addition & 3 deletions lib/inspec/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ def detect
puts res.to_json
else
ui.headline("Platform Details")

detect_cmd_ui_color = ui.color? ? 36 : 0
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: detect_cmd_ui_color)
ui.plain Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: 36, enable_color: ui.color?)
end
rescue ArgumentError, RuntimeError, Train::UserError => e
$stderr.puts e.message
Expand Down
4 changes: 2 additions & 2 deletions test/functional/ui_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def show_spaces(str)
let(:result) { inspec("detect") }

it "has a colorful output" do
_(result.stdout).must_include("\e[1m\e[36m")
_(result.stdout).must_include("\e[")
assert_exit_code 0, result
end
end
Expand Down Expand Up @@ -144,7 +144,7 @@ def show_spaces(str)
let(:result) { inspec("detect --no-color") }

it "has no color in the output" do
_(result.stdout).must_include("\e[1m\e[0m")
_(result.stdout).wont_include("\e[")
assert_exit_code 0, result
end
end
Expand Down

0 comments on commit 209948d

Please sign in to comment.