color_me_rad 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cbbd4b90433cc887ccb37d0aaa93ca552b1856074f7033caf57a466b128393b
4
- data.tar.gz: 9d5d7b7c35f63cd083377dfac5b04f3a57e2979d624b34aa848da615fc0ffbd0
3
+ metadata.gz: bdfeeccfdcd9b4de8a6ae0e55b3596e9b254d698c6ee052aa3e9c56409c2b83c
4
+ data.tar.gz: 263dab043bc2cc5690327112bb5171650720bdf17d5e078e64302d4e56c47fe2
5
5
  SHA512:
6
- metadata.gz: 9c4c171654e4390dda6a105e9e91fbc019e649697a9d33b5002b52c22ce60814e6f19b076956d66d858a25bd9a499453a8d8fc69632bc578b51ae2fb0822a54b
7
- data.tar.gz: 2744bc8e9fc69bba9fc647dd2612118ecd670a4d1238bd2ce927daae74acaa9c9722707b05e88c8a6fbab5b70e0559d863b93689c6e01fced519d31eb4b0dc78
6
+ metadata.gz: 48bb56e8265f18a0e034705eccf7845d9c76e4824e208d47c9164866f9e67b390d77567d850ca34ce7615b8ec8daa31c636e8abb92c2126ee9930f6a285620c9
7
+ data.tar.gz: 47421db76bd6ba8a30dafb98fb1d4fd99e78381c47c409f584b87b5668f23afeff9ee1818124138763597113e22fd0aadc43a6e25b465fda93470ea8bf2a54f7
@@ -0,0 +1 @@
1
+ plans/
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.5.1
1
+ ruby 2.7.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- color_me_rad (0.0.4)
4
+ color_me_rad (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -42,4 +42,4 @@ DEPENDENCIES
42
42
  rspec
43
43
 
44
44
  BUNDLED WITH
45
- 1.16.3
45
+ 2.2.16
@@ -0,0 +1 @@
1
+ 484f40c8c86d889bdf97c7154bbb7b3f
@@ -0,0 +1 @@
1
+ 8f52cf27f013b5941627ddafde3bfce6f1cdf164f9356a4b87b10ce3ec7d730e
@@ -0,0 +1 @@
1
+ f8fa0000a5ac1f713a6e503e5d192de090a0d6c2ab766861af562d640277ebd400c9cca9c796fb72bf82b62a605775df3403122ae97be861ec117ea7f7bd5d47
data/color_me_rad.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'color_me_rad'
3
- spec.version = '0.0.4'
3
+ spec.version = '0.0.5'
4
4
  spec.authors = ['Travis Herrick']
5
5
  spec.email = ['tthetoad@gmail.com']
6
6
 
@@ -91,7 +91,7 @@ module ColorMeRad
91
91
  data = data.inspect if [NilClass, Symbol].include?(data.class)
92
92
  data = data.to_s unless data.is_a?(String)
93
93
 
94
- ColorMeRad.colorize data, color
94
+ ColorMeRad.colorize data, *Array(color)
95
95
  end
96
96
 
97
97
  def colorize(text, foreground = nil, background = nil)
@@ -14,11 +14,17 @@ module ColorMeRad
14
14
  :default => 9
15
15
  }
16
16
 
17
- def colorize(text, foreground, background)
17
+ STYLES = {
18
+ :bold => 1,
19
+ :dim => 2,
20
+ }
21
+
22
+ def colorize(text, foreground, background, *styles)
18
23
  return text unless ColorMeRad.enabled?
19
24
 
20
25
  text = set_foreground(text, foreground) if foreground
21
26
  text = set_background(text, background) if background
27
+ styles.each { |style| text = set_style(text, style) }
22
28
 
23
29
  text
24
30
  end
@@ -28,6 +34,13 @@ module ColorMeRad
28
34
  message = sample_message(background, foreground, 13)
29
35
  puts colorize(message, foreground, background)
30
36
  end
37
+
38
+ STYLES.keys.each do |style|
39
+ CODES.keys.each do |foreground|
40
+ message = sample_message(style, foreground, 13)
41
+ puts colorize(message, foreground, nil, style)
42
+ end
43
+ end
31
44
  end
32
45
 
33
46
  def colored?(text)
@@ -55,6 +68,15 @@ module ColorMeRad
55
68
  end.join
56
69
  end
57
70
 
71
+ def set_style(text, style)
72
+ return text unless STYLES[style]
73
+
74
+ code = STYLES[style]
75
+ text = text.split("\e[0m").map do |string|
76
+ "\033[#{code}m#{string}\e[0m"
77
+ end.join
78
+ end
79
+
58
80
  def sample_message(background, foreground, pad)
59
81
  ' example of %s on %s ' % [
60
82
  foreground.to_s.ljust(pad),
@@ -127,8 +127,27 @@ module ColorMeRad
127
127
  end
128
128
 
129
129
  def validate_color(color, errors)
130
- return if ColorMeRad::Colorize::CODES.keys.include?(color)
131
- errors << "#{color} is not a valid color"
130
+ if color.is_a?(Array)
131
+ validate_color_array(color, errors)
132
+ else
133
+ return if ColorMeRad::Colorize::CODES.keys.include?(color)
134
+ errors << "#{color} is not a valid color"
135
+ end
136
+ end
137
+
138
+ def validate_color_array(color, errors)
139
+ fg, bg, *styles = color
140
+ if fg && !ColorMeRad::Colorize::CODES.keys.include?(fg)
141
+ errors << "#{fg} is not a valid color"
142
+ end
143
+ if bg && !ColorMeRad::Colorize::CODES.keys.include?(bg)
144
+ errors << "#{bg} is not a valid color"
145
+ end
146
+ styles.each do |style|
147
+ unless ColorMeRad::Colorize::STYLES.keys.include?(style)
148
+ errors << "#{style} is not a valid style"
149
+ end
150
+ end
132
151
  end
133
152
 
134
153
  def validate_unique_key(key, errors)
@@ -41,8 +41,8 @@ module ColorMeRad
41
41
  # colorization methods
42
42
 
43
43
  # TODO: test (officially)
44
- def colorize(data, foreground = nil, background = nil)
45
- Colorize.colorize data, foreground, background
44
+ def colorize(data, foreground = nil, background = nil, *styles)
45
+ Colorize.colorize data, foreground, background, *styles
46
46
  end
47
47
 
48
48
  # TODO: test (officially)
data/readme.md CHANGED
@@ -123,6 +123,36 @@ end
123
123
  ```
124
124
 
125
125
 
126
+ ### Styles
127
+
128
+ Styles are applied after foreground and background colors.
129
+ The supported styles are `:bold` and `:dim`.
130
+
131
+ Pass styles as additional arguments to `colorize`:
132
+
133
+ ```ruby
134
+ ColorMeRad.colorize('hello', :blue, nil, :bold)
135
+ ColorMeRad.colorize('hello', :blue, :green, :dim)
136
+ ```
137
+
138
+ Styles can also be set in configuration using array values
139
+ in the format `[foreground, background, *styles]`:
140
+
141
+ ```ruby
142
+ ColorMeRad.configure do |config|
143
+ config.set_color :title, [:green, nil, :bold]
144
+ config.set_class_color 'String', [:blue, nil, :dim]
145
+ end
146
+ ```
147
+
148
+ Single symbol values continue to work as before.
149
+
150
+ Styles are applied in argument order.
151
+ While both `:bold` and `:dim` can be passed simultaneously,
152
+ the ANSI spec considers them mutually exclusive --
153
+ some terminals may render both, others may not.
154
+
155
+
126
156
  Development
127
157
  -----------
128
158
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_me_rad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Herrick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-30 00:00:00.000000000 Z
11
+ date: 2026-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".cane"
91
+ - ".cursor/.gitignore"
91
92
  - ".tool-versions"
92
93
  - Gemfile
93
94
  - Gemfile.lock
@@ -102,6 +103,9 @@ files:
102
103
  - checksum/color_me_rad-0.0.3.gem.md5
103
104
  - checksum/color_me_rad-0.0.3.gem.sha256
104
105
  - checksum/color_me_rad-0.0.3.gem.sha512
106
+ - checksum/color_me_rad-0.0.4.gem.md5
107
+ - checksum/color_me_rad-0.0.4.gem.sha256
108
+ - checksum/color_me_rad-0.0.4.gem.sha512
105
109
  - color_me_rad.gemspec
106
110
  - lib/color_me_rad.rb
107
111
  - lib/color_me_rad/color_helper.rb
@@ -128,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
132
  - !ruby/object:Gem::Version
129
133
  version: '0'
130
134
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.7.6
135
+ rubygems_version: 3.1.6
133
136
  signing_key:
134
137
  specification_version: 4
135
138
  summary: Simple color console output