jamescook-pow 0.1.1 → 0.1.2
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 +5 -1
- data/jamescook-pow.gemspec +3 -3
- data/lib/pow.rb +12 -3
- data/rakefile.rb +12 -2
- data/test/pow_test.rb +6 -0
- metadata +3 -3
data/README
CHANGED
@@ -12,9 +12,13 @@ Examples:
|
|
12
12
|
puts.yellow "Hello world in yellow"
|
13
13
|
puts.red "Hello world in red"
|
14
14
|
puts.red! "Hello world in red, but with boldness"
|
15
|
-
puts.red_ "Hello world in red, but with
|
15
|
+
puts.red_ "Hello world in red, but with underscore"
|
16
16
|
puts.rainbow "Hellow world, but more silly."
|
17
17
|
|
18
|
+
p.red "Hello world, but less typing .. also red."
|
19
|
+
p! "Hello world, in bold"
|
20
|
+
p! "Mix and match", :color => :purple, :background => :black
|
21
|
+
|
18
22
|
|
19
23
|
TODO:
|
20
24
|
- Figure out if you can bold a 'dark' color
|
data/jamescook-pow.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
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.2"
|
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-
|
13
|
-
s.description = %q{'puts' with shell colors.}
|
12
|
+
s.date = %q{2009-11-20}
|
13
|
+
s.description = %q{Ruby 'puts' with shell colors.}
|
14
14
|
s.email = %q{jamecook@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README"
|
data/lib/pow.rb
CHANGED
@@ -2,6 +2,10 @@ module Pow
|
|
2
2
|
# Override puts on include to allow coloring (but also retain existing function)
|
3
3
|
def self.included(base)
|
4
4
|
base.send(:define_method, :puts){ |*args| Puts.new(*args) }
|
5
|
+
base.send(:define_method, :puts!){ |*args| opts=(args.detect{|a| a.is_a?(Hash)} || {}).merge(:misc => {:bold => true}); args.reject!{|a| a.is_a?(Hash)}; args = [args.push(opts)].flatten; Puts.new(*args) } # Now that's just self-explanatory ..
|
6
|
+
|
7
|
+
base.send(:alias_method, :p, :puts)
|
8
|
+
base.send(:alias_method, :p!, :puts!)
|
5
9
|
end
|
6
10
|
CODES = {
|
7
11
|
:clear => 0,
|
@@ -49,14 +53,14 @@ module Pow
|
|
49
53
|
class Puts
|
50
54
|
attr_accessor :writer
|
51
55
|
def initialize(*args)
|
52
|
-
options = args[0].is_a?(String) ? {:text => args[0] } : (args[0] || {})
|
56
|
+
options = args[0].is_a?(String) ? {:text => args[0]}.merge(args[1] || {}) : (args[0] || {})
|
53
57
|
CODES.keys.each do |key|
|
54
58
|
# Color
|
55
59
|
self.class.send(:define_method, key.to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :misc => args[1]}).out! }
|
56
60
|
# Bold
|
57
61
|
self.class.send(:define_method, "#{key}!".to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :bold => true, :misc => args[1]}).out! }
|
58
|
-
#
|
59
|
-
self.class.send(:define_method, "#{key}_".to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :
|
62
|
+
# Underline
|
63
|
+
self.class.send(:define_method, "#{key}_".to_sym) { |*args| Puts.new({:color => key.to_sym, :text => args[0], :underline => true, :misc => args[1]}).out! }
|
60
64
|
end
|
61
65
|
# FIXME make this part a method or less fug
|
62
66
|
if options[:misc] && options[:misc].is_a?(Hash)
|
@@ -113,6 +117,7 @@ module Pow
|
|
113
117
|
background = options.fetch(:background){ false }
|
114
118
|
concealed = options.fetch(:concealed){ false }
|
115
119
|
strikethrough = options.fetch(:strikethrough){ false }
|
120
|
+
underscore = options.fetch(:underscore){ false }
|
116
121
|
|
117
122
|
if text != ""
|
118
123
|
result = [escape_sequence(color), text, escape_sequence(:reset), newline].join
|
@@ -142,6 +147,10 @@ module Pow
|
|
142
147
|
result.insert(0, escape_sequence(:strikethrough))
|
143
148
|
end
|
144
149
|
|
150
|
+
if underscore
|
151
|
+
result.insert(0, escape_sequence(:underscore))
|
152
|
+
end
|
153
|
+
|
145
154
|
return result
|
146
155
|
end
|
147
156
|
|
data/rakefile.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
require "rake"
|
1
2
|
begin
|
2
3
|
require 'jeweler'
|
3
4
|
Jeweler::Tasks.new do |gemspec|
|
4
5
|
gemspec.name = "jamescook-pow"
|
5
|
-
gemspec.version = "0.1.
|
6
|
+
gemspec.version = "0.1.2"
|
6
7
|
gemspec.summary = "puts with colors"
|
7
|
-
gemspec.description = "'puts' with shell colors."
|
8
|
+
gemspec.description = "Ruby 'puts' with shell colors."
|
8
9
|
gemspec.email = "jamecook@gmail.com"
|
9
10
|
gemspec.homepage = "http://github.com/jamescook/pow"
|
10
11
|
gemspec.authors = ["James Cook"]
|
@@ -12,3 +13,12 @@ begin
|
|
12
13
|
rescue LoadError
|
13
14
|
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
14
15
|
end
|
16
|
+
|
17
|
+
task :default => [:test]
|
18
|
+
|
19
|
+
desc "Run tests"
|
20
|
+
task :test do |t|
|
21
|
+
ruby "test/pow_test.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
data/test/pow_test.rb
CHANGED
@@ -39,6 +39,12 @@ class PowTest < Test::Unit::TestCase
|
|
39
39
|
assert_equal "\e[1mTEST\e[0m\n", @writer.gets
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_puts_with_underscore
|
43
|
+
@puts.new(:text => "TEST", :underscore => :true, :writer => @writer).out!
|
44
|
+
@writer.rewind
|
45
|
+
assert_equal "\e[4m\e[37mTEST\e[0m\n", @writer.gets
|
46
|
+
end
|
47
|
+
|
42
48
|
def test_puts_with_strikethrough
|
43
49
|
@puts.new(:text => "TEST", :strikethrough => :true, :writer => @writer).out!
|
44
50
|
@writer.rewind
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Cook
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-20 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Ruby 'puts' with shell colors.
|
17
17
|
email: jamecook@gmail.com
|
18
18
|
executables: []
|
19
19
|
|