ex_aequo 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +9 -3
- data/lib/ex_aequo/color/ansi.rb +36 -0
- data/lib/ex_aequo/color/ansi256.rb +19 -0
- data/lib/ex_aequo/color/colorizer.rb +22 -0
- data/lib/ex_aequo/color/rgb.rb +61 -0
- data/lib/ex_aequo/color.rb +40 -0
- data/lib/ex_aequo/version.rb +1 -1
- data/lib/ex_aequo.rb +7 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aae17031917aa3f9f0321d0f71f66e55a132f53220de7614edea1aced743b989
|
4
|
+
data.tar.gz: f47174e7f94bb872469c44dc13a2aef2f1ad418d39ac743fec13359a934e5b46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16bf984e4980c795890f5665ede3d3515c1c33872a023b346c689c2ffb83b293eb2ce06b76b363d6dc55c87f641c0cf72566b8dbad7456a742ffc0bb41d30a5f
|
7
|
+
data.tar.gz: 4294e88bd872a53906aa7155cdb53e0808ea4424a47170578b7faef553bcdee0ee11ef11e69abdea0a8855ab6942affe895124ce877529d3c8e388834cfb1688
|
data/README.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
[](https://gitlab.com/robert_dober/rb_ex_aequo/actions)
|
2
2
|
[](https://coveralls.io/gitlab/robert_dober/rb_ex_aequo?branch=master)
|
3
|
-
[](http://badge.fury.io/rb/ex_aequo)
|
4
|
+
[](https://rubygems.org/gems/ex_aequo)
|
5
5
|
|
6
|
-
#
|
6
|
+
# ExAequo
|
7
|
+
|
8
|
+
gem install ex_aequo
|
7
9
|
|
8
10
|
Some Tools
|
9
11
|
|
12
|
+
|
13
|
+
|
14
|
+
##
|
15
|
+
|
10
16
|
## LICENSE
|
11
17
|
|
12
18
|
Copyright 2022 Robert Dober robert.dober@gmail.com
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Color
|
5
|
+
module Ansi
|
6
|
+
extend self
|
7
|
+
|
8
|
+
AnsiColorEscape = {
|
9
|
+
black: 30,
|
10
|
+
red: 31,
|
11
|
+
green: 32,
|
12
|
+
yellow: 33,
|
13
|
+
blue: 34,
|
14
|
+
magenta: 35,
|
15
|
+
cyan: 36,
|
16
|
+
white: 37
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
def ansi(name)
|
20
|
+
case AnsiColorEscape.fetch(name.to_s.downcase.to_sym, nil)
|
21
|
+
in nil
|
22
|
+
raise IllegalColor, "#{name} is not one of the 8 legal basic ansi color names: #{_legal_ansi_color_names}"
|
23
|
+
in value
|
24
|
+
"\e[#{value}m"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def _legal_ansi_color_names
|
31
|
+
AnsiColorEscape.keys.inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Color
|
5
|
+
module Ansi256
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def ansi256(color)
|
9
|
+
case color
|
10
|
+
in 1..256
|
11
|
+
"\e[38;5;#{color}m"
|
12
|
+
else
|
13
|
+
raise IllegalColor, "#{color.inspect} is not a color number between 1 and 256"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Color
|
5
|
+
module Colorizer
|
6
|
+
extend self
|
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
|
12
|
+
|
13
|
+
[
|
14
|
+
ExAequo::Color.rgb(*Array(rgb)),
|
15
|
+
text,
|
16
|
+
reset ? ExAequo::Color.reset : nil
|
17
|
+
].join
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Color
|
5
|
+
module Rgb
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def rgb(red, green = nil, blue = nil)
|
9
|
+
if green && blue
|
10
|
+
_rgb(red, green, blue)
|
11
|
+
else
|
12
|
+
raise ArgumentError, 'takes 1 or 3 parameters, given two' if green
|
13
|
+
|
14
|
+
_rgb(*_hex_to_triple(red))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def _check_rgb(red, green, blue)
|
21
|
+
if _check_rgb_byte(red) && _check_rgb_byte(green) && _check_rgb_byte(blue)
|
22
|
+
:ok
|
23
|
+
else
|
24
|
+
"#{[red, green, blue]} is not a legal rgb specification, need three bytes (0..255)"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def _check_rgb_byte(byte)
|
29
|
+
case byte
|
30
|
+
in 0..255
|
31
|
+
true
|
32
|
+
else
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
LeadingHashRgx = %r{\A#}
|
38
|
+
def _hex_to_triple(hex)
|
39
|
+
chex = hex.sub(LeadingHashRgx, '')
|
40
|
+
case chex.grapheme_clusters.each_slice(2).map(&:join).map { Integer(_1, 16) }
|
41
|
+
in r, g, b
|
42
|
+
[r, g, b]
|
43
|
+
else
|
44
|
+
raise IllegalColor, "#{hex} is not a legal rgb hex string"
|
45
|
+
end
|
46
|
+
rescue ArgumentError
|
47
|
+
raise IllegalColor, "#{hex} is not a legal rgb hex string"
|
48
|
+
end
|
49
|
+
|
50
|
+
def _rgb(red, green, blue)
|
51
|
+
case _check_rgb(red, green, blue)
|
52
|
+
in :ok
|
53
|
+
"\e[38;2;#{red};#{green};#{blue}m"
|
54
|
+
in message
|
55
|
+
raise IllegalColor, message
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'color/ansi'
|
4
|
+
require_relative 'color/ansi256'
|
5
|
+
require_relative 'color/rgb'
|
6
|
+
|
7
|
+
require_relative 'color/colorizer'
|
8
|
+
|
9
|
+
module ExAequo
|
10
|
+
module Color
|
11
|
+
extend self
|
12
|
+
|
13
|
+
class IllegalColor < RuntimeError; end
|
14
|
+
|
15
|
+
def ansi(color)
|
16
|
+
ExAequo::Color::Ansi.ansi(color)
|
17
|
+
end
|
18
|
+
|
19
|
+
def ansi256(color)
|
20
|
+
ExAequo::Color::Ansi256.ansi256(color)
|
21
|
+
end
|
22
|
+
|
23
|
+
def colorize(text, **params)
|
24
|
+
if ENV['NO_COLOR']
|
25
|
+
text
|
26
|
+
else
|
27
|
+
ExAequo::Color::Colorizer.colorize(text, **params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
"\e[0m"
|
33
|
+
end
|
34
|
+
|
35
|
+
def rgb(*args)
|
36
|
+
ExAequo::Color::Rgb.rgb(*args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# SPDX-License-Identifier: Apache-2.0
|
data/lib/ex_aequo/version.rb
CHANGED
data/lib/ex_aequo.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ex_aequo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -20,6 +20,12 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- LICENSE
|
22
22
|
- README.md
|
23
|
+
- lib/ex_aequo.rb
|
24
|
+
- lib/ex_aequo/color.rb
|
25
|
+
- lib/ex_aequo/color/ansi.rb
|
26
|
+
- lib/ex_aequo/color/ansi256.rb
|
27
|
+
- lib/ex_aequo/color/colorizer.rb
|
28
|
+
- lib/ex_aequo/color/rgb.rb
|
23
29
|
- lib/ex_aequo/version.rb
|
24
30
|
homepage: https://gitlab.com/robert_dober/rb_ex_aequo
|
25
31
|
licenses:
|