Skip to content

Commit

Permalink
Merge pull request #1510 from trickyearlobe/fix_windows_output_format…
Browse files Browse the repository at this point in the history
…ting

Fix formatting and colors on Windows
  • Loading branch information
chris-rock committed Feb 24, 2017
2 parents 6511a67 + ee87dfb commit 26dc4e7
Showing 1 changed file with 54 additions and 21 deletions.
75 changes: 54 additions & 21 deletions lib/inspec/rspec_json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,60 @@ def format_example(example)
class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
RSpec::Core::Formatters.register self, :close

COLORS = {
'critical' => "\033[38;5;9m",
'major' => "\033[38;5;208m",
'minor' => "\033[0;36m",
'failed' => "\033[38;5;9m",
'passed' => "\033[38;5;41m",
'skipped' => "\033[38;5;247m",
'reset' => "\033[0m",
}.freeze

INDICATORS = {
'critical' => ' × ',
'major' => ' ∅ ',
'minor' => ' ⊚ ',
'failed' => ' × ',
'skipped' => ' ↺ ',
'passed' => ' ✔ ',
'unknown' => ' ? ',
'empty' => ' ',
'small' => ' ',
}.freeze
case RUBY_PLATFORM
when /windows|mswin|msys|mingw|cygwin/

# Most currently available Windows terminals have poor support
# for ANSI extended colors
COLORS = {
'critical' => "\033[0;1;31m",
'major' => "\033[0;1;31m",
'minor' => "\033[0;36m",
'failed' => "\033[0;1;31m",
'passed' => "\033[0;1;32m",
'skipped' => "\033[0;37m",
'reset' => "\033[0m",
}.freeze

# Most currently available Windows terminals have poor support
# for UTF-8 characters so use these boring indicators
INDICATORS = {
'critical' => ' [CRIT] ',
'major' => ' [MAJR] ',
'minor' => ' [MINR] ',
'failed' => ' [FAIL] ',
'skipped' => ' [SKIP] ',
'passed' => ' [PASS] ',
'unknown' => ' [UNKN] ',
'empty' => ' ',
'small' => ' ',
}.freeze
else
# Extended colors for everyone else
COLORS = {
'critical' => "\033[38;5;9m",
'major' => "\033[38;5;208m",
'minor' => "\033[0;36m",
'failed' => "\033[38;5;9m",
'passed' => "\033[38;5;41m",
'skipped' => "\033[38;5;247m",
'reset' => "\033[0m",
}.freeze

# Groovy UTF-8 characters for everyone else...
# ...even though they probably only work on Mac
INDICATORS = {
'critical' => ' × ',
'major' => ' ∅ ',
'minor' => ' ⊚ ',
'failed' => ' × ',
'skipped' => ' ↺ ',
'passed' => ' ✔ ',
'unknown' => ' ? ',
'empty' => ' ',
'small' => ' ',
}.freeze
end

MULTI_TEST_CONTROL_SUMMARY_MAX_LEN = 60

Expand Down

0 comments on commit 26dc4e7

Please sign in to comment.