hl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@hl --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hl.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hl (0.0.1)
5
+ gem-man
6
+ methadone (~> 1.0.0.rc5)
7
+ rainbow
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ aruba (0.4.11)
13
+ childprocess (>= 0.2.3)
14
+ cucumber (>= 1.1.1)
15
+ ffi (>= 1.0.11)
16
+ rspec (>= 2.7.0)
17
+ builder (3.0.0)
18
+ childprocess (0.3.1)
19
+ ffi (~> 1.0.6)
20
+ cucumber (1.1.9)
21
+ builder (>= 2.1.2)
22
+ diff-lcs (>= 1.1.2)
23
+ gherkin (~> 2.9.0)
24
+ json (>= 1.4.6)
25
+ term-ansicolor (>= 1.0.6)
26
+ diff-lcs (1.1.3)
27
+ ffi (1.0.11)
28
+ gem-man (0.3.0)
29
+ gherkin (2.9.0)
30
+ json (>= 1.4.6)
31
+ hpricot (0.8.6)
32
+ json (1.6.5)
33
+ methadone (1.0.0.rc5)
34
+ bundler
35
+ mustache (0.99.4)
36
+ rainbow (1.1.3)
37
+ rake (0.9.2.2)
38
+ rdiscount (1.6.8)
39
+ rdoc (3.12)
40
+ json (~> 1.4)
41
+ ronn (0.7.3)
42
+ hpricot (>= 0.8.2)
43
+ mustache (>= 0.7.0)
44
+ rdiscount (>= 1.5.8)
45
+ rspec (2.8.0)
46
+ rspec-core (~> 2.8.0)
47
+ rspec-expectations (~> 2.8.0)
48
+ rspec-mocks (~> 2.8.0)
49
+ rspec-core (2.8.0)
50
+ rspec-expectations (2.8.0)
51
+ diff-lcs (~> 1.1.2)
52
+ rspec-mocks (2.8.0)
53
+ term-ansicolor (1.0.7)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ aruba
60
+ hl!
61
+ rake (~> 0.9.2)
62
+ rdoc
63
+ ronn
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ hl(1) -- Highlight text in an output stream or file
2
+ ===================================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `hl [options] PATTERN [FILE...]`
7
+
8
+ `hl [options] -p PATTERN [FILE...]`
9
+
10
+ ## INSTALL
11
+
12
+ $ gem install hl
13
+
14
+ ## DESCRIPTION
15
+
16
+ **hl** higlights (using ANSI escape sequences) instances of _PATTERN_ in the named input _FILEs_ or standard in if none are specified. **hl**'s goal is to assist visually scanning such output, but without trimming that output as `grep(1)` would. The most common use-case is when trying to scan the output of a `grep` invocation that has complex data or long lines. In this case, you don't want to further grep the output for the term you're looking for, bit instead simply need a visual cue as to where the secondary search term is in the output.
17
+
18
+ _PATTERN_ can be a plain string, or a regular expression.
19
+
20
+ ## OPTIONS
21
+
22
+ * `-c COLOR`, `--color=COLOR`:
23
+ Color to use for highlighting. Available colors are red, green, yellow, blue, magenta, cyan, or white,
24
+ with yellow being the default.
25
+
26
+ * `-n`, `--[no-]inverse`:
27
+ Inverse highlight. Shows the highlighting in inverse, with the background of the highlight being the selected color and the foreground being the color of your terminal's background. This is off by default
28
+
29
+ * `-i`, `--[no-]ignore-case`:
30
+ Ignore case when matching. This is off by default.
31
+
32
+ * `-u`, `--[no-]underline`:
33
+ Underline highlight. This is off by default.
34
+
35
+ * `-b`, `--[no-]bright`:
36
+ Use bright colors. Shows the highlighting using the bright version of the color. This is off by default.
37
+
38
+ * `-p PATTERN`, `--regexp=PATTERN`:
39
+ Search term as explicit option. This is useful for searching for patterns that start with a dash.
40
+
41
+ * `-h`, `--help`, `--version`:
42
+ Show the version and help information
43
+
44
+ ## ENVIRONMENT
45
+
46
+ Default options can be specified in the `HL_OPTS` environment variable, exactly as they would appear on the command line. You
47
+ can override these switches with the `-no-` form of the options
48
+
49
+ ## EXAMPLES
50
+
51
+ Highlight the output of grep
52
+
53
+ grep '2012-01-02' some_log_file.txt | hl 'user_id'
54
+
55
+ Highlight the word "user_id" in bright cyan in several files
56
+
57
+ hl --color=cyan -b user_id some_file some_other_file yet_a_third_file
58
+
59
+ ## BUGS
60
+
61
+ * Does not allow for highlighting multiple terms at once
62
+
63
+ ## AUTHOR
64
+
65
+ David Copeland, davec (at) naildrivin5.com
66
+
67
+ ## COPYRIGHT
68
+
69
+ hl is copyright(c) 2012 by David Copeland, released under the Apache license.
70
+
71
+ ## SEE ALSO
72
+
73
+ * Source on github: https://github.com/davetron5000/hl
74
+
75
+
76
+ [SYNOPSIS]: #SYNOPSIS "SYNOPSIS"
77
+ [INSTALL]: #INSTALL "INSTALL"
78
+ [DESCRIPTION]: #DESCRIPTION "DESCRIPTION"
79
+ [OPTIONS]: #OPTIONS "OPTIONS"
80
+ [ENVIRONMENT]: #ENVIRONMENT "ENVIRONMENT"
81
+ [EXAMPLES]: #EXAMPLES "EXAMPLES"
82
+ [BUGS]: #BUGS "BUGS"
83
+ [AUTHOR]: #AUTHOR "AUTHOR"
84
+ [COPYRIGHT]: #COPYRIGHT "COPYRIGHT"
85
+ [SEE ALSO]: #SEE-ALSO "SEE ALSO"
86
+
87
+
88
+ [hl(1)]: hl.1.html
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'bundler'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'cucumber'
5
+ require 'cucumber/rake/task'
6
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
7
+ require 'rdoc/task'
8
+ require 'methadone'
9
+ require 'fileutils'
10
+
11
+ include Rake::DSL
12
+ include Methadone::SH
13
+ include FileUtils
14
+
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ Rake::TestTask.new do |t|
18
+ t.pattern = 'test/tc_*.rb'
19
+ end
20
+
21
+ CUKE_RESULTS = 'results.html'
22
+ CLEAN << CUKE_RESULTS
23
+ Cucumber::Rake::Task.new(:features) do |t|
24
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
25
+ t.fork = false
26
+ end
27
+
28
+ Rake::RDocTask.new do |rd|
29
+
30
+ rd.main = "README.rdoc"
31
+
32
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
33
+ end
34
+
35
+ task :man do
36
+ sh 'ronn --markdown --roff man/hl.1.ronn'
37
+ mv 'man/hl.1.markdown','README.md'
38
+ end
39
+ CLEAN << 'man/hl.1'
40
+ CLEAN << 'man/hl.1.html'
41
+
42
+ task :default => [:test,:features,:man]
data/bin/hl ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'hl'
6
+
7
+ class App
8
+ include Methadone::Main
9
+ include Methadone::CLILogging
10
+
11
+ main do |keyword,*filenames|
12
+ if options[:regexp]
13
+ Array(filenames).unshift(keyword)
14
+ keyword = options[:regexp]
15
+ end
16
+
17
+ exit_now! 'search term or --regexp/-p required' if keyword.nil?
18
+
19
+ keyword = keyword.dup
20
+ highlighter = Hl::Highlighter.new(options)
21
+
22
+ puts highlighter.highlight(filenames,keyword)
23
+ end
24
+
25
+ description "Highlight terms in output without grepping out lines"
26
+
27
+ options[:color] = 'yellow'
28
+ colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
29
+ on("-c COLOR","--color","Color to use for highlighting",colors,"(#{colors.join('|')})")
30
+ on("--[no-]bright","-b","Use bright colors")
31
+ on("--[no-]inverse","-n","Inverse highlight")
32
+ on("--[no-]underline","-u","Underline highlight")
33
+ on("--regexp PATTERN","-p","Search term as explicit option")
34
+ on("--[no-]ignore-case","-i","Ignore case in match")
35
+
36
+ arg :search_term, :optional
37
+ arg :filename, :optional
38
+
39
+ version Hl::VERSION
40
+
41
+ defaults_from_env_var 'HL_OPTS'
42
+
43
+ go!
44
+ end
@@ -0,0 +1,80 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "hl"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+
12
+ And the banner should document that this app's arguments are:
13
+ |search_term|which is optional|
14
+ |filename |which is optional|
15
+
16
+ Scenario: Highlights stuff in yellow by default
17
+ Given a file named "test_file" with the word "foo" in it
18
+ When I successfully run `hl foo ../../test_file`
19
+ Then the entire contents of "test_file" should be output
20
+ But the word "foo" should be highlighted in yellow
21
+
22
+ Scenario: Highlights the pattern used in the flag
23
+ Given a file named "test_file" with the word "foo" in it
24
+ When I successfully run `hl --regexp=foo ../../test_file`
25
+ Then the entire contents of "test_file" should be output
26
+ But the word "foo" should be highlighted in yellow
27
+
28
+ Scenario: Highlights multiple times per line if needed
29
+ Given a file named "test_file" with the word "foo bar foo" in it
30
+ When I successfully run `hl foo ../../test_file`
31
+ Then the entire contents of "test_file" should be output
32
+ But the word "foo" should be highlighted both times in yellow
33
+
34
+ Scenario: Highlights with case insensitivity
35
+ Given a file named "test_file" with the word "FOO bar foo" in it
36
+ When I successfully run `hl -i foo ../../test_file`
37
+ Then the entire contents of "test_file" should be output
38
+ But the word "foo" should be highlighted in yellow
39
+ And the word "FOO" should be highlighted in yellow
40
+
41
+ Scenario Outline: Treats search term as a regexp
42
+ Given a file named "test_file" with the word "867-5309" in it
43
+ When I successfully run `hl <term> ../../test_file`
44
+ Then the entire contents of "test_file" should be output
45
+ But the word "867-5309" should be highlighted in yellow
46
+
47
+ Examples:
48
+ |term|
49
+ |'867-\d\d\d\d'|
50
+ |--regexp='867-\d\d\d\d'|
51
+
52
+ Scenario: It is an error to omit both the search term and the --regexp flag
53
+ When I run `hl`
54
+ Then the stderr should contain "search term or --regexp/-p required"
55
+
56
+ Scenario: Highlights stuff in yellow by default using multiple files
57
+ Given a file named "test_file" with the word "foo" in it
58
+ And a file named "test_file2" with the word "foobar" in it
59
+ When I successfully run `hl foo ../../test_file ../../test_file2`
60
+ Then the entire contents of "test_file" should be output
61
+ Then the entire contents of "test_file2" should be output
62
+ But the word "foo" should be highlighted in yellow
63
+
64
+ Scenario: Highlights from stdin if no file is given
65
+ When I run `hl foo` interactively
66
+ And I type some text containing "foo"
67
+ Then the contents of what I typed should be output
68
+ But the word "foo" should be highlighted in yellow
69
+
70
+ Scenario: Highlights stuff in blue if requested
71
+ Given a file named "test_file" with the word "foo" in it
72
+ When I successfully run `hl --color blue foo ../../test_file`
73
+ Then the entire contents of "test_file" should be output
74
+ But the word "foo" should be highlighted in blue
75
+
76
+ Scenario: Highlights stuff in bright, inverted, underlined cyan if requested
77
+ Given a file named "test_file" with the word "foo" in it
78
+ When I successfully run `hl --color blue -bun foo ../../test_file`
79
+ Then the entire contents of "test_file" should be output
80
+ But the word "foo" should be highlighted in bright inverted underlined blue
@@ -0,0 +1,47 @@
1
+ require 'rainbow'
2
+ Sickill::Rainbow.enabled = true
3
+ CONTENTS = [
4
+ 'This is the first line',
5
+ 'This is the second line and %{keyword} it contains the search term',
6
+ 'This is the last line',
7
+ ]
8
+ Given /^a file named "([^"]*)" with the word "([^"]*)" in it$/ do |filename, keyword|
9
+ @contents_without_ansi = CONTENTS.map { |line| line.gsub('%{keyword}','>>=').split('>>=') }.flatten
10
+ @contents = CONTENTS.map { |line| line % { :keyword => keyword } }
11
+ File.open(filename,'w') { |file| @contents.each { |_| file.puts _ } }
12
+ end
13
+
14
+ Then /^the entire contents of "([^"]*)" should be output$/ do |file|
15
+ @contents_without_ansi.each { |_| assert_partial_output(_,all_stdout) }
16
+ end
17
+
18
+ Then /^the word "([^"]*)" should be highlighted in (.*$)$/ do |keyword,color|
19
+ if color == 'bright inverted underlined blue'
20
+ expected = keyword.color(:blue).inverse.bright.underline
21
+ else
22
+ expected = keyword.color(color.to_sym)
23
+ end
24
+ assert_partial_output(expected,all_stdout)
25
+ end
26
+
27
+ Then /^the word "([^"]*)" should be highlighted both times in (.*$)$/ do |keyword,color|
28
+ expected = keyword.color(color.to_sym)
29
+ all_stdout.should match /#{Regexp.escape(expected)}.*#{Regexp.escape(expected)}/
30
+ end
31
+
32
+ Then /^I type some text containing "([^"]*)"$/ do |keyword|
33
+ @contents_without_ansi = CONTENTS.map { |line| line.gsub('%{keyword}','>>=').split('>>=') }.flatten
34
+ contents = CONTENTS.map { |line| line % { :keyword => keyword } }
35
+ contents.each do |line|
36
+ step %{I type "#{line}"}
37
+ end
38
+ @interactive.stdin.close
39
+ end
40
+
41
+ Then /^the contents of what I typed should be output$/ do
42
+ @contents_without_ansi.each { |_| assert_partial_output(_,all_stdout) }
43
+ end
44
+
45
+ Then /^I should see the help output$/ do
46
+ step %{the banner should be present}
47
+ end
@@ -0,0 +1,20 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+ require 'fileutils'
4
+
5
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
6
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
7
+ Before do
8
+ @aruba_keep_ansi = true
9
+ # Using "announce" causes massive warnings on 1.9.2
10
+ @puts = true
11
+ @original_rubylib = ENV['RUBYLIB']
12
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
13
+ end
14
+
15
+ After do
16
+ ENV['RUBYLIB'] = @original_rubylib
17
+ %w(test_file test_file2).each do |filename|
18
+ FileUtils.rm filename if File.exist? filename
19
+ end
20
+ end
data/hl.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hl/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hl"
7
+ s.version = Hl::VERSION
8
+ s.authors = ["Dave Copeland"]
9
+ s.email = ["davetron5000@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Highlight words in stdin or files}
12
+ s.description = %q{To help with reading the results of grep without further reducing the output, hl will highlight terms in the output}
13
+
14
+ s.rubyforge_project = "hl"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency('rdoc')
22
+ s.add_development_dependency('ronn')
23
+ s.add_development_dependency('aruba')
24
+ s.add_development_dependency('rake','~> 0.9.2')
25
+ s.add_dependency('methadone', '~>1.0.0.rc5')
26
+ s.add_dependency('rainbow')
27
+ s.add_dependency('gem-man')
28
+ end
data/lib/hl.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'hl/highlighter'
2
+ require 'hl/version'
@@ -0,0 +1,54 @@
1
+ require 'rainbow'
2
+ module Hl
3
+ class Highlighter
4
+ # options - a Hash of symbols to values:
5
+ # :color - color to highlight
6
+ # :bright - highlight in bright
7
+ # :underline - underline highlight
8
+ # :inverse - invert highlight
9
+ # 'ignore-case' - ignore case when matching
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ # Returns a string containing the highlighted text from the given files or
15
+ # STDIN if filenames is empty
16
+ def highlight(filenames,keyword)
17
+ Sickill::Rainbow.enabled = true
18
+ files = if filenames.empty?
19
+ [STDIN]
20
+ else
21
+ filenames.map { |_| File.open(_) }
22
+ end
23
+ begin
24
+
25
+ regexp = Regexp.new(keyword,@options['ignore-case'] ? Regexp::IGNORECASE : nil)
26
+
27
+ files.map { |_| _.readlines}.flatten.map { |_| highlight_matches(regexp,_) }.join("\n")
28
+ ensure
29
+ files && files.map(&:close)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def highlight_matches(regexp,rest_of_string)
36
+ match_data = regexp.match(rest_of_string)
37
+ return rest_of_string if match_data.nil?
38
+
39
+ before_match = rest_of_string[0..match_data.begin(0)-1]
40
+ after_match = rest_of_string[match_data.end(0)..-1]
41
+
42
+ return before_match + highlight_string(match_data[0]) + highlight_matches(regexp,after_match)
43
+ end
44
+
45
+ def highlight_string(string)
46
+ string = string.color(@options['color'].to_sym)
47
+ string = string.inverse if @options[:inverse]
48
+ string = string.bright if @options[:bright]
49
+ string = string.underline if @options[:underline]
50
+ string
51
+ end
52
+
53
+ end
54
+ end
data/lib/hl/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Hl
2
+ VERSION = "0.0.1"
3
+ end
data/man/hl.1 ADDED
@@ -0,0 +1,107 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "HL" "1" "March 2012" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBhl\fR \- Highlight text in an output stream or file
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBhl [options] PATTERN [FILE\.\.\.]\fR
11
+ .
12
+ .P
13
+ \fBhl [options] \-p PATTERN [FILE\.\.\.]\fR
14
+ .
15
+ .SH "INSTALL"
16
+ .
17
+ .nf
18
+
19
+ $ gem install hl
20
+ .
21
+ .fi
22
+ .
23
+ .SH "DESCRIPTION"
24
+ \fBhl\fR higlights (using ANSI escape sequences) instances of \fIPATTERN\fR in the named input \fIFILEs\fR or standard in if none are specified\. \fBhl\fR\'s goal is to assist visually scanning such output, but without trimming that output as \fBgrep(1)\fR would\. The most common use\-case is when trying to scan the output of a \fBgrep\fR invocation that has complex data or long lines\. In this case, you don\'t want to further grep the output for the term you\'re looking for, bit instead simply need a visual cue as to where the secondary search term is in the output\.
25
+ .
26
+ .P
27
+ \fIPATTERN\fR can be a plain string, or a regular expression\.
28
+ .
29
+ .SH "OPTIONS"
30
+ .
31
+ .TP
32
+ \fB\-c COLOR\fR, \fB\-\-color=COLOR\fR
33
+ Color to use for highlighting\. Available colors are red, green, yellow, blue, magenta, cyan, or white, with yellow being the default\.
34
+ .
35
+ .TP
36
+ \fB\-n\fR, \fB\-\-[no\-]inverse\fR
37
+ Inverse highlight\. Shows the highlighting in inverse, with the background of the highlight being the selected color and the foreground being the color of your terminal\'s background\. This is off by default
38
+ .
39
+ .TP
40
+ \fB\-i\fR, \fB\-\-[no\-]ignore\-case\fR
41
+ Ignore case when matching\. This is off by default\.
42
+ .
43
+ .TP
44
+ \fB\-u\fR, \fB\-\-[no\-]underline\fR
45
+ Underline highlight\. This is off by default\.
46
+ .
47
+ .TP
48
+ \fB\-b\fR, \fB\-\-[no\-]bright\fR
49
+ Use bright colors\. Shows the highlighting using the bright version of the color\. This is off by default\.
50
+ .
51
+ .TP
52
+ \fB\-p PATTERN\fR, \fB\-\-regexp=PATTERN\fR
53
+ Search term as explicit option\. This is useful for searching for patterns that start with a dash\.
54
+ .
55
+ .TP
56
+ \fB\-h\fR, \fB\-\-help\fR, \fB\-\-version\fR
57
+ Show the version and help information
58
+ .
59
+ .SH "ENVIRONMENT"
60
+ Default options can be specified in the \fBHL_OPTS\fR environment variable, exactly as they would appear on the command line\. You can override these switches with the \fB\-no\-\fR form of the options
61
+ .
62
+ .SH "EXAMPLES"
63
+ Highlight the output of grep
64
+ .
65
+ .IP "" 4
66
+ .
67
+ .nf
68
+
69
+ grep \'2012\-01\-02\' some_log_file\.txt | hl \'user_id\'
70
+ .
71
+ .fi
72
+ .
73
+ .IP "" 0
74
+ .
75
+ .P
76
+ Highlight the word "user_id" in bright cyan in several files
77
+ .
78
+ .IP "" 4
79
+ .
80
+ .nf
81
+
82
+ hl \-\-color=cyan \-b user_id some_file some_other_file yet_a_third_file
83
+ .
84
+ .fi
85
+ .
86
+ .IP "" 0
87
+ .
88
+ .SH "BUGS"
89
+ .
90
+ .IP "\(bu" 4
91
+ Does not allow for highlighting multiple terms at once
92
+ .
93
+ .IP "" 0
94
+ .
95
+ .SH "AUTHOR"
96
+ David Copeland, davec (at) naildrivin5\.com
97
+ .
98
+ .SH "COPYRIGHT"
99
+ hl is copyright(c) 2012 by David Copeland, released under the Apache license\.
100
+ .
101
+ .SH "SEE ALSO"
102
+ .
103
+ .IP "\(bu" 4
104
+ Source on github: https://github\.com/davetron5000/hl
105
+ .
106
+ .IP "" 0
107
+
data/man/hl.1.ronn ADDED
@@ -0,0 +1,73 @@
1
+ hl(1) -- Highlight text in an output stream or file
2
+ ===================================================
3
+
4
+ ## SYNOPSIS
5
+
6
+ `hl [options] PATTERN [FILE...]`
7
+
8
+ `hl [options] -p PATTERN [FILE...]`
9
+
10
+ ## INSTALL
11
+
12
+ $ gem install hl
13
+
14
+ ## DESCRIPTION
15
+
16
+ **hl** higlights (using ANSI escape sequences) instances of _PATTERN_ in the named input _FILEs_ or standard in if none are specified. **hl**'s goal is to assist visually scanning such output, but without trimming that output as `grep(1)` would. The most common use-case is when trying to scan the output of a `grep` invocation that has complex data or long lines. In this case, you don't want to further grep the output for the term you're looking for, bit instead simply need a visual cue as to where the secondary search term is in the output.
17
+
18
+ _PATTERN_ can be a plain string, or a regular expression.
19
+
20
+ ## OPTIONS
21
+
22
+ * `-c COLOR`, `--color=COLOR`:
23
+ Color to use for highlighting. Available colors are red, green, yellow, blue, magenta, cyan, or white,
24
+ with yellow being the default.
25
+
26
+ * `-n`, `--[no-]inverse`:
27
+ Inverse highlight. Shows the highlighting in inverse, with the background of the highlight being the selected color and the foreground being the color of your terminal's background. This is off by default
28
+
29
+ * `-i`, `--[no-]ignore-case`:
30
+ Ignore case when matching. This is off by default.
31
+
32
+ * `-u`, `--[no-]underline`:
33
+ Underline highlight. This is off by default.
34
+
35
+ * `-b`, `--[no-]bright`:
36
+ Use bright colors. Shows the highlighting using the bright version of the color. This is off by default.
37
+
38
+ * `-p PATTERN`, `--regexp=PATTERN`:
39
+ Search term as explicit option. This is useful for searching for patterns that start with a dash.
40
+
41
+ * `-h`, `--help`, `--version`:
42
+ Show the version and help information
43
+
44
+ ## ENVIRONMENT
45
+
46
+ Default options can be specified in the `HL_OPTS` environment variable, exactly as they would appear on the command line. You
47
+ can override these switches with the `-no-` form of the options
48
+
49
+ ## EXAMPLES
50
+
51
+ Highlight the output of grep
52
+
53
+ grep '2012-01-02' some_log_file.txt | hl 'user_id'
54
+
55
+ Highlight the word "user_id" in bright cyan in several files
56
+
57
+ hl --color=cyan -b user_id some_file some_other_file yet_a_third_file
58
+
59
+ ## BUGS
60
+
61
+ * Does not allow for highlighting multiple terms at once
62
+
63
+ ## AUTHOR
64
+
65
+ David Copeland, davec (at) naildrivin5.com
66
+
67
+ ## COPYRIGHT
68
+
69
+ hl is copyright(c) 2012 by David Copeland, released under the Apache license.
70
+
71
+ ## SEE ALSO
72
+
73
+ * Source on github: https://github.com/davetron5000/hl
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ class TestSomething < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Copeland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: &70354328956620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70354328956620
25
+ - !ruby/object:Gem::Dependency
26
+ name: ronn
27
+ requirement: &70354328956160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70354328956160
36
+ - !ruby/object:Gem::Dependency
37
+ name: aruba
38
+ requirement: &70354328955720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70354328955720
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70354328955220 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70354328955220
58
+ - !ruby/object:Gem::Dependency
59
+ name: methadone
60
+ requirement: &70354328954680 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0.rc5
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70354328954680
69
+ - !ruby/object:Gem::Dependency
70
+ name: rainbow
71
+ requirement: &70354328954180 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70354328954180
80
+ - !ruby/object:Gem::Dependency
81
+ name: gem-man
82
+ requirement: &70354328953580 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70354328953580
91
+ description: To help with reading the results of grep without further reducing the
92
+ output, hl will highlight terms in the output
93
+ email:
94
+ - davetron5000@gmail.com
95
+ executables:
96
+ - hl
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - .gitignore
101
+ - .rvmrc
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/hl
108
+ - features/hl.feature
109
+ - features/step_definitions/hl_steps.rb
110
+ - features/support/env.rb
111
+ - hl.gemspec
112
+ - lib/hl.rb
113
+ - lib/hl/highlighter.rb
114
+ - lib/hl/version.rb
115
+ - man/hl.1
116
+ - man/hl.1.ronn
117
+ - test/tc_something.rb
118
+ homepage: ''
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project: hl
138
+ rubygems_version: 1.8.10
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Highlight words in stdin or files
142
+ test_files:
143
+ - features/hl.feature
144
+ - features/step_definitions/hl_steps.rb
145
+ - features/support/env.rb
146
+ - test/tc_something.rb