Class: Colours::Colours
- Inherits:
-
Base
- Object
- Base
- Colours::Colours
show all
- Defined in:
- lib/colours/class/colours.rb
Overview
Constant Summary
collapse
- LEADING_PART =
#
LEADING_PART
We don’t include the “[” here.
#
"\033"
- TRAILING_PART =
"\033[0m"
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === Colours::Colours[] ========================================================================= #.
Instance Method Summary
collapse
-
#+(i = '') ⇒ Object
# === + ========================================================================= #.
-
#append(i) ⇒ Object
# === append ========================================================================= #.
-
#background(i = :yellow) ⇒ Object
(also: #bg)
# === background ========================================================================= #.
-
#bright ⇒ Object
(also: #bold)
# === bright ========================================================================= #.
-
#build_the_main_string ⇒ Object
(also: #to_str, #to_s, #build_main_string)
# === build_the_main_string (main tag).
-
#display ⇒ Object
(also: #report)
# === display ========================================================================= #.
-
#increased_intensity? ⇒ Boolean
# === increased_intensity? ========================================================================= #.
-
#initialize(i = '') ⇒ Colours
constructor
# === initialize ========================================================================= #.
-
#italic ⇒ Object
# === italic ========================================================================= #.
-
#leading_part? ⇒ Boolean
# === leading_part? ========================================================================= #.
-
#raw_content? ⇒ Boolean
(also: #content?, #string?)
# === raw_content? ========================================================================= #.
-
#red ⇒ Object
(also: #blue, #black, #green, #brown, #yellow, #purple, #magenta, #cyan, #light_blue, #light_gray, #light_green, #light_magenta, #white, #light_red, #grey)
# === red ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#reversed ⇒ Object
# === reversed ========================================================================= #.
-
#reversed? ⇒ Boolean
# === reversed? ========================================================================= #.
-
#set_content(i) ⇒ Object
# === set_content ========================================================================= #.
-
#set_slow_blink_to_true ⇒ Object
# === set_slow_blink_to_true ========================================================================= #.
-
#set_use_this_background_colour(i) ⇒ Object
# === set_use_this_background_colour ========================================================================= #.
-
#set_use_this_colour(i) ⇒ Object
# === set_use_this_colour ========================================================================= #.
-
#set_use_underline_to_true ⇒ Object
# === set_use_underline_to_true ========================================================================= #.
-
#slow_blink ⇒ Object
# === slow_blink ========================================================================= #.
-
#slow_blink? ⇒ Boolean
# === slow_blink? ========================================================================= #.
-
#string_increased_intensity? ⇒ Boolean
# === string_increased_intensity? ========================================================================= #.
-
#trailing_end? ⇒ Boolean
# === trailing_end? ========================================================================= #.
-
#underline ⇒ Object
(also: #underlined)
# === underline ========================================================================= #.
-
#use_italic? ⇒ Boolean
# === use_italic? ========================================================================= #.
-
#use_this_background_colour? ⇒ Boolean
# === use_this_background_colour?.
-
#use_this_colour? ⇒ Boolean
# === use_this_colour? ========================================================================= #.
-
#use_underline? ⇒ Boolean
# === use_underline? ========================================================================= #.
Methods inherited from Base
#commandline_arguments?, #e, #extend_module_256_colours, #first_argument?, #second_argument?, #set_commandline_arguments
Constructor Details
#initialize(i = '') ⇒ Colours
50
51
52
53
54
55
56
|
# File 'lib/colours/class/colours.rb', line 50
def initialize(i = '')
reset
if i.is_a? Array
i = i.join(' ').strip
end
@internal_hash[:raw_content] = i end
|
Class Method Details
.[](i = ARGV) ⇒ Object
359
360
361
|
# File 'lib/colours/class/colours.rb', line 359
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#+(i = '') ⇒ Object
281
282
283
|
# File 'lib/colours/class/colours.rb', line 281
def +(i = '')
append(i)
end
|
#append(i) ⇒ Object
288
289
290
|
# File 'lib/colours/class/colours.rb', line 288
def append(i)
"#{to_str}#{i.to_str}"
end
|
#background(i = :yellow) ⇒ Object
Also known as:
bg
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/colours/class/colours.rb', line 256
def background(i = :yellow)
i = i.to_s
unless i.start_with? 'background_'
i = i.dup if i.frozen?
i.prepend('background_')
end
i = i.to_sym
unless HASH_ANSI_COLOURS.has_key? i
e 'Warning: the key '+i.to_s+' is not registered in the main Hash.'
end
i = HASH_ANSI_COLOURS[i].to_s
set_use_this_background_colour(i)
self
end
|
#bright ⇒ Object
Also known as:
bold
248
249
250
251
|
# File 'lib/colours/class/colours.rb', line 248
def bright
@internal_hash[:leading_colour_component] = '1'
self
end
|
#build_the_main_string ⇒ Object
Also known as:
to_str, to_s, build_main_string
#
build_the_main_string (main tag)
This method must always rebuild the full, modified content.
#
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/colours/class/colours.rb', line 297
def build_the_main_string
result = ''.dup
result << leading_part?
result << '['
result << string_increased_intensity?
result << ";#{use_this_colour?}" unless use_this_colour? == '0'
if use_this_background_colour?
result << ";#{use_this_background_colour?}"
end
result << ';3' if use_italic?
result << ';4' if use_underline?
result << ';5' if slow_blink?
result << ';7' if reversed?
result << 'm'
result << raw_content?
result << trailing_end?
return result
end
|
#display ⇒ Object
Also known as:
report
185
186
187
|
# File 'lib/colours/class/colours.rb', line 185
def display
print build_main_string(content?)
end
|
#increased_intensity? ⇒ Boolean
229
230
231
232
|
# File 'lib/colours/class/colours.rb', line 229
def increased_intensity?
_ = @internal_hash[:leading_colour_component]
return (_ and !_.empty?)
end
|
#italic ⇒ Object
344
345
346
347
|
# File 'lib/colours/class/colours.rb', line 344
def italic
@internal_hash[:use_italic] = true
self
end
|
#leading_part? ⇒ Boolean
206
207
208
|
# File 'lib/colours/class/colours.rb', line 206
def leading_part?
"#{LEADING_PART}"
end
|
#raw_content? ⇒ Boolean
Also known as:
content?, string?
156
157
158
|
# File 'lib/colours/class/colours.rb', line 156
def raw_content?
@internal_hash[:raw_content]
end
|
#red ⇒ Object
Also known as:
blue, black, green, brown, yellow, purple, magenta, cyan, light_blue, light_gray, light_green, light_magenta, white, light_red, grey
321
322
323
324
325
|
# File 'lib/colours/class/colours.rb', line 321
def red
real_name_of_the_method = HASH_ANSI_COLOURS[__callee__]
set_use_this_colour(real_name_of_the_method)
self
end
|
#reset ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/colours/class/colours.rb', line 61
def reset
@internal_hash = {}
@internal_hash[:raw_content] = nil
@internal_hash[:leading_colour_component] = ''.dup
@internal_hash[:use_italic] = false
@internal_hash[:use_underline] = false
@internal_hash[:slow_blink] = false
@internal_hash[:use_this_background_colour] = nil
@internal_hash[:use_this_colour] = '0'
@internal_hash[:reversed] = false
end
|
#reversed ⇒ Object
134
135
136
137
|
# File 'lib/colours/class/colours.rb', line 134
def reversed
@internal_hash[:reversed] = true
self
end
|
#reversed? ⇒ Boolean
111
112
113
|
# File 'lib/colours/class/colours.rb', line 111
def reversed?
@internal_hash[:reversed]
end
|
#set_content(i) ⇒ Object
192
193
194
|
# File 'lib/colours/class/colours.rb', line 192
def set_content(i)
@internal_hash[:raw_content] = i.dup
end
|
#set_slow_blink_to_true ⇒ Object
#
set_slow_blink_to_true
#
149
150
151
|
# File 'lib/colours/class/colours.rb', line 149
def set_slow_blink_to_true
@internal_hash[:slow_blink] = true
end
|
#set_use_this_background_colour(i) ⇒ Object
#
set_use_this_background_colour
#
127
128
129
|
# File 'lib/colours/class/colours.rb', line 127
def set_use_this_background_colour(i)
@internal_hash[:use_this_background_colour] = i
end
|
#set_use_this_colour(i) ⇒ Object
274
275
276
|
# File 'lib/colours/class/colours.rb', line 274
def set_use_this_colour(i)
@internal_hash[:use_this_colour] = i
end
|
#set_use_underline_to_true ⇒ Object
#
set_use_underline_to_true
#
142
143
144
|
# File 'lib/colours/class/colours.rb', line 142
def set_use_underline_to_true
@internal_hash[:use_underline] = true
end
|
#slow_blink ⇒ Object
213
214
215
216
|
# File 'lib/colours/class/colours.rb', line 213
def slow_blink
set_slow_blink_to_true
self
end
|
#slow_blink? ⇒ Boolean
178
179
180
|
# File 'lib/colours/class/colours.rb', line 178
def slow_blink?
@internal_hash[:slow_blink]
end
|
#string_increased_intensity? ⇒ Boolean
#
string_increased_intensity?
#
237
238
239
240
241
242
243
|
# File 'lib/colours/class/colours.rb', line 237
def string_increased_intensity?
_ = @internal_hash[:leading_colour_component]
if _ and !_.empty?
return "#{_}" end
return ''
end
|
#trailing_end? ⇒ Boolean
199
200
201
|
# File 'lib/colours/class/colours.rb', line 199
def trailing_end?
TRAILING_PART
end
|
#underline ⇒ Object
Also known as:
underlined
221
222
223
224
|
# File 'lib/colours/class/colours.rb', line 221
def underline
set_use_underline_to_true
self
end
|
#use_italic? ⇒ Boolean
352
353
354
|
# File 'lib/colours/class/colours.rb', line 352
def use_italic?
@internal_hash[:use_italic]
end
|
#use_this_background_colour? ⇒ Boolean
#
use_this_background_colour?
Background colours go from e. g. 40 to 47, give or take.
#
120
121
122
|
# File 'lib/colours/class/colours.rb', line 120
def use_this_background_colour?
@internal_hash[:use_this_background_colour]
end
|
#use_this_colour? ⇒ Boolean
164
165
166
|
# File 'lib/colours/class/colours.rb', line 164
def use_this_colour?
@internal_hash[:use_this_colour]
end
|
#use_underline? ⇒ Boolean
171
172
173
|
# File 'lib/colours/class/colours.rb', line 171
def use_underline?
@internal_hash[:use_underline]
end
|