term_color 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -14
- data/lib/term_color/rule.rb +67 -5
- 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: a5c5c053cd07cea1249b693d74cd9f0bb063b0c2be81e4ca8ee50c1e43789273
|
4
|
+
data.tar.gz: 2db955626d5da3fd4d5299a36487c854c8f2386ce0d332589bc73694551cc256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8755f513658b1233352886f93325de9dc84f393f4509cc46b9cd29815ef81a1ed0c59749f2468d89edf5944aa6b763e3d7a5cbb5ca8cfc3b85e79ebb64c164e8
|
7
|
+
data.tar.gz: 7d852dc156d2c00483142547cb24add1d252a42b9ad3e994ace9bf72c41da66d95633ed6ae3876e4209a4d7c09c20a560f4a00a776d299324957b9537001d2bd
|
data/README.md
CHANGED
@@ -93,37 +93,71 @@ r = { fg: :red, bg: :blue }
|
|
93
93
|
r = { after: { reset: :all} }
|
94
94
|
```
|
95
95
|
|
96
|
-
|
96
|
+
## Rule Parts/Actions
|
97
97
|
|
98
|
-
|
98
|
+
Option parts / actions available to rule definitions.
|
99
99
|
|
100
|
-
|
100
|
+
### Colors
|
101
|
+
|
102
|
+
#### Attributes
|
101
103
|
|
102
104
|
- `fg` - Change foreground color
|
103
105
|
- `bg` - Change background color
|
104
106
|
|
105
|
-
|
107
|
+
#### Values
|
108
|
+
|
109
|
+
_If images don't show up, try viewing on [Github](https://github.com/vdtdev/term_color/blob/master/README.md)_
|
110
|
+
|
111
|
+
##### Standard Named Colors
|
112
|
+
|
113
|
+
Color values can be color-name symbols as defined in {TermColor::Rule::Colors Rule::Colors} (`:black, :red, :yellow, :blue, :magenta, :cyan, :white, :bright_black, :bright_red, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white`)
|
106
114
|
|
107
|
-
|
115
|
+
```ruby
|
116
|
+
rs = TermColor.create_rule_set({
|
117
|
+
named: { fg: :yellow, bg: :blue }
|
118
|
+
})
|
119
|
+
rs.print "Before {%namedHello!%}\n"
|
120
|
+
```
|
108
121
|
|
109
|
-
|
122
|
+
![](./docs/colors_named.png)
|
123
|
+
![](./file/docs/colors_named.png)
|
110
124
|
|
111
|
-
|
125
|
+
##### XTerm 256 Color Values
|
112
126
|
|
113
127
|
To use XTerm 256 Color Mode values, include the color code integer inside a single item array. (E.g. for code `208`, use `[208]`)
|
114
128
|
|
115
|
-
|
129
|
+
```ruby
|
130
|
+
rs = TermColor.create_rule_set({
|
131
|
+
x256: { fg: [226], bg: [56] }
|
132
|
+
})
|
133
|
+
rs.print "Before {%x256Hello!%}\n"
|
134
|
+
```
|
135
|
+
|
136
|
+
![](./docs/colors_256.png)
|
137
|
+
![](./file/docs/colors_256.png)
|
138
|
+
|
139
|
+
##### XTerm 16m Color Values
|
116
140
|
|
117
141
|
To use XTerm 16m Color Mode RGB colors, include the red, green and blue color values in an ordered array (E.g. for 80 red, 80 green, 255 blue, use `[80,80,255]`)
|
118
142
|
|
119
|
-
|
143
|
+
```ruby
|
144
|
+
rs = TermColor.create_rule_set({
|
145
|
+
x16: { fg: [255,250,11], bg: [15,15,200] }
|
146
|
+
})
|
147
|
+
rs.print "Before {%x16Hello!%}\n"
|
148
|
+
```
|
149
|
+
|
150
|
+
![](./docs/colors_16m.png)
|
151
|
+
![](./file/docs/colors_16m.png)
|
120
152
|
|
121
|
-
|
153
|
+
### Styles
|
154
|
+
|
155
|
+
#### Actions
|
122
156
|
|
123
157
|
- `enable` - Style(s) to enable (Can be single item or array)
|
124
158
|
- `disable` - Style(s) to disable (Can be single item or array)
|
125
159
|
|
126
|
-
|
160
|
+
#### Values
|
127
161
|
|
128
162
|
(See symbols in {TermColor::Rule::Styles})
|
129
163
|
|
@@ -135,7 +169,7 @@ To use XTerm 16m Color Mode RGB colors, include the red, green and blue color va
|
|
135
169
|
- `:hidden`
|
136
170
|
- `:strikethrough`
|
137
171
|
|
138
|
-
|
172
|
+
### Reset / Keep
|
139
173
|
|
140
174
|
_(Only valid in `after` section)_
|
141
175
|
|
@@ -154,8 +188,6 @@ Quick way of resetting one or more style rules. `reset`/`keep` can be given a si
|
|
154
188
|
- `:style` - Reset all styling
|
155
189
|
- `:all` - Reset all colors and styling
|
156
190
|
|
157
|
-
[If example images are missing, view readme on github](https://github.com/vdtdev/term_color/blob/master/README.md)
|
158
|
-
|
159
191
|
## Examples
|
160
192
|
|
161
193
|
_If images don't show up, try viewing on [Github](https://github.com/vdtdev/term_color/blob/master/README.md)_
|
data/lib/term_color/rule.rb
CHANGED
@@ -39,10 +39,18 @@ module TermColor
|
|
39
39
|
blue: 4,
|
40
40
|
magenta: 5,
|
41
41
|
cyan: 6,
|
42
|
-
white: 7
|
42
|
+
white: 7,
|
43
|
+
bright_black: 60,
|
44
|
+
bright_red: 61,
|
45
|
+
bright_green: 62,
|
46
|
+
bright_yellow: 63,
|
47
|
+
bright_blue: 64,
|
48
|
+
bright_magenta: 65,
|
49
|
+
bright_cyan: 66,
|
50
|
+
bright_white: 67
|
43
51
|
}.freeze
|
44
52
|
|
45
|
-
|
53
|
+
##
|
46
54
|
# Numerical modifiers used with Color Values
|
47
55
|
# to target foreground or background.
|
48
56
|
#
|
@@ -240,6 +248,30 @@ module TermColor
|
|
240
248
|
codes = codes.flatten.compact.uniq
|
241
249
|
end
|
242
250
|
|
251
|
+
##
|
252
|
+
# Resolve named color, allowing fg target colors
|
253
|
+
# to use names prefixed with `light_` (e.g. `:light_blue`)
|
254
|
+
# def resolve_named_color(color, target = :fg)
|
255
|
+
# sym = color.to_sym
|
256
|
+
# unless target == :fg
|
257
|
+
# # strip out any light_ prefix if not targetting :fg
|
258
|
+
# sym = (sym.to_s.gsub('light_','')).to_sym
|
259
|
+
# end
|
260
|
+
# if Colors.has_key?(sym)
|
261
|
+
# # Name found, return value + fg target
|
262
|
+
# return [Colors[sym].to_i]
|
263
|
+
# end
|
264
|
+
# pre,name = sym.to_s.split("_")
|
265
|
+
# if pre == 'light' && !name.nil? && Colors.has_key?(name.to_sym)
|
266
|
+
# # Named color with 'light_' prefix
|
267
|
+
# # Return color code along with Proc to format with "1;val"
|
268
|
+
# return [Colors[name.to_sym].to_i, Proc.new {|c| "1;#{c}" }]
|
269
|
+
# end
|
270
|
+
|
271
|
+
# # Give back 0 if not resolved
|
272
|
+
# return 0
|
273
|
+
# end
|
274
|
+
|
243
275
|
def resolve_color(color, target = :fg)
|
244
276
|
if color.is_a?(Array)
|
245
277
|
color = color[0..2]
|
@@ -253,7 +285,7 @@ module TermColor
|
|
253
285
|
end
|
254
286
|
color = Colors[color.to_sym].to_i
|
255
287
|
end
|
256
|
-
|
288
|
+
color + ColorTargets[target.to_sym].to_i
|
257
289
|
end
|
258
290
|
|
259
291
|
def resolve_style(style, state = :enable)
|
@@ -339,6 +371,15 @@ module TermColor
|
|
339
371
|
return parts.merge({evaluated: true})
|
340
372
|
end
|
341
373
|
|
374
|
+
##
|
375
|
+
# Normalize a rule's part, making sure all possible keys
|
376
|
+
# exist with at least `nil` values, and values that can be arrays
|
377
|
+
# are at least empty arrays, or arrays containing singular value
|
378
|
+
# @param [Hash] hash Input part to normalize
|
379
|
+
# @param [Symbol] part Which part to normalize {TermColor::Rule::PartOps}
|
380
|
+
# @param [Boolean] clean If true, strip out all values that are nil
|
381
|
+
# or empty arrays (default `false`)
|
382
|
+
# @return [Hash] Copy of input hash after normalization is applied
|
342
383
|
def normalize_part(hash,part,clean=false)
|
343
384
|
h = hash.dup
|
344
385
|
PartOps[part].each do |o|
|
@@ -356,6 +397,17 @@ module TermColor
|
|
356
397
|
return h
|
357
398
|
end
|
358
399
|
|
400
|
+
##
|
401
|
+
# Combine an 'override' version of a rule's after part with a
|
402
|
+
# default 'after' part, resulting in the original default 'after' part
|
403
|
+
# with any adjustments needed to apply rules from override
|
404
|
+
# @param [Hash] inside 'Inside' part of rule, used to expand
|
405
|
+
# `reset: :style` into specific `disable`
|
406
|
+
# @param [Hash] override Override version of after to apply to given
|
407
|
+
# default
|
408
|
+
# @param [Hash] after Default 'after' part to be overridden
|
409
|
+
# @return [Hash] Overridden version of after rules
|
410
|
+
# @see normalize_part
|
359
411
|
def override_after(inside, override, after)
|
360
412
|
c_ovr = normalize_part(override, :after)
|
361
413
|
c_aft = normalize_part(after, :after)
|
@@ -414,9 +466,18 @@ module TermColor
|
|
414
466
|
return normalize_part(result, :after, true)
|
415
467
|
end
|
416
468
|
|
469
|
+
##
|
470
|
+
# Build after rule automatically based on inside portion of
|
471
|
+
# rule, treating given existing explict 'after' rules as overrides
|
472
|
+
# @param [Hash] inside Inside portion of rule to generate after for
|
473
|
+
# @param [Hash] after Explicitly defined after section of source rule,
|
474
|
+
# combined with result by treating as overrides
|
475
|
+
# @return [Hash] Generated 'after' rules
|
417
476
|
def build_auto_after(inside, after={})
|
418
477
|
c_inside = normalize_part(inside, :inside)
|
419
|
-
n_after = normalize_part({}, :after)
|
478
|
+
# n_after = normalize_part({}, :after)
|
479
|
+
# TODO: Test to make sure the below fixed line doesn't break stuff :)
|
480
|
+
n_after = normalize_part(after, :after)
|
420
481
|
|
421
482
|
if c_inside[:enable].length > 0
|
422
483
|
n_after[:reset] += [:style]
|
@@ -428,7 +489,8 @@ module TermColor
|
|
428
489
|
end
|
429
490
|
end
|
430
491
|
|
431
|
-
|
492
|
+
# Combine override after section
|
493
|
+
rules = override_after(inside, after, n_after)
|
432
494
|
end
|
433
495
|
|
434
496
|
##
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: term_color
|
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
|
- Wade H.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -46,7 +46,7 @@ licenses:
|
|
46
46
|
- MIT
|
47
47
|
metadata:
|
48
48
|
source_code_uri: https://github.com/vdtdev/term_color
|
49
|
-
documentation_uri: https://rubydoc.info/gems/term_color/0.1.
|
49
|
+
documentation_uri: https://rubydoc.info/gems/term_color/0.1.1
|
50
50
|
post_install_message:
|
51
51
|
rdoc_options: []
|
52
52
|
require_paths:
|