ex_aequo 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ex_aequo/color/ansi.rb +4 -2
- data/lib/ex_aequo/color/ansi256.rb +4 -2
- data/lib/ex_aequo/color/colorizer.rb +57 -6
- data/lib/ex_aequo/color/modifiers.rb +27 -0
- data/lib/ex_aequo/color/rgb.rb +7 -5
- data/lib/ex_aequo/color.rb +9 -6
- 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
- metadata +6 -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/lib/ex_aequo/color/ansi.rb
CHANGED
@@ -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,68 @@ module ExAequo
|
|
5
5
|
module Colorizer
|
6
6
|
extend self
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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)
|
12
26
|
|
13
27
|
[
|
14
|
-
|
28
|
+
_color_code(**kwds),
|
15
29
|
text,
|
16
|
-
reset
|
30
|
+
_maybe_reset(kwds[:reset])
|
17
31
|
].join
|
18
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
|
19
70
|
end
|
20
71
|
end
|
21
72
|
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
|
data/lib/ex_aequo/color/rgb.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/ex_aequo/color.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
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'
|
@@ -12,12 +15,12 @@ module ExAequo
|
|
12
15
|
|
13
16
|
class IllegalColor < RuntimeError; end
|
14
17
|
|
15
|
-
def ansi(color)
|
16
|
-
ExAequo::Color::Ansi.ansi(color)
|
18
|
+
def ansi(color, **kwds)
|
19
|
+
ExAequo::Color::Ansi.ansi(color, **kwds)
|
17
20
|
end
|
18
21
|
|
19
|
-
def ansi256(color)
|
20
|
-
ExAequo::Color::Ansi256.ansi256(color)
|
22
|
+
def ansi256(color, **kwds)
|
23
|
+
ExAequo::Color::Ansi256.ansi256(color, **kwds)
|
21
24
|
end
|
22
25
|
|
23
26
|
def colorize(text, **params)
|
@@ -32,8 +35,8 @@ module ExAequo
|
|
32
35
|
"\e[0m"
|
33
36
|
end
|
34
37
|
|
35
|
-
def rgb(*args)
|
36
|
-
ExAequo::Color::Rgb.rgb(*args)
|
38
|
+
def rgb(*args, **kwds)
|
39
|
+
ExAequo::Color::Rgb.rgb(*args, **kwds)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
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
|
data/lib/ex_aequo/version.rb
CHANGED
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
|
|
@@ -25,7 +25,11 @@ 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/kernel.rb
|
31
|
+
- lib/ex_aequo/kernel/access.rb
|
32
|
+
- lib/ex_aequo/kernel/fn.rb
|
29
33
|
- lib/ex_aequo/version.rb
|
30
34
|
homepage: https://gitlab.com/robert_dober/rb_ex_aequo
|
31
35
|
licenses:
|