ex_aequo 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/lib/ex_aequo/color/text.rb +48 -0
- data/lib/ex_aequo/tools/text_scanner.rb +17 -0
- data/lib/ex_aequo/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c6e147aed9d019eca15bd2ef01eca0a963865edc3836b62ade5ac56a33ac78
|
4
|
+
data.tar.gz: f3ada2a623e9f50109f64ca3e6c711e394ccbf7ef3b5f135ff8ece55fc832081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a74c191b8f1a45e81536e64c715611a2629a9a0a4c79418bdf1ab5f56c20fee4cadb6a4486c81888c8fafac68ec1b8a79f020eae7efc7c28d42a2897685cba0
|
7
|
+
data.tar.gz: c857b6f53336633ae930a6d0f0d2616bfae956baaa8353107ce1d00564261ebb1eb196f9f683cfc50d953ec72955dcd21b6986e99f53f0939287f0577aea4546
|
data/README.md
CHANGED
@@ -97,7 +97,7 @@ And, we can also provide allowed values (N.B. ruby sytnax is default)
|
|
97
97
|
|
98
98
|
## Context: Colors
|
99
99
|
|
100
|
-
Given the
|
100
|
+
Given the inclusion of the `Color` module
|
101
101
|
```ruby
|
102
102
|
include ExAequo::Color
|
103
103
|
```
|
@@ -131,14 +131,25 @@ Or we can omit the reset
|
|
131
131
|
expect(colorize('red', ansi: :green, reset: false)).to eq("\e[32mred")
|
132
132
|
```
|
133
133
|
|
134
|
+
### Context: Colorize Text
|
134
135
|
|
136
|
+
Given we include the Color::Text module
|
137
|
+
```ruby
|
138
|
+
require 'ex_aequo/color/text'
|
139
|
+
include ExAequo::Color::Text
|
140
|
+
```
|
135
141
|
|
142
|
+
Then we can obtain a colored text as follows
|
143
|
+
```ruby
|
144
|
+
expect(colorized_text(:red, 'green', :yellow, 'blue', :reset, 'white'))
|
145
|
+
.to eq("\e[31mgreen\e[33mblue\e[0mwhite")
|
146
|
+
```
|
136
147
|
|
137
|
-
|
148
|
+
## Other Tools are described [here](/speculations)
|
138
149
|
|
139
150
|
## LICENSE
|
140
151
|
|
141
|
-
Copyright
|
152
|
+
Copyright 202[2,3] Robert Dober robert.dober@gmail.com
|
142
153
|
|
143
154
|
Apache-2.0 [c.f LICENSE](LICENSE)
|
144
155
|
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Color
|
5
|
+
module Text extend self
|
6
|
+
|
7
|
+
def put_col(*segments, to: $stdout)
|
8
|
+
to.puts(colorized_text(segments))
|
9
|
+
end
|
10
|
+
|
11
|
+
def colorized_text(*segments)
|
12
|
+
if ENV['NO_COLOR']
|
13
|
+
segments.flatten.filter { String === _1 }.join
|
14
|
+
else
|
15
|
+
segments.flatten.map(&_color_or_text).join
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
|
22
|
+
def _color_or_text
|
23
|
+
-> color_or_text do
|
24
|
+
case color_or_text
|
25
|
+
when Symbol
|
26
|
+
_colorize(color_or_text)
|
27
|
+
else
|
28
|
+
color_or_text
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def _colorize(color)
|
34
|
+
case ExAequo::Color::Ansi::AnsiColorEscape[color]
|
35
|
+
when nil
|
36
|
+
if color == :reset
|
37
|
+
ExAequo::Color.reset
|
38
|
+
else
|
39
|
+
raise ArgumentError, "#{color} not yet implemented"
|
40
|
+
end
|
41
|
+
else
|
42
|
+
ExAequo::Color::Ansi.ansi(color)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExAequo
|
4
|
+
module Tools
|
5
|
+
module TextScanner extend self
|
6
|
+
def scan(str, rgx: '/', ws_at_end: true)
|
7
|
+
r = Regexp === rgx ? r : Regex.compile(rgx)
|
8
|
+
_scan(str, rgx: r, ws_at_end:)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def _scan(str, rgx:, ws_at_end:)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
# 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.2.
|
4
|
+
version: 0.2.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: 2023-
|
11
|
+
date: 2023-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwarder3
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/ex_aequo/color/colorizer.rb
|
44
44
|
- lib/ex_aequo/color/modifiers.rb
|
45
45
|
- lib/ex_aequo/color/rgb.rb
|
46
|
+
- lib/ex_aequo/color/text.rb
|
46
47
|
- lib/ex_aequo/color/web.rb
|
47
48
|
- lib/ex_aequo/colors.rb
|
48
49
|
- lib/ex_aequo/kernel.rb
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- lib/ex_aequo/kernel/fn.rb
|
51
52
|
- lib/ex_aequo/my_struct.rb
|
52
53
|
- lib/ex_aequo/my_struct/class_methods.rb
|
54
|
+
- lib/ex_aequo/tools/text_scanner.rb
|
53
55
|
- lib/ex_aequo/version.rb
|
54
56
|
homepage: https://gitlab.com/robert_dober/rb_ex_aequo
|
55
57
|
licenses:
|