ex_aequo 0.1.0 → 0.1.2
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 +38 -0
- data/lib/ex_aequo/color/ansi256.rb +21 -0
- data/lib/ex_aequo/color/colorizer.rb +73 -0
- data/lib/ex_aequo/color/modifiers.rb +27 -0
- data/lib/ex_aequo/color/rgb.rb +63 -0
- data/lib/ex_aequo/color.rb +43 -0
- data/lib/ex_aequo/kernel/access.rb +15 -0
- data/lib/ex_aequo/kernel/fn.rb +9 -0
- data/lib/ex_aequo/kernel.rb +4 -0
- data/lib/ex_aequo/version.rb +1 -1
- data/lib/ex_aequo.rb +7 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6cd6a07b2a9d435aeadf493afb7c3efb927697e24ba774e524d2c05d0345dc
|
4
|
+
data.tar.gz: 6d7ad31a36ccd40db1673cf2bb9e50303cb23300a1f0455fcdae85cb217c21ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d58560196e7c7a9ba5ab95eacced6545843a35e12c0b5cea22e43cdeb3e2d416012e4328f625d482dfdcce77b18d83320b22ac0224764555220e8fc750bd026
|
7
|
+
data.tar.gz: 1f4ca9354ac79edd8cb66690bb2b89986bd2a1411393862be7baefbfcd8dbfc62d349dad1f7f4cf4d7146636bc54049295ab0cbacd044bd52ca81c3160619b91
|
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,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'modifiers'
|
4
|
+
module ExAequo
|
5
|
+
module Color
|
6
|
+
module Ansi
|
7
|
+
extend self
|
8
|
+
include ExAequo::Color::Modifiers
|
9
|
+
|
10
|
+
AnsiColorEscape = {
|
11
|
+
black: 30,
|
12
|
+
red: 31,
|
13
|
+
green: 32,
|
14
|
+
yellow: 33,
|
15
|
+
blue: 34,
|
16
|
+
magenta: 35,
|
17
|
+
cyan: 36,
|
18
|
+
white: 37
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def ansi(name, bold: false, dim: false, italic: false, underline: false)
|
22
|
+
case AnsiColorEscape.fetch(name.to_s.downcase.to_sym, nil)
|
23
|
+
in nil
|
24
|
+
raise IllegalColor, "#{name} is not one of the 8 legal basic ansi color names: #{_legal_ansi_color_names}"
|
25
|
+
in value
|
26
|
+
"\e[#{value}#{postfix_modifiers(bold:, dim:, italic:, underline:)}m"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def _legal_ansi_color_names
|
33
|
+
AnsiColorEscape.keys.inspect
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'modifiers'
|
4
|
+
module ExAequo
|
5
|
+
module Color
|
6
|
+
module Ansi256
|
7
|
+
extend self
|
8
|
+
include ExAequo::Color::Modifiers
|
9
|
+
|
10
|
+
def ansi256(color, bold: false, dim: false, italic: false, underline: false)
|
11
|
+
case color
|
12
|
+
in 1..256
|
13
|
+
"\e[38;5;#{color}#{postfix_modifiers(bold:, dim:, italic:, underline:)}m"
|
14
|
+
else
|
15
|
+
raise IllegalColor, "#{color.inspect} is not a color number between 1 and 256"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Color
|
5
|
+
module Colorizer
|
6
|
+
extend self
|
7
|
+
|
8
|
+
ColorMethodKeywords = {
|
9
|
+
ansi: nil,
|
10
|
+
ansi256: nil,
|
11
|
+
rgb: nil,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
StyleKeywords = {
|
15
|
+
bold: nil,
|
16
|
+
dim: nil,
|
17
|
+
italic: nil,
|
18
|
+
underline: nil
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
ColorizeKeywords = ColorMethodKeywords.merge(StyleKeywords).merge(reset: true)
|
22
|
+
|
23
|
+
def colorize(text, **kwds)
|
24
|
+
kwds = ColorizeKeywords.merge(kwds)
|
25
|
+
_check_args!(kwds)
|
26
|
+
|
27
|
+
[
|
28
|
+
_color_code(**kwds),
|
29
|
+
text,
|
30
|
+
_maybe_reset(kwds[:reset])
|
31
|
+
].join
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def _check_args!(kwds)
|
37
|
+
spurious = kwds.keys - ColorizeKeywords.keys
|
38
|
+
raise ArgumentError, "illegal keywords #{spurious}, allowed: #{ColorizeKeywords.keys}" unless spurious.empty?
|
39
|
+
|
40
|
+
_check_rgb_args!(kwds)
|
41
|
+
end
|
42
|
+
|
43
|
+
def _check_rgb_args!(kwds)
|
44
|
+
unless kwds.values_at(*ColorMethodKeywords.keys).compact.size == 1
|
45
|
+
raise ArgumentError, 'need to specify exactly one of the following keyword arguments: :ansi, :ansi256, :rgb'
|
46
|
+
end
|
47
|
+
|
48
|
+
if kwds[:rgb] && Access.any_key?(kwds, :bold, :dim)
|
49
|
+
raise(
|
50
|
+
ArgumentError,
|
51
|
+
'specifying bold and/or dim with rgb does not make sense'
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def _color_code(**kwds)
|
57
|
+
kwds => {ansi:, ansi256:, rgb:, italic:, underline:}
|
58
|
+
if rgb
|
59
|
+
ExAequo::Color.rgb(*Array(rgb), italic:, underline:)
|
60
|
+
elsif ansi
|
61
|
+
ExAequo::Color.ansi(ansi, **kwds.slice(*StyleKeywords.keys))
|
62
|
+
else
|
63
|
+
ExAequo::Color.ansi256(ansi256, **kwds.slice(*StyleKeywords.keys))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def _maybe_reset(reset)
|
68
|
+
reset ? ExAequo::Color.reset : nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -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
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'modifiers'
|
4
|
+
module ExAequo
|
5
|
+
module Color
|
6
|
+
module Rgb
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def rgb(red, green = nil, blue = nil, **kwds)
|
10
|
+
if green && blue
|
11
|
+
_rgb(red, green, blue, **kwds)
|
12
|
+
else
|
13
|
+
raise ArgumentError, 'takes 1 or 3 parameters, given two' if green
|
14
|
+
|
15
|
+
_rgb(*_hex_to_triple(red), **kwds)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def _check_rgb(red, green, blue)
|
22
|
+
if _check_rgb_byte(red) && _check_rgb_byte(green) && _check_rgb_byte(blue)
|
23
|
+
:ok
|
24
|
+
else
|
25
|
+
"#{[red, green, blue]} is not a legal rgb specification, need three bytes (0..255)"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def _check_rgb_byte(byte)
|
30
|
+
case byte
|
31
|
+
in 0..255
|
32
|
+
true
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
LeadingHashRgx = %r{\A#}
|
39
|
+
def _hex_to_triple(hex)
|
40
|
+
chex = hex.sub(LeadingHashRgx, '')
|
41
|
+
case chex.grapheme_clusters.each_slice(2).map(&:join).map { Integer(_1, 16) }
|
42
|
+
in r, g, b
|
43
|
+
[r, g, b]
|
44
|
+
else
|
45
|
+
raise IllegalColor, "#{hex} is not a legal rgb hex string"
|
46
|
+
end
|
47
|
+
rescue ArgumentError
|
48
|
+
raise IllegalColor, "#{hex} is not a legal rgb hex string"
|
49
|
+
end
|
50
|
+
|
51
|
+
def _rgb(red, green, blue, italic: false, underline: false)
|
52
|
+
case _check_rgb(red, green, blue)
|
53
|
+
in :ok
|
54
|
+
modifier = ExAequo::Color::Modifiers.postfix_modifiers(italic:, underline:)
|
55
|
+
"\e[38;2;#{red};#{green};#{blue}#{modifier}m"
|
56
|
+
in message
|
57
|
+
raise IllegalColor, message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'kernel/access'
|
4
|
+
require_relative 'kernel/fn'
|
5
|
+
|
6
|
+
require_relative 'color/ansi'
|
7
|
+
require_relative 'color/ansi256'
|
8
|
+
require_relative 'color/rgb'
|
9
|
+
|
10
|
+
require_relative 'color/colorizer'
|
11
|
+
|
12
|
+
module ExAequo
|
13
|
+
module Color
|
14
|
+
extend self
|
15
|
+
|
16
|
+
class IllegalColor < RuntimeError; end
|
17
|
+
|
18
|
+
def ansi(color, **kwds)
|
19
|
+
ExAequo::Color::Ansi.ansi(color, **kwds)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ansi256(color, **kwds)
|
23
|
+
ExAequo::Color::Ansi256.ansi256(color, **kwds)
|
24
|
+
end
|
25
|
+
|
26
|
+
def colorize(text, **params)
|
27
|
+
if ENV['NO_COLOR']
|
28
|
+
text
|
29
|
+
else
|
30
|
+
ExAequo::Color::Colorizer.colorize(text, **params)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset
|
35
|
+
"\e[0m"
|
36
|
+
end
|
37
|
+
|
38
|
+
def rgb(*args, **kwds)
|
39
|
+
ExAequo::Color::Rgb.rgb(*args, **kwds)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -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
|
data/lib/ex_aequo/version.rb
CHANGED
data/lib/ex_aequo.rb
ADDED
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.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2022-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Some tools
|
14
14
|
|
@@ -20,6 +20,16 @@ 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/modifiers.rb
|
29
|
+
- lib/ex_aequo/color/rgb.rb
|
30
|
+
- lib/ex_aequo/kernel.rb
|
31
|
+
- lib/ex_aequo/kernel/access.rb
|
32
|
+
- lib/ex_aequo/kernel/fn.rb
|
23
33
|
- lib/ex_aequo/version.rb
|
24
34
|
homepage: https://gitlab.com/robert_dober/rb_ex_aequo
|
25
35
|
licenses:
|