jamescook-pow 0.1.4 → 0.1.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.
- data/README +4 -0
- data/bin/ruby-pow +38 -0
- data/jamescook-pow.gemspec +5 -2
- data/lib/pow.rb +18 -7
- data/rakefile.rb +1 -1
- metadata +6 -5
data/README
CHANGED
@@ -29,3 +29,7 @@ Examples:
|
|
29
29
|
You can also set defaults in your ~/.irbrc or wherever.
|
30
30
|
require 'pow'
|
31
31
|
Pow.defaults = {:bold => true} # Now any puts will default to bold
|
32
|
+
|
33
|
+
|
34
|
+
There's a script included that you can pipe text into and output customized text:
|
35
|
+
cat README | ruby bin/ruby-pow --bold --background=purple
|
data/bin/ruby-pow
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'pow'
|
4
|
+
require 'optparse'
|
5
|
+
include Pow
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: TODO.."
|
10
|
+
|
11
|
+
opts.on("-m MATCH", "--match MATCH", "Match keyword") do |v|
|
12
|
+
options[:match] = v
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("--match-color COLOR", "Match color") do |v|
|
16
|
+
options[:match_color] = v.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("--bold", "Bold") do |v|
|
20
|
+
options[:bold] = true
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("-c COLOR", "--color COLOR", "Text color") do |v|
|
24
|
+
options[:color] = v.downcase.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-b BACKGROUND", "--background BACKGROUND", "Background color") do |v|
|
28
|
+
options[:background] = v.downcase.to_sym
|
29
|
+
end
|
30
|
+
end.parse!
|
31
|
+
|
32
|
+
Pow.defaults = options
|
33
|
+
|
34
|
+
if $0 == __FILE__
|
35
|
+
STDIN.read.split("\n").each do |line|
|
36
|
+
puts line, Pow.defaults # FIXME: Why aren't defaults working implicitly..
|
37
|
+
end
|
38
|
+
end
|
data/jamescook-pow.gemspec
CHANGED
@@ -5,19 +5,22 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jamescook-pow}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Cook"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-26}
|
13
|
+
s.default_executable = %q{ruby-pow}
|
13
14
|
s.description = %q{Ruby 'puts' with shell colors.}
|
14
15
|
s.email = %q{jamecook@gmail.com}
|
16
|
+
s.executables = ["ruby-pow"]
|
15
17
|
s.extra_rdoc_files = [
|
16
18
|
"README"
|
17
19
|
]
|
18
20
|
s.files = [
|
19
21
|
".gitignore",
|
20
22
|
"README",
|
23
|
+
"bin/ruby-pow",
|
21
24
|
"jamescook-pow.gemspec",
|
22
25
|
"lib/pow.rb",
|
23
26
|
"pow.rb",
|
data/lib/pow.rb
CHANGED
@@ -11,6 +11,7 @@ module Pow
|
|
11
11
|
base.send(:alias_method, :p!, :puts!)
|
12
12
|
base.send(:alias_method, :p_, :puts_)
|
13
13
|
end
|
14
|
+
|
14
15
|
def defaults
|
15
16
|
@@defaults
|
16
17
|
end
|
@@ -66,7 +67,7 @@ module Pow
|
|
66
67
|
class Puts
|
67
68
|
attr_accessor :writer
|
68
69
|
def initialize(*args)
|
69
|
-
options = args[0].is_a?(Hash) ? args[0] : {:text => args[0].to_s}.merge(args[1] || {})
|
70
|
+
options = args[0].is_a?(Hash) ? args[0] : {:text => args[0].to_s}.merge(args[1] || {}) rescue {:text => args[0]}
|
70
71
|
@@match_color = :red
|
71
72
|
CODES.keys.each do |key|
|
72
73
|
# Color
|
@@ -99,7 +100,7 @@ module Pow
|
|
99
100
|
end
|
100
101
|
|
101
102
|
def match_color=(val)
|
102
|
-
@@match_color = val
|
103
|
+
@@match_color = val
|
103
104
|
end
|
104
105
|
|
105
106
|
def match_color
|
@@ -125,7 +126,9 @@ module Pow
|
|
125
126
|
out!(text.to_s.split("").inject(""){|m, word| m+= format_string(:text => word, :bold => true, :newline => "", :color => painbow_keys.sort_by{|k| rand}[0]) + " " } + "\n")
|
126
127
|
end
|
127
128
|
|
128
|
-
def inspect
|
129
|
+
def inspect
|
130
|
+
@formatted_text.inspect
|
131
|
+
end
|
129
132
|
|
130
133
|
protected
|
131
134
|
def painbow_keys
|
@@ -149,10 +152,9 @@ module Pow
|
|
149
152
|
strikethrough = options.fetch(:strikethrough){ Pow.defaults[:strikethrough] }
|
150
153
|
underscore = options.fetch(:underscore){ Pow.defaults[:underscore] }
|
151
154
|
match = options.fetch(:match){ false }
|
155
|
+
match_color = options.fetch(:match_color){ Pow.defaults[:match_color] || :red }
|
152
156
|
|
153
|
-
|
154
|
-
Puts.match_color = options[:match_color]
|
155
|
-
end
|
157
|
+
Puts.match_color = (match_color == color) ? [:negative, match_color] : match_color
|
156
158
|
|
157
159
|
if text != ""
|
158
160
|
result = [escape_sequence(color), text, escape_sequence(:reset), newline].join
|
@@ -189,7 +191,7 @@ module Pow
|
|
189
191
|
end
|
190
192
|
|
191
193
|
if match.is_a?(Regexp) || match.is_a?(String)
|
192
|
-
result = wrap_match(result, match, Puts.match_color, false)
|
194
|
+
result = wrap_match(result, match, escape_sequence_of(Puts.match_color), false)
|
193
195
|
end
|
194
196
|
|
195
197
|
return result + escape_sequence(:clear)
|
@@ -207,6 +209,10 @@ module Pow
|
|
207
209
|
end
|
208
210
|
end
|
209
211
|
|
212
|
+
def escape_sequence_of(arr)
|
213
|
+
arr.is_a?(Array) ? arr.inject(""){|m, v| m+= escape_sequence(v)} : arr
|
214
|
+
end
|
215
|
+
|
210
216
|
def wrap_match(text, match, match_color, negative=false)
|
211
217
|
#TODO use the negative sequence when the text color is the same as the match color.
|
212
218
|
text.gsub(match, [escape_sequence(match_color), match, escape_sequence(Puts.color)].join(''))
|
@@ -215,3 +221,8 @@ module Pow
|
|
215
221
|
end
|
216
222
|
|
217
223
|
include Pow
|
224
|
+
|
225
|
+
if $0 == __FILE__
|
226
|
+
puts STDIN.gets
|
227
|
+
end
|
228
|
+
|
data/rakefile.rb
CHANGED
@@ -3,7 +3,7 @@ begin
|
|
3
3
|
require 'jeweler'
|
4
4
|
Jeweler::Tasks.new do |gemspec|
|
5
5
|
gemspec.name = "jamescook-pow"
|
6
|
-
gemspec.version = "0.1.
|
6
|
+
gemspec.version = "0.1.5"
|
7
7
|
gemspec.summary = "puts with colors"
|
8
8
|
gemspec.description = "Ruby 'puts' with shell colors."
|
9
9
|
gemspec.email = "jamecook@gmail.com"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jamescook-pow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Cook
|
@@ -9,14 +9,14 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
13
|
-
default_executable:
|
12
|
+
date: 2009-11-26 00:00:00 -06:00
|
13
|
+
default_executable: ruby-pow
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Ruby 'puts' with shell colors.
|
17
17
|
email: jamecook@gmail.com
|
18
|
-
executables:
|
19
|
-
|
18
|
+
executables:
|
19
|
+
- ruby-pow
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
@@ -24,6 +24,7 @@ extra_rdoc_files:
|
|
24
24
|
files:
|
25
25
|
- .gitignore
|
26
26
|
- README
|
27
|
+
- bin/ruby-pow
|
27
28
|
- jamescook-pow.gemspec
|
28
29
|
- lib/pow.rb
|
29
30
|
- pow.rb
|