epitools 0.3.1 → 0.3.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/VERSION +1 -1
- data/epitools.gemspec +3 -3
- data/lib/epitools.rb +1 -1
- data/lib/epitools/{highlight.rb → clitools.rb} +16 -0
- data/lib/epitools/colored.rb +54 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{epitools}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-05}
|
13
13
|
s.description = %q{Miscellaneous utility libraries to make my life easier.}
|
14
14
|
s.email = %q{chris@ill-logic.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,9 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/epitools/browser.rb",
|
29
29
|
"lib/epitools/browser/browser_cache.rb",
|
30
30
|
"lib/epitools/browser/mechanize_progressbar.rb",
|
31
|
+
"lib/epitools/clitools.rb",
|
31
32
|
"lib/epitools/colored.rb",
|
32
33
|
"lib/epitools/hexdump.rb",
|
33
|
-
"lib/epitools/highlight.rb",
|
34
34
|
"lib/epitools/http.rb",
|
35
35
|
"lib/epitools/lcs.rb",
|
36
36
|
"lib/epitools/metaclass.rb",
|
data/lib/epitools.rb
CHANGED
@@ -15,3 +15,19 @@ class String
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
+
#
|
19
|
+
# Output to less.
|
20
|
+
#
|
21
|
+
def lesspipe(output=nil, options={})
|
22
|
+
params = []
|
23
|
+
params << "-R" unless options[:color] == false
|
24
|
+
params << "-S" unless options[:wrap] == true
|
25
|
+
params << "-X"
|
26
|
+
IO.popen("less #{params * ' '}", "w") do |less|
|
27
|
+
if output
|
28
|
+
less.puts output
|
29
|
+
else
|
30
|
+
yield less
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/epitools/colored.rb
CHANGED
@@ -84,9 +84,15 @@ module Colored
|
|
84
84
|
|
85
85
|
COLORS.each do |highlight, value|
|
86
86
|
next if color == highlight
|
87
|
+
|
87
88
|
define_method("#{color}_on_#{highlight}") do
|
88
89
|
colorize(self, :foreground => color, :background => highlight)
|
89
90
|
end
|
91
|
+
|
92
|
+
define_method("light_#{color}_on_#{highlight}") do
|
93
|
+
colorize(self, :foreground => color, :background => highlight, :extra => 'bold')
|
94
|
+
end
|
95
|
+
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
@@ -105,8 +111,17 @@ module Colored
|
|
105
111
|
tmp
|
106
112
|
end
|
107
113
|
|
108
|
-
|
109
|
-
|
114
|
+
#
|
115
|
+
# A class/instance method to colorize a string.
|
116
|
+
#
|
117
|
+
# Accepts options:
|
118
|
+
# :foreground
|
119
|
+
# The name of the foreground color as a string.
|
120
|
+
# :background
|
121
|
+
# The name of the background color as a string.
|
122
|
+
# :extra
|
123
|
+
# Extra styling, like 'bold', 'light', 'underline', 'reversed', or 'clear'.
|
124
|
+
#
|
110
125
|
def colorize(string=nil, options = {})
|
111
126
|
if string == nil
|
112
127
|
return tagged_colors(self)
|
@@ -121,15 +136,24 @@ module Colored
|
|
121
136
|
end
|
122
137
|
end
|
123
138
|
|
139
|
+
#
|
140
|
+
# An array of all possible colors.
|
141
|
+
#
|
124
142
|
def colors
|
125
143
|
@@colors ||= COLORS.keys.sort
|
126
144
|
end
|
127
145
|
|
146
|
+
#
|
147
|
+
# Returns the terminal code for one of the extra styling options.
|
148
|
+
#
|
128
149
|
def extra(extra_name)
|
129
150
|
extra_name = extra_name.to_s
|
130
151
|
"\e[#{EXTRAS[extra_name]}m" if EXTRAS[extra_name]
|
131
152
|
end
|
132
153
|
|
154
|
+
#
|
155
|
+
# Returns the terminal code for a specified color.
|
156
|
+
#
|
133
157
|
def color(color_name)
|
134
158
|
background = color_name.to_s =~ /on_/
|
135
159
|
color_name = color_name.to_s.sub('on_', '')
|
@@ -137,22 +161,42 @@ module Colored
|
|
137
161
|
"\e[#{COLORS[color_name] + (background ? 10 : 0)}m"
|
138
162
|
end
|
139
163
|
|
140
|
-
|
164
|
+
#
|
165
|
+
# Will color commands actually modify the strings?
|
166
|
+
#
|
167
|
+
def enabled?
|
168
|
+
@@is_tty
|
169
|
+
end
|
170
|
+
|
171
|
+
alias_method :is_tty?, :enabled?
|
141
172
|
|
173
|
+
#
|
174
|
+
# Color commands will always produce colored strings.
|
175
|
+
#
|
142
176
|
def enable!
|
143
177
|
@@is_tty = true
|
144
178
|
end
|
145
179
|
|
146
180
|
alias_method :force!, :enable!
|
147
|
-
|
181
|
+
|
182
|
+
#
|
183
|
+
# Enable Colored just for this block.
|
184
|
+
#
|
185
|
+
def enable_temporarily(&block)
|
186
|
+
last_state = @@is_tty
|
187
|
+
|
188
|
+
@@is_tty = true
|
189
|
+
block.call
|
190
|
+
@@is_tty = last_state
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# Color commands will do nothing.
|
195
|
+
#
|
148
196
|
def disable!
|
149
197
|
@@is_tty = false
|
150
198
|
end
|
151
199
|
|
152
|
-
def is_tty?
|
153
|
-
@@is_tty
|
154
|
-
end
|
155
|
-
|
156
200
|
#
|
157
201
|
# Is this string legal?
|
158
202
|
#
|
@@ -170,10 +214,10 @@ module Colored
|
|
170
214
|
# Examples:
|
171
215
|
#
|
172
216
|
# Colors as words:
|
173
|
-
# puts "<
|
217
|
+
# puts "<light_green><magenta>*</magenta> Hey mom! I am <light_blue>SO</light_blue> colored right now.</light_green>".colorize
|
174
218
|
#
|
175
219
|
# Numeric ANSI colors (from the BBS days):
|
176
|
-
# puts "<10><5>*</5> Hey mom! I am <9>SO</9>
|
220
|
+
# puts "<10><5>*</5> Hey mom! I am <9>SO</9> colored right now.</10>".colorize
|
177
221
|
#
|
178
222
|
def tagged_colors(string)
|
179
223
|
stack = []
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- epitron
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-05 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -81,9 +81,9 @@ files:
|
|
81
81
|
- lib/epitools/browser.rb
|
82
82
|
- lib/epitools/browser/browser_cache.rb
|
83
83
|
- lib/epitools/browser/mechanize_progressbar.rb
|
84
|
+
- lib/epitools/clitools.rb
|
84
85
|
- lib/epitools/colored.rb
|
85
86
|
- lib/epitools/hexdump.rb
|
86
|
-
- lib/epitools/highlight.rb
|
87
87
|
- lib/epitools/http.rb
|
88
88
|
- lib/epitools/lcs.rb
|
89
89
|
- lib/epitools/metaclass.rb
|