-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace colorize with a simple internal implementation
- Loading branch information
1 parent
3bc3392
commit 4152d09
Showing
5 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Fasterer | ||
module Painter | ||
COLOR_CODES = { | ||
red: 31, | ||
green: 32, | ||
} | ||
|
||
def self.paint(string, color) | ||
color_code = COLOR_CODES[color.to_sym] | ||
if color_code.nil? | ||
raise ArgumentError, "Color #{color} is not supported. Allowed colors are #{COLOR_CODES.keys.join(', ')}" | ||
end | ||
paint_with_code(string, color_code) | ||
end | ||
|
||
def self.paint_with_code(string, color_code) | ||
"\e[#{color_code}m#{string}\e[0m" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
describe Fasterer::Statistics do | ||
let(:traverser_mock) do | ||
traverser = OpenStruct.new | ||
traverser.scannable_files = [] | ||
traverser.offenses_total_count = 0 | ||
traverser.parse_error_paths = [] | ||
traverser | ||
end | ||
|
||
let(:statistics) { Fasterer::Statistics.new(traverser_mock) } | ||
|
||
describe 'inspected_files_output' do | ||
it 'should be green' do | ||
expect(statistics.inspected_files_output) | ||
.to eq("\e[32m0 files inspected\e[0m") | ||
end | ||
end | ||
end |