ex_aequo 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aae17031917aa3f9f0321d0f71f66e55a132f53220de7614edea1aced743b989
4
- data.tar.gz: f47174e7f94bb872469c44dc13a2aef2f1ad418d39ac743fec13359a934e5b46
3
+ metadata.gz: 394e714f95ecbb3b54b5a264ce5be367d235fcebe7513b89d48d0491de236312
4
+ data.tar.gz: 177328fccfa5fbfd1911944ac5d6a65ccf7a7315589930d91beb764e413b2c4f
5
5
  SHA512:
6
- metadata.gz: 16bf984e4980c795890f5665ede3d3515c1c33872a023b346c689c2ffb83b293eb2ce06b76b363d6dc55c87f641c0cf72566b8dbad7456a742ffc0bb41d30a5f
7
- data.tar.gz: 4294e88bd872a53906aa7155cdb53e0808ea4424a47170578b7faef553bcdee0ee11ef11e69abdea0a8855ab6942affe895124ce877529d3c8e388834cfb1688
6
+ metadata.gz: c929dc3f52e077403241a32d114e36f76629f62c0da14d4927b03b6845bdfba0e3a1240d5a0b4285b048e2971a5898af675b86a80c5830fb35fc404a52d343ce
7
+ data.tar.gz: 2c2966155b1b3ddb5ca671105568248b8e1e1f6e1ebc205d4d91dc3582343969ecf1ca9bd56f2f7906f322011ab376047b699afea2c9925f1bedd399a32f7061
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'modifiers'
3
4
  module ExAequo
4
5
  module Color
5
6
  module Ansi
6
7
  extend self
8
+ include ExAequo::Color::Modifiers
7
9
 
8
10
  AnsiColorEscape = {
9
11
  black: 30,
@@ -16,12 +18,12 @@ module ExAequo
16
18
  white: 37
17
19
  }.freeze
18
20
 
19
- def ansi(name)
21
+ def ansi(name, bold: false, dim: false, italic: false, underline: false)
20
22
  case AnsiColorEscape.fetch(name.to_s.downcase.to_sym, nil)
21
23
  in nil
22
24
  raise IllegalColor, "#{name} is not one of the 8 legal basic ansi color names: #{_legal_ansi_color_names}"
23
25
  in value
24
- "\e[#{value}m"
26
+ "\e[#{value}#{postfix_modifiers(bold:, dim:, italic:, underline:)}m"
25
27
  end
26
28
  end
27
29
 
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'modifiers'
3
4
  module ExAequo
4
5
  module Color
5
6
  module Ansi256
6
7
  extend self
8
+ include ExAequo::Color::Modifiers
7
9
 
8
- def ansi256(color)
10
+ def ansi256(color, bold: false, dim: false, italic: false, underline: false)
9
11
  case color
10
12
  in 1..256
11
- "\e[38;5;#{color}m"
13
+ "\e[38;5;#{color}#{postfix_modifiers(bold:, dim:, italic:, underline:)}m"
12
14
  else
13
15
  raise IllegalColor, "#{color.inspect} is not a color number between 1 and 256"
14
16
  end
@@ -5,17 +5,71 @@ module ExAequo
5
5
  module Colorizer
6
6
  extend self
7
7
 
8
- def colorize(text, rgb: nil, ansi: nil, ansi256: nil, reset: true)
9
- unless [rgb, ansi, ansi256].compact.size == 1
10
- raise ArgumentError, 'need to specify exactly one of the following keyword arguments: :ansi, :ansi256, :rgb'
11
- end
8
+ ColorMethodKeywords = {
9
+ ansi: nil,
10
+ ansi256: nil,
11
+ rgb: nil,
12
+ web: nil
13
+ }.freeze
14
+
15
+ StyleKeywords = {
16
+ bold: nil,
17
+ dim: nil,
18
+ italic: nil,
19
+ underline: nil
20
+ }.freeze
21
+
22
+ ColorizeKeywords = ColorMethodKeywords.merge(StyleKeywords).merge(reset: true)
23
+
24
+ def colorize(text, **kwds)
25
+ kwds = ColorizeKeywords.merge(kwds)
26
+ _check_args!(kwds)
12
27
 
13
28
  [
14
- ExAequo::Color.rgb(*Array(rgb)),
29
+ _color_code(**kwds),
15
30
  text,
16
- reset ? ExAequo::Color.reset : nil
31
+ _maybe_reset(kwds[:reset])
17
32
  ].join
18
33
  end
34
+
35
+ private
36
+
37
+ def _check_args!(kwds)
38
+ spurious = kwds.keys - ColorizeKeywords.keys
39
+ raise ArgumentError, "illegal keywords #{spurious}, allowed: #{ColorizeKeywords.keys}" unless spurious.empty?
40
+
41
+ _check_rgb_args!(kwds)
42
+ end
43
+
44
+ def _check_rgb_args!(kwds)
45
+ unless kwds.values_at(*ColorMethodKeywords.keys).compact.size == 1
46
+ raise ArgumentError, 'need to specify exactly one of the following keyword arguments: :ansi, :ansi256, :rgb, :web'
47
+ end
48
+
49
+ if kwds[:rgb] && Access.any_key?(kwds, :bold, :dim)
50
+ raise(
51
+ ArgumentError,
52
+ 'specifying bold and/or dim with rgb does not make sense'
53
+ )
54
+ end
55
+ end
56
+
57
+ def _color_code(**kwds)
58
+ kwds => {ansi:, ansi256:, rgb:, web:, italic:, underline:}
59
+ if rgb
60
+ ExAequo::Color.rgb(*Array(rgb), italic:, underline:)
61
+ elsif web
62
+ ExAequo::Color.rgb(*ExAequo::Color::Web.to_rgb(web), italic:, underline:)
63
+ elsif ansi
64
+ ExAequo::Color.ansi(ansi, **kwds.slice(*StyleKeywords.keys))
65
+ else
66
+ ExAequo::Color.ansi256(ansi256, **kwds.slice(*StyleKeywords.keys))
67
+ end
68
+ end
69
+
70
+ def _maybe_reset(reset)
71
+ reset ? ExAequo::Color.reset : nil
72
+ end
19
73
  end
20
74
  end
21
75
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExAequo
4
+ module Color
5
+ module Modifiers extend self
6
+ ModifierValues = {
7
+ bold: 1,
8
+ dim: 2,
9
+ italic: 3,
10
+ underline: 4
11
+ }.freeze
12
+
13
+ def postfix_modifiers(bold: nil, dim: nil, italic: nil, underline: nil)
14
+ [
15
+ bold ? :bold : nil,
16
+ dim ? :dim : nil,
17
+ italic ? :italic : nil,
18
+ underline ? :underline : nil
19
+ ].compact
20
+ .map(&Access.hash_by_key(ModifierValues))
21
+ .map(&Fn.prefix_string(';'))
22
+ .join
23
+ end
24
+ end
25
+ end
26
+ end
27
+ # SPDX-License-Identifier: Apache-2.0
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'modifiers'
3
4
  module ExAequo
4
5
  module Color
5
6
  module Rgb
6
7
  extend self
7
8
 
8
- def rgb(red, green = nil, blue = nil)
9
+ def rgb(red, green = nil, blue = nil, **kwds)
9
10
  if green && blue
10
- _rgb(red, green, blue)
11
+ _rgb(red, green, blue, **kwds)
11
12
  else
12
13
  raise ArgumentError, 'takes 1 or 3 parameters, given two' if green
13
14
 
14
- _rgb(*_hex_to_triple(red))
15
+ _rgb(*_hex_to_triple(red), **kwds)
15
16
  end
16
17
  end
17
18
 
@@ -47,10 +48,11 @@ module ExAequo
47
48
  raise IllegalColor, "#{hex} is not a legal rgb hex string"
48
49
  end
49
50
 
50
- def _rgb(red, green, blue)
51
+ def _rgb(red, green, blue, italic: false, underline: false)
51
52
  case _check_rgb(red, green, blue)
52
53
  in :ok
53
- "\e[38;2;#{red};#{green};#{blue}m"
54
+ modifier = ExAequo::Color::Modifiers.postfix_modifiers(italic:, underline:)
55
+ "\e[38;2;#{red};#{green};#{blue}#{modifier}m"
54
56
  in message
55
57
  raise IllegalColor, message
56
58
  end
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExAequo
4
+ module Color
5
+ module Web
6
+ extend self
7
+
8
+ WebColorNames = {
9
+ 'aliceblue' => [240, 248, 255],
10
+ 'antiquewhite' => [250, 235, 215],
11
+ 'aqua' => [0, 255, 255],
12
+ 'aquamarine' => [127, 255, 212],
13
+ 'azure' => [240, 255, 255],
14
+ 'beige' => [245, 245, 220],
15
+ 'bisque' => [255, 228, 196],
16
+ 'black' => [0, 0, 0],
17
+ 'blanchedalmond' => [255, 235, 205],
18
+ 'blue' => [0, 0, 255],
19
+ 'blueviolet' => [138, 43, 226],
20
+ 'brown' => [165, 42, 42],
21
+ 'burlywood' => [222, 184, 135],
22
+ 'cadetblue' => [95, 158, 160],
23
+ 'chartreuse' => [127, 255, 0],
24
+ 'chocolate' => [210, 105, 30],
25
+ 'coral' => [255, 127, 80],
26
+ 'cornflowerblue' => [100, 149, 237],
27
+ 'cornsilk' => [255, 248, 220],
28
+ 'crimson' => [220, 20, 60],
29
+ 'cyan' => [0, 255, 255],
30
+ 'darkblue' => [0, 0, 139],
31
+ 'darkcyan' => [0, 139, 139],
32
+ 'darkgoldenrod' => [184, 134, 11],
33
+ 'darkgray' => [169, 169, 169],
34
+ 'darkgreen' => [0, 100, 0],
35
+ 'darkgrey' => [169, 169, 169],
36
+ 'darkkhaki' => [189, 183, 107],
37
+ 'darkmagenta' => [139, 0, 139],
38
+ 'darkolivegreen' => [85, 107, 47],
39
+ 'darkorange' => [255, 140, 0],
40
+ 'darkorchid' => [153, 50, 204],
41
+ 'darkred' => [139, 0, 0],
42
+ 'darksalmon' => [233, 150, 122],
43
+ 'darkseagreen' => [143, 188, 143],
44
+ 'darkslateblue' => [72, 61, 139],
45
+ 'darkslategray' => [47, 79, 79],
46
+ 'darkslategrey' => [47, 79, 79],
47
+ 'darkturquoise' => [0, 206, 209],
48
+ 'darkviolet' => [148, 0, 211],
49
+ 'deeppink' => [255, 20, 147],
50
+ 'deepskyblue' => [0, 191, 255],
51
+ 'dimgray' => [105, 105, 105],
52
+ 'dimgrey' => [105, 105, 105],
53
+ 'dodgerblue' => [30, 144, 255],
54
+ 'firebrick' => [178, 34, 34],
55
+ 'floralwhite' => [255, 250, 240],
56
+ 'forestgreen' => [34, 139, 34],
57
+ 'fuchsia' => [255, 0, 255],
58
+ 'gainsboro' => [220, 220, 220],
59
+ 'ghostwhite' => [248, 248, 255],
60
+ 'gold' => [255, 215, 0],
61
+ 'goldenrod' => [218, 165, 32],
62
+ 'gray' => [128, 128, 128],
63
+ 'green' => [0, 128, 0],
64
+ 'greenyellow' => [173, 255, 47],
65
+ 'grey' => [128, 128, 128],
66
+ 'honeydew' => [240, 255, 240],
67
+ 'hotpink' => [255, 105, 180],
68
+ 'indianred' => [205, 92, 92],
69
+ 'indigo' => [75, 0, 130],
70
+ 'ivory' => [255, 255, 240],
71
+ 'khaki' => [240, 230, 140],
72
+ 'lavender' => [230, 230, 250],
73
+ 'lavenderblush' => [255, 240, 245],
74
+ 'lawngreen' => [124, 252, 0],
75
+ 'lemonchiffon' => [255, 250, 205],
76
+ 'lightblue' => [173, 216, 230],
77
+ 'lightcoral' => [240, 128, 128],
78
+ 'lightcyan' => [224, 255, 255],
79
+ 'lightgoldenrodyellow' => [250, 250, 210],
80
+ 'lightgray' => [211, 211, 211],
81
+ 'lightgreen' => [144, 238, 144],
82
+ 'lightgrey' => [211, 211, 211],
83
+ 'lightpink' => [255, 182, 193],
84
+ 'lightsalmon' => [255, 160, 122],
85
+ 'lightseagreen' => [32, 178, 170],
86
+ 'lightskyblue' => [135, 206, 250],
87
+ 'lightslategray' => [119, 136, 153],
88
+ 'lightslategrey' => [119, 136, 153],
89
+ 'lightsteelblue' => [176, 196, 222],
90
+ 'lightyellow' => [255, 255, 224],
91
+ 'lime' => [0, 255, 0],
92
+ 'limegreen' => [50, 205, 50],
93
+ 'linen' => [250, 240, 230],
94
+ 'magenta' => [255, 0, 255],
95
+ 'maroon' => [128, 0, 0],
96
+ 'mediumaquamarine' => [102, 205, 170],
97
+ 'mediumblue' => [0, 0, 205],
98
+ 'mediumorchid' => [186, 85, 211],
99
+ 'mediumpurple' => [147, 112, 219],
100
+ 'mediumseagreen' => [60, 179, 113],
101
+ 'mediumslateblue' => [123, 104, 238],
102
+ 'mediumspringgreen' => [0, 250, 154],
103
+ 'mediumturquoise' => [72, 209, 204],
104
+ 'mediumvioletred' => [199, 21, 133],
105
+ 'midnightblue' => [25, 25, 112],
106
+ 'mintcream' => [245, 255, 250],
107
+ 'mistyrose' => [255, 228, 225],
108
+ 'moccasin' => [255, 228, 181],
109
+ 'navajowhite' => [255, 222, 173],
110
+ 'navy' => [0, 0, 128],
111
+ 'oldlace' => [253, 245, 230],
112
+ 'olive' => [128, 128, 0],
113
+ 'olivedrab' => [107, 142, 35],
114
+ 'orange' => [255, 165, 0],
115
+ 'orangered' => [255, 69, 0],
116
+ 'orchid' => [218, 112, 214],
117
+ 'palegoldenrod' => [238, 232, 170],
118
+ 'palegreen' => [152, 251, 152],
119
+ 'paleturquoise' => [175, 238, 238],
120
+ 'palevioletred' => [219, 112, 147],
121
+ 'papayawhip' => [255, 239, 213],
122
+ 'peachpuff' => [255, 218, 185],
123
+ 'peru' => [205, 133, 63],
124
+ 'pink' => [255, 192, 203],
125
+ 'plum' => [221, 160, 221],
126
+ 'powderblue' => [176, 224, 230],
127
+ 'purple' => [128, 0, 128],
128
+ 'red' => [255, 0, 0],
129
+ 'rosybrown' => [188, 143, 143],
130
+ 'royalblue' => [65, 105, 225],
131
+ 'saddlebrown' => [139, 69, 19],
132
+ 'salmon' => [250, 128, 114],
133
+ 'sandybrown' => [244, 164, 96],
134
+ 'seagreen' => [46, 139, 87],
135
+ 'seashell' => [255, 245, 238],
136
+ 'sienna' => [160, 82, 45],
137
+ 'silver' => [192, 192, 192],
138
+ 'skyblue' => [135, 206, 235],
139
+ 'slateblue' => [106, 90, 205],
140
+ 'slategray' => [112, 128, 144],
141
+ 'slategrey' => [112, 128, 144],
142
+ 'snow' => [255, 250, 250],
143
+ 'springgreen' => [0, 255, 127],
144
+ 'steelblue' => [70, 130, 180],
145
+ 'tan' => [210, 180, 140],
146
+ 'teal' => [0, 128, 128],
147
+ 'thistle' => [216, 191, 216],
148
+ 'tomato' => [255, 99, 71],
149
+ 'transparent' => [0, 0, 0],
150
+ 'turquoise' => [64, 224, 208],
151
+ 'violet' => [238, 130, 238],
152
+ 'wheat' => [245, 222, 179],
153
+ 'white' => [255, 255, 255],
154
+ 'whitesmoke' => [245, 245, 245],
155
+ 'yellow' => [255, 255, 0],
156
+ 'yellowgreen' => [154, 205, 50],
157
+ 'rebeccapurple' => [102, 51, 153]
158
+ }.freeze
159
+ def to_rgb(color)
160
+ WebColorNames.fetch(color.to_s.downcase) { raise ArgumentError, "unsupported web color: #{color}" }
161
+ end
162
+ end
163
+ end
164
+ end
165
+ # SPDX-License-Identifier: Apache-2.0
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'kernel/access'
4
+ require_relative 'kernel/fn'
5
+
3
6
  require_relative 'color/ansi'
4
7
  require_relative 'color/ansi256'
5
8
  require_relative 'color/rgb'
9
+ require_relative 'color/web'
6
10
 
7
11
  require_relative 'color/colorizer'
8
12
 
@@ -12,12 +16,12 @@ module ExAequo
12
16
 
13
17
  class IllegalColor < RuntimeError; end
14
18
 
15
- def ansi(color)
16
- ExAequo::Color::Ansi.ansi(color)
19
+ def ansi(color, **kwds)
20
+ ExAequo::Color::Ansi.ansi(color, **kwds)
17
21
  end
18
22
 
19
- def ansi256(color)
20
- ExAequo::Color::Ansi256.ansi256(color)
23
+ def ansi256(color, **kwds)
24
+ ExAequo::Color::Ansi256.ansi256(color, **kwds)
21
25
  end
22
26
 
23
27
  def colorize(text, **params)
@@ -32,8 +36,8 @@ module ExAequo
32
36
  "\e[0m"
33
37
  end
34
38
 
35
- def rgb(*args)
36
- ExAequo::Color::Rgb.rgb(*args)
39
+ def rgb(*args, **kwds)
40
+ ExAequo::Color::Rgb.rgb(*args, **kwds)
37
41
  end
38
42
  end
39
43
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Access
4
+ extend self
5
+
6
+ def any_key?(hash, *keys)
7
+ keys.flatten.reduce(false) { |_, key| return true if hash[key] }
8
+ false
9
+ end
10
+
11
+ def hash_by_key(hash)
12
+ ->(key) { hash[key] }
13
+ end
14
+ end
15
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fn
4
+ extend self
5
+ def prefix_string(with)
6
+ ->(subject) { "#{with}#{subject}" }
7
+ end
8
+ end
9
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'kernel/fn'
4
+ # SPDX-License-Identifier: Apache-2.0
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ExAequo
4
4
  module Version
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.3'
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ex_aequo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-19 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Some tools
14
14
 
@@ -25,7 +25,12 @@ files:
25
25
  - lib/ex_aequo/color/ansi.rb
26
26
  - lib/ex_aequo/color/ansi256.rb
27
27
  - lib/ex_aequo/color/colorizer.rb
28
+ - lib/ex_aequo/color/modifiers.rb
28
29
  - lib/ex_aequo/color/rgb.rb
30
+ - lib/ex_aequo/color/web.rb
31
+ - lib/ex_aequo/kernel.rb
32
+ - lib/ex_aequo/kernel/access.rb
33
+ - lib/ex_aequo/kernel/fn.rb
29
34
  - lib/ex_aequo/version.rb
30
35
  homepage: https://gitlab.com/robert_dober/rb_ex_aequo
31
36
  licenses: