Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit c4cd13c

Browse files
githubuseracctcm-jc
authored andcommitted
Add support for bold colors
1 parent 94dfb29 commit c4cd13c

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

lib/rspec/core/formatters/console_codes.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ module ConsoleCodes
77
# @private
88
VT100_CODES =
99
{
10-
:black => 30,
11-
:red => 31,
12-
:green => 32,
13-
:yellow => 33,
14-
:blue => 34,
15-
:magenta => 35,
16-
:cyan => 36,
17-
:white => 37,
18-
:bold => 1,
10+
:black => 30,
11+
:red => 31,
12+
:green => 32,
13+
:yellow => 33,
14+
:blue => 34,
15+
:magenta => 35,
16+
:cyan => 36,
17+
:white => 37,
18+
:bold_black => '1;30',
19+
:bold_red => '1;31',
20+
:bold_green => '1;32',
21+
:bold_yellow => '1;33',
22+
:bold_blue => '1;34',
23+
:bold_magenta => '1;35',
24+
:bold_cyan => '1;36',
25+
:bold_white => '1;37',
26+
:bold => 1,
1927
}
2028
# @private
2129
VT100_CODE_VALUES = VT100_CODES.invert

spec/rspec/core/formatters/console_codes_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
end
1111
end
1212

13+
context "when given a VT100 compound code" do
14+
it "returns the code" do
15+
expect(console_codes.console_code_for('1;32')).to eq '1;32'
16+
end
17+
end
18+
1319
context "when given a symbolic name" do
1420
it "returns the code" do
1521
expect(console_codes.console_code_for(:green)).to eq 32
@@ -41,19 +47,37 @@
4147
end
4248
end
4349

50+
context "when given a VT100 compound code" do
51+
it "formats the text with it" do
52+
expect(console_codes.wrap('abc', '1;32')).to eq "\e[1;32mabc\e[0m"
53+
end
54+
end
55+
4456
context "when given a symbolic color name" do
4557
it "translates it to the correct integer code and formats the text with it" do
4658
expect(console_codes.wrap('abc', :green)).to eq "\e[32mabc\e[0m"
4759
end
4860
end
4961

62+
context "when given a symbolic bold color name" do
63+
it "translates it to the correct integer code and formats the text with it" do
64+
expect(console_codes.wrap('abc', :bold_green)).to eq "\e[1;32mabc\e[0m"
65+
end
66+
end
67+
5068
context "when given an rspec code" do
5169
it "returns the console code" do
5270
RSpec.configuration.success_color = :blue # blue is 34
5371
expect(console_codes.wrap('abc', :success)).to eq "\e[34mabc\e[0m"
5472
end
5573
end
5674

75+
context "when given a compound rspec code" do
76+
it "returns the console code" do
77+
RSpec.configuration.success_color = :bold_blue # blue is 34
78+
expect(console_codes.wrap('abc', :success)).to eq "\e[1;34mabc\e[0m"
79+
end
80+
end
5781

5882
context "when given :bold" do
5983
it "formats the text as bold" do

0 commit comments

Comments
 (0)