pagoda 0.7.5 → 0.7.6

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
  SHA1:
3
- metadata.gz: bc94611a3f7274ca55f382eac24d5046d8bf95a8
4
- data.tar.gz: 7544372284da6c61088bbd753ee1ea952cb29561
3
+ metadata.gz: 01c9a1239407fa07ff18f6f60d89186c7a3bd103
4
+ data.tar.gz: bacf61bf5d5eb0de901423c969f53fbd7451dcc9
5
5
  SHA512:
6
- metadata.gz: 2383112bd5c4a4e6a7f4e99d0976e0790d8ac2118ddad9c40d50fa2b960c2d5a1ac6716e08e4342352f4452f458ade1eb9a57ce1daf7e3170fc84e1612feb8d1
7
- data.tar.gz: 6511198ef920ac81aaf9b0eb2a3e955e67eb1fef3a4746a75c80144e83fae9f650b1078bf2a2b5626442e296b12de402ceaa56c58d7ee6eb40eaf74126f2b631
6
+ metadata.gz: 40739d6d76eeb7dcde98cf5c0db02ccd473e66ed4723a7ac4c07b65498b62b3e3365a192d84be074806792f414f5d8b974f5ff6c07f53fa4b2613ebdf4fcf699
7
+ data.tar.gz: a0ef259834da2988011a643b90a06283d5cd062165624923e79c5ac8b7705647fc651050999e27b75d31670028320567445bdaf3df1d448de48e5f58d108509d
@@ -17,4 +17,193 @@ unless String.method_defined?(:shellescape)
17
17
  empty? ? "''" : gsub(/([^A-Za-z0-9_\-.,:\/@\n])/n, '\\\\\\1').gsub(/\n/, "'\n'")
18
18
  end
19
19
  end
20
+ end
21
+
22
+ class String
23
+
24
+ #
25
+ # Colors Hash
26
+ #
27
+ COLORS = {
28
+ :black => 0,
29
+ :red => 1,
30
+ :green => 2,
31
+ :yellow => 3,
32
+ :blue => 4,
33
+ :magenta => 5,
34
+ :cyan => 6,
35
+ :white => 7,
36
+ :default => 9,
37
+
38
+ :light_black => 10,
39
+ :light_red => 11,
40
+ :light_green => 12,
41
+ :light_yellow => 13,
42
+ :light_blue => 14,
43
+ :light_magenta => 15,
44
+ :light_cyan => 16,
45
+ :light_white => 17
46
+ }
47
+
48
+ #
49
+ # Modes Hash
50
+ #
51
+ MODES = {
52
+ :default => 0, # Turn off all attributes
53
+ #:bright => 1, # Set bright mode
54
+ :underline => 4, # Set underline mode
55
+ :blink => 5, # Set blink mode
56
+ :swap => 7, # Exchange foreground and background colors
57
+ :hide => 8 # Hide text (foreground color would be the same as background)
58
+ }
59
+
60
+ protected
61
+
62
+ #
63
+ # Set color values in new string intance
64
+ #
65
+ def set_color_parameters( params )
66
+ if (params.instance_of?(Hash))
67
+ @color = params[:color]
68
+ @background = params[:background]
69
+ @mode = params[:mode]
70
+ @uncolorized = params[:uncolorized]
71
+ self
72
+ else
73
+ nil
74
+ end
75
+ end
76
+
77
+ public
78
+
79
+ #
80
+ # Change color of string
81
+ #
82
+ # Examples:
83
+ #
84
+ # puts "This is blue".colorize( :blue )
85
+ # puts "This is light blue".colorize( :light_blue )
86
+ # puts "This is also blue".colorize( :color => :blue )
87
+ # puts "This is light blue with red background".colorize( :color => :light_blue, :background => :red )
88
+ # puts "This is light blue with red background".colorize( :light_blue ).colorize( :background => :red )
89
+ # puts "This is blue text on red".blue.on_red
90
+ # puts "This is red on blue".colorize( :red ).on_blue
91
+ # puts "This is red on blue and underline".colorize( :red ).on_blue.underline
92
+ # puts "This is blue text on red".blue.on_red.blink
93
+ # puts "This is uncolorized".blue.on_red.uncolorize
94
+ #
95
+ def colorize( params )
96
+ return self unless STDOUT.isatty
97
+
98
+ begin
99
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
100
+ rescue LoadError
101
+ raise 'You must gem install win32console to use colorize on Windows'
102
+ end
103
+
104
+ color_parameters = {}
105
+
106
+ if (params.instance_of?(Hash))
107
+ color_parameters[:color] = COLORS[params[:color]]
108
+ color_parameters[:background] = COLORS[params[:background]]
109
+ color_parameters[:mode] = MODES[params[:mode]]
110
+ elsif (params.instance_of?(Symbol))
111
+ color_parameters[:color] = COLORS[params]
112
+ end
113
+
114
+ color_parameters[:color] ||= @color ||= COLORS[:default]
115
+ color_parameters[:background] ||= @background ||= COLORS[:default]
116
+ color_parameters[:mode] ||= @mode ||= MODES[:default]
117
+
118
+ color_parameters[:uncolorized] ||= @uncolorized ||= self.dup
119
+
120
+ # calculate bright mode
121
+ color_parameters[:color] += 50 if color_parameters[:color] > 10
122
+
123
+ color_parameters[:background] += 50 if color_parameters[:background] > 10
124
+
125
+ "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
126
+ end
127
+
128
+ #
129
+ # Return uncolorized string
130
+ #
131
+ def uncolorize
132
+ @uncolorized || self
133
+ end
134
+
135
+ #
136
+ # Return true if sting is colorized
137
+ #
138
+ def colorized?
139
+ !defined?(@uncolorized).nil?
140
+ end
141
+
142
+ #
143
+ # Make some color and on_color methods
144
+ #
145
+ COLORS.each_key do | key |
146
+ next if key == :default
147
+
148
+ define_method key do
149
+ self.colorize( :color => key )
150
+ end
151
+
152
+ define_method "on_#{key}" do
153
+ self.colorize( :background => key )
154
+ end
155
+ end
156
+
157
+ #
158
+ # Methods for modes
159
+ #
160
+ MODES.each_key do | key |
161
+ next if key == :default
162
+
163
+ define_method key do
164
+ self.colorize( :mode => key )
165
+ end
166
+ end
167
+
168
+ class << self
169
+
170
+ #
171
+ # Return array of available modes used by colorize method
172
+ #
173
+ def modes
174
+ keys = []
175
+ MODES.each_key do | key |
176
+ keys << key
177
+ end
178
+ keys
179
+ end
180
+
181
+ #
182
+ # Return array of available colors used by colorize method
183
+ #
184
+ def colors
185
+ keys = []
186
+ COLORS.each_key do | key |
187
+ keys << key
188
+ end
189
+ keys
190
+ end
191
+
192
+ #
193
+ # Display color matrix with color names.
194
+ #
195
+ def color_matrix( txt = "[X]" )
196
+ size = String.colors.length
197
+ String.colors.each do | color |
198
+ String.colors.each do | back |
199
+ print txt.colorize( :color => color, :background => back )
200
+ end
201
+ puts " < #{color}"
202
+ end
203
+ String.colors.reverse.each_with_index do | back, index |
204
+ puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
205
+ end
206
+ ""
207
+ end
208
+ end
20
209
  end
@@ -1,5 +1,5 @@
1
1
  module Pagoda
2
2
  module CLI
3
- VERSION = "0.7.5"
3
+ VERSION = "0.7.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagoda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lyon Hill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-06 00:00:00.000000000 Z
11
+ date: 2013-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec