Module: Vedeu::EscapeSequences::Colours Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Provides colour related escape sequences.
Instance Method Summary collapse
-
#background_codes ⇒ Hash<Symbol => Fixnum>
private
Produces the background named colour escape sequence hash from the foreground escape sequence hash.
- #background_colour(named_colour, &block) ⇒ String private
- #colour(named_colour, &block) ⇒ String (also: #foreground_colour) private
-
#foreground_codes ⇒ Hash<Symbol => Fixnum>
private
Produces the foreground named colour escape sequence hash.
- #valid_codes ⇒ Array<Symbol> private
-
#valid_name?(named_colour) ⇒ Boolean
private
Returns a boolean indicating whether the colour provided is a valid named colour.
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Instance Method Details
#background_codes ⇒ Hash<Symbol => Fixnum>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Produces the background named colour escape sequence hash from the foreground escape sequence hash.
20 21 22 23 24 25 |
# File 'lib/vedeu/esc/colours.rb', line 20 def background_codes foreground_codes.each_with_object({}) do |(k, v), h| h[k] = v + 10 h end end |
#background_colour(named_colour, &block) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 |
# File 'lib/vedeu/esc/colours.rb', line 30 def background_colour(named_colour, &block) return '' unless valid_name?(named_colour) colour(named_colour.to_s.prepend('on_').to_sym, &block) end |
#colour(named_colour, &block) ⇒ String Also known as: foreground_colour
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 |
# File 'lib/vedeu/esc/colours.rb', line 39 def colour(named_colour, &block) return '' unless valid_name?(named_colour) public_send(named_colour, &block) end |
#foreground_codes ⇒ Hash<Symbol => Fixnum>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Produces the foreground named colour escape sequence hash. The background escape sequences are also generated from this by adding 10 to the values. This hash gives rise to methods you can call directly on ‘Esc` to produce the desired colours:
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vedeu/esc/colours.rb', line 72 def foreground_codes { black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, light_grey: 37, default: 39, dark_grey: 90, light_red: 91, light_green: 92, light_yellow: 93, light_blue: 94, light_magenta: 95, light_cyan: 96, white: 97, } end |
#valid_codes ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 |
# File 'lib/vedeu/esc/colours.rb', line 95 def valid_codes @_valid_codes ||= foreground_codes.keys.map do |name| name.to_s.prepend('on_').to_sym end + foreground_codes.keys end |
#valid_name?(named_colour) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the colour provided is a valid named colour.
106 107 108 109 110 |
# File 'lib/vedeu/esc/colours.rb', line 106 def valid_name?(named_colour) return false unless symbol?(named_colour) valid_codes.include?(named_colour) end |