reinbow 1.2.0 → 2.0.0
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/lib/reinbow/painter.rb +8 -30
- data/lib/reinbow.rb +1 -10
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc98c589b653d5bacda7413a89cdebb71987a7e43a1b3e36fa09a9f106b8a87b
|
|
4
|
+
data.tar.gz: 7397cea4cc6e3776d84f176e722d18332607b715cfc8f1c2f5b0ca3fe914cbe7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47614281b1d5e9606bf33bb56ed3a09aed582d8afd37fddbcedd31d2a869d5b056aa079fd6e09466d9d958177c5d98e0799ac7a0e7d757ef62ad5aab6c9f0a8f
|
|
7
|
+
data.tar.gz: 3ad177fc8c88b76efe33225c74834d5ceb1fca60ba8005dcbd0696ba45a2f64f8cf1cd1f051c22dc17c1ba9d40b6cabcbf99a84bf2944c554659b0547cb7cc47
|
data/lib/reinbow/painter.rb
CHANGED
|
@@ -14,7 +14,6 @@ module Reinbow
|
|
|
14
14
|
# Accepts all parameters that String.new accepts.
|
|
15
15
|
def initialize( input )
|
|
16
16
|
@raw = input.to_s
|
|
17
|
-
@sgr_stack = []
|
|
18
17
|
|
|
19
18
|
# Ref: https://bixense.com/clicolors/
|
|
20
19
|
@enable = if ENV.key?( "NO_COLOR" )
|
|
@@ -26,14 +25,6 @@ module Reinbow
|
|
|
26
25
|
end
|
|
27
26
|
end
|
|
28
27
|
|
|
29
|
-
def reinbow? = @enable
|
|
30
|
-
|
|
31
|
-
def reinbow!( status = true )
|
|
32
|
-
@enable = status
|
|
33
|
-
self
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
|
|
37
28
|
#
|
|
38
29
|
# Define method for various color names
|
|
39
30
|
#
|
|
@@ -76,41 +67,28 @@ module Reinbow
|
|
|
76
67
|
raise ArgumentError, "layer should be one of :fg, :bg or :effect" \
|
|
77
68
|
unless layer in :fg | :bg | :effect
|
|
78
69
|
|
|
70
|
+
sgr_code = nil
|
|
71
|
+
|
|
79
72
|
case data
|
|
80
73
|
in Effect
|
|
81
74
|
data => { code: }
|
|
82
|
-
|
|
75
|
+
sgr_code = "\e[#{code}m"
|
|
83
76
|
in Ansi
|
|
84
77
|
data => { raw_code: }
|
|
85
78
|
code = raw_code + ( layer == :fg ? 30 : 40 )
|
|
86
|
-
|
|
79
|
+
sgr_code = "\e[#{code}m"
|
|
87
80
|
in Rgb
|
|
88
81
|
data => { red:, green:, blue: }
|
|
89
82
|
ground = layer == :fg ? 38 : 48
|
|
90
|
-
|
|
83
|
+
sgr_code = "\e[#{ground};2;#{red};#{green};#{blue}m"
|
|
91
84
|
else
|
|
92
|
-
raise NotImplementedError, "Can't paint #{
|
|
85
|
+
raise NotImplementedError, "Can't paint #{data.class}"
|
|
93
86
|
end
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#
|
|
100
|
-
# String behaviours
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
def to_s
|
|
104
|
-
if @enable
|
|
105
|
-
sgr = @sgr_stack.join( nil )
|
|
106
|
-
"#{sgr}#{@raw}\e[0m"
|
|
107
|
-
else
|
|
108
|
-
@raw
|
|
109
|
-
end
|
|
88
|
+
"#{sgr_code}#{@raw}" \
|
|
89
|
+
+ ( @raw.end_with?( "\e[0m" ) ? "" : "\e[0m" )
|
|
110
90
|
end
|
|
111
91
|
|
|
112
|
-
def +( other ) = to_s + other.to_s
|
|
113
|
-
|
|
114
92
|
end
|
|
115
93
|
|
|
116
94
|
end
|
data/lib/reinbow.rb
CHANGED
|
@@ -4,7 +4,7 @@ require_relative "./reinbow/painter.rb"
|
|
|
4
4
|
|
|
5
5
|
module Reinbow
|
|
6
6
|
|
|
7
|
-
VERSION = "
|
|
7
|
+
VERSION = "2.0.0"
|
|
8
8
|
|
|
9
9
|
refine String do
|
|
10
10
|
Painter.instance_methods( false ).each do |name|
|
|
@@ -15,12 +15,3 @@ module Reinbow
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
end
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# rubocop:disable Naming/MethodName
|
|
21
|
-
|
|
22
|
-
def Reinbow( content, enable_color: true )
|
|
23
|
-
Reinbow::Painter.new( content ).reinbow!( enable_color )
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# rubocop:enable Naming/MethodName
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reinbow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- MidAutumnMoon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Ruby gem for colorizing text in terminal
|
|
14
14
|
email:
|
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '0'
|
|
48
48
|
requirements: []
|
|
49
|
-
rubygems_version: 3.5.
|
|
49
|
+
rubygems_version: 3.5.21
|
|
50
50
|
signing_key:
|
|
51
51
|
specification_version: 4
|
|
52
52
|
summary: Ruby gem for colorizing text in terminal
|