1515
1616class String
1717
18- def bg_black
19- "\e [40m#{ self } \e [0m"
18+ @color_enabled = true
19+
20+ class << self
21+ attr_accessor :color_enabled
2022 end
2123
22- def bg_blue
23- "\e [44m#{ self } \e [0m"
24+ # Sets the string to bold
25+ def bold
26+ return self unless @color_enabled
27+ "\e [1m#{ self } \e [22m"
2428 end
2529
26- def bg_brown
27- "\e [43m#{ self } \e [0m"
30+ # Sets the string to italic
31+ def italic
32+ return self unless @color_enabled
33+ "\e [3m#{ self } \e [23m"
2834 end
2935
30- def bg_cyan
31- "\e [46m#{ self } \e [0m"
36+ # Sets the string to underlined
37+ def underline
38+ return self unless @color_enabled
39+ "\e [4m#{ self } \e [24m"
3240 end
3341
34- def bg_gray
35- "\e [47m#{ self } \e [0m"
42+ # Sets the string to blink
43+ def blink
44+ return self unless @color_enabled
45+ "\e [5m#{ self } \e [25m"
3646 end
3747
38- def bg_green
39- "\e [42m#{ self } \e [0m"
48+ # Sets the string reverse the current colors
49+ def reverse_color
50+ return self unless @color_enabled
51+ "\e [7m#{ self } \e [27m"
4052 end
4153
42- def bg_magenta
43- "\e [45m#{ self } \e [0m"
54+ # Sets the string to black
55+ def black
56+ return self unless @color_enabled
57+ "\e [30m#{ self } \e [0m"
4458 end
4559
46- def bg_red
47- "\e [41m#{ self } \e [0m"
60+ # Sets the string to red
61+ def red
62+ return self unless @color_enabled
63+ "\e [31m#{ self } \e [0m"
4864 end
4965
50- def black
51- "\e [30m#{ self } \e [0m"
66+ # Sets the string to green
67+ def green
68+ return self unless @color_enabled
69+ "\e [32m#{ self } \e [0m"
5270 end
5371
54- def blink
55- "\e [5m#{ self } \e [25m"
72+ # Sets the string to yellow
73+ def yellow
74+ return self unless @color_enabled
75+ "\e [33m#{ self } \e [0m"
5676 end
5777
78+ # Sets the string to blue
5879 def blue
80+ return self unless @color_enabled
5981 "\e [34m#{ self } \e [0m"
6082 end
6183
62- def bold
63- "\e [1m#{ self } \e [22m"
64- end
65-
66- def brown
67- "\e [33m#{ self } \e [0m"
84+ # Sets the string to magenta
85+ def magenta
86+ return self unless @color_enabled
87+ "\e [35m#{ self } \e [0m"
6888 end
6989
90+ # Sets the string to cyan
7091 def cyan
92+ return self unless @color_enabled
7193 "\e [36m#{ self } \e [0m"
7294 end
7395
74- def gray
96+ # Sets the string to white
97+ def white
98+ return self unless @color_enabled
7599 "\e [37m#{ self } \e [0m"
76100 end
77101
78- def green
79- "\e [32m#{ self } \e [0m"
102+ # Sets the string background to black
103+ def bg_black
104+ return self unless @color_enabled
105+ "\e [40m#{ self } \e [0m"
80106 end
81107
82- def italic
83- "\e [3m#{ self } \e [23m"
108+ # Sets the string background to red
109+ def bg_red
110+ return self unless @color_enabled
111+ "\e [41m#{ self } \e [0m"
84112 end
85113
86- def magenta
87- "\e [35m#{ self } \e [0m"
114+ # Sets the string background to green
115+ def bg_green
116+ return self unless @color_enabled
117+ "\e [42m#{ self } \e [0m"
88118 end
89119
90- def red
91- "\e [31m#{ self } \e [0m"
120+ # Sets the string background to yellow
121+ def bg_yellow
122+ return self unless @color_enabled
123+ "\e [43m#{ self } \e [0m"
92124 end
93125
94- def reverse_color
95- "\e [7m#{ self } \e [27m"
126+ # Sets the string background to blue
127+ def bg_blue
128+ return self unless @color_enabled
129+ "\e [44m#{ self } \e [0m"
96130 end
97131
98- def underline
99- "\e [4m#{ self } \e [24m"
132+ # Sets the string background to magenta
133+ def bg_magenta
134+ return self unless @color_enabled
135+ "\e [45m#{ self } \e [0m"
136+ end
137+
138+ # Sets the string background to cyan
139+ def bg_cyan
140+ return self unless @color_enabled
141+ "\e [46m#{ self } \e [0m"
142+ end
143+
144+ # Sets the string background to white
145+ def bg_white
146+ return self unless @color_enabled
147+ "\e [47m#{ self } \e [0m"
100148 end
101149
102- end
150+ end
0 commit comments