gren 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.ja.txt +8 -0
- data/History.txt +10 -0
- data/Manifest.txt +18 -4
- data/Rakefile +6 -1
- data/bin/grenweb +11 -0
- data/lib/common/util.rb +3 -3
- data/lib/findgrep/findgrep.rb +46 -25
- data/lib/gren.rb +1 -1
- data/lib/grenweb/cli.rb +52 -0
- data/lib/grenweb/database.rb +179 -0
- data/lib/grenweb/grenweb.ru +35 -0
- data/lib/grenweb/grep.rb +52 -0
- data/lib/grenweb/help.rb +37 -0
- data/lib/grenweb/home.rb +37 -0
- data/lib/grenweb/html_renderer.rb +231 -0
- data/lib/grenweb/public/css/gren.css +63 -0
- data/lib/grenweb/public/images/gren-icon-mini.png +0 -0
- data/lib/grenweb/public/images/gren-icon.png +0 -0
- data/lib/grenweb/query.rb +82 -0
- data/lib/grenweb/searcher.rb +127 -0
- data/lib/grenweb/viewer.rb +53 -0
- data/lib/mkgrendb/mkgrendb.rb +15 -8
- data/test/test_gren.rb +1 -2
- data/test/test_gren_util.rb +33 -32
- data/test/test_grenweb_cli.rb +10 -0
- data/test/test_grenweb_html_renderer.rb +40 -0
- data/test/test_grenweb_query.rb +54 -0
- data/test/test_grenweb_searcher.rb +35 -0
- data/test/test_string_snip.rb +3 -1
- metadata +59 -15
- data/lib/gren/findgrep.rb +0 -215
- data/test/test_gren_cli.rb +0 -14
- data/test/test_grendb_cli.rb +0 -14
- data/test/test_mkgrendb_cli.rb +0 -14
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/cli.rb')
|
3
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/searcher.rb')
|
4
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/viewer.rb')
|
5
|
+
|
6
|
+
class TestGrenwebCli < Test::Unit::TestCase
|
7
|
+
def test_print_default_output
|
8
|
+
# assert_match(/To update this executable/, @stdout)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
3
|
+
require File.join(File.dirname(__FILE__), "../lib/grenweb/html_renderer.rb")
|
4
|
+
|
5
|
+
class TestGrenwebHTMLRendeler < Test::Unit::TestCase
|
6
|
+
include Grenweb
|
7
|
+
|
8
|
+
def setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_pagination_line
|
12
|
+
assert_equal("<span class='pagination-link'><a href='?page=1'>test</a></span>\n", HTMLRendeler.pagination_link(1, "test"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_search_summary
|
16
|
+
assert_equal(HTMLRendeler.search_summary(10, 500, 10..20, 0.00893),
|
17
|
+
<<-EOS)
|
18
|
+
<div class='search-summary'>
|
19
|
+
<span class="keyword">10</span>の検索結果:
|
20
|
+
<span class="total-entries">500</span>件中
|
21
|
+
<span class="display-range">10 - 20</span>件(0.00893秒)
|
22
|
+
</div>
|
23
|
+
EOS
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_match_strong
|
27
|
+
assert_equal(HTMLRendeler.match_strong("This is line.", [nil, nil]), "This is line.")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_search_box
|
31
|
+
assert_equal(HTMLRendeler.search_box('test must'), <<-EOF)
|
32
|
+
<form method="post" action="/::search">
|
33
|
+
<p>
|
34
|
+
<input name="query" type="text" size="60" value="test must" />
|
35
|
+
<input type="submit" value="検索" />
|
36
|
+
</p>
|
37
|
+
</form>
|
38
|
+
EOF
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2010/10/21
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
9
|
+
require File.join(File.dirname(__FILE__), '../lib/grenweb/query')
|
10
|
+
|
11
|
+
class TestGrenWebQuery < Test::Unit::TestCase
|
12
|
+
include Grenweb
|
13
|
+
include Rack::Utils
|
14
|
+
|
15
|
+
def test_query
|
16
|
+
q = create_query("test fire beam")
|
17
|
+
assert_equal q.keywords, ['test', 'fire', 'beam']
|
18
|
+
assert_equal q.packages, []
|
19
|
+
assert_equal q.fpaths, []
|
20
|
+
assert_equal q.suffixs, []
|
21
|
+
assert_equal q.escape_html, 'test fire beam'
|
22
|
+
|
23
|
+
q = create_query("test fire beam f:testfile1")
|
24
|
+
assert_equal q.keywords, ['test', 'fire', 'beam']
|
25
|
+
assert_equal q.packages, []
|
26
|
+
assert_equal q.fpaths, ['testfile1']
|
27
|
+
assert_equal q.suffixs, []
|
28
|
+
|
29
|
+
q = create_query("test fire beam f:testfile1 filepath:dir32")
|
30
|
+
assert_equal q.keywords, ['test', 'fire', 'beam']
|
31
|
+
assert_equal q.packages, []
|
32
|
+
assert_equal q.fpaths, ['dir32', 'testfile1']
|
33
|
+
assert_equal q.suffixs, []
|
34
|
+
|
35
|
+
q = create_query("package:gren test fire beam f:testfile1 filepath:dir32 s:rb p:test suffix:pl")
|
36
|
+
assert_equal q.keywords, ['test', 'fire', 'beam']
|
37
|
+
assert_equal q.packages, ['gren', 'test']
|
38
|
+
assert_equal q.fpaths, ['dir32', 'testfile1']
|
39
|
+
assert_equal q.suffixs, ['pl', 'rb']
|
40
|
+
|
41
|
+
q = create_query("&p")
|
42
|
+
assert_equal q.escape_html, '&p'
|
43
|
+
|
44
|
+
q = create_query("int &p")
|
45
|
+
assert_equal q.escape_html, 'int &p'
|
46
|
+
|
47
|
+
q = create_query('"def update"')
|
48
|
+
assert_equal q.keywords, ['def update']
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_query(query)
|
52
|
+
Query.new(Rack::Request.new({"PATH_INFO"=>"/#{escape(query)}/"}))
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2010/10/21
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
9
|
+
require File.join(File.dirname(__FILE__), "../lib/grenweb/searcher.rb")
|
10
|
+
require 'rack/mock'
|
11
|
+
|
12
|
+
class TestGrenwebSearcher < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@app = Grenweb::Searcher.new
|
15
|
+
@mr = Rack::MockRequest.new(@app)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get
|
19
|
+
res = nil
|
20
|
+
assert_nothing_raised('なんか失敗した') { res = @mr.get('/', :lint => true) }
|
21
|
+
assert_not_nil res, 'レスポンス来てない'
|
22
|
+
assert_equal 200, res.status, 'ステータスコードが変'
|
23
|
+
assert_equal 'text/html; charset=UTF-8', res['Content-Type'], 'Content-Typeが変'
|
24
|
+
#puts res.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_post
|
28
|
+
res = nil
|
29
|
+
assert_nothing_raised('なんか失敗した') { res = @mr.post('/', :lint => true) }
|
30
|
+
assert_not_nil res, 'レスポンス来てない'
|
31
|
+
assert_equal 302, res.status, 'ステータスコードが変'
|
32
|
+
assert_equal 'text/html; charset=UTF-8', res['Content-Type'], 'Content-Typeが変'
|
33
|
+
#puts res.body
|
34
|
+
end
|
35
|
+
end
|
data/test/test_string_snip.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require File.join(File.dirname(__FILE__), "../lib/common/util.rb")
|
3
|
+
require File.join(File.dirname(__FILE__), "../lib/common/grensnip.rb")
|
2
4
|
|
3
5
|
class TestStringSnip < Test::Unit::TestCase
|
4
6
|
def setup
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- ongaeshi
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-02 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -46,9 +46,37 @@ dependencies:
|
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: rack
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 2
|
58
|
+
- 1
|
59
|
+
version: 1.2.1
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: launchy
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 3
|
72
|
+
- 7
|
73
|
+
version: 0.3.7
|
74
|
+
type: :runtime
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rubyforge
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
52
80
|
requirements:
|
53
81
|
- - ">="
|
54
82
|
- !ruby/object:Gem::Version
|
@@ -58,11 +86,11 @@ dependencies:
|
|
58
86
|
- 4
|
59
87
|
version: 2.0.4
|
60
88
|
type: :development
|
61
|
-
version_requirements: *
|
89
|
+
version_requirements: *id005
|
62
90
|
- !ruby/object:Gem::Dependency
|
63
91
|
name: hoe
|
64
92
|
prerelease: false
|
65
|
-
requirement: &
|
93
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
66
94
|
requirements:
|
67
95
|
- - ">="
|
68
96
|
- !ruby/object:Gem::Version
|
@@ -72,13 +100,14 @@ dependencies:
|
|
72
100
|
- 1
|
73
101
|
version: 2.6.1
|
74
102
|
type: :development
|
75
|
-
version_requirements: *
|
103
|
+
version_requirements: *id006
|
76
104
|
description: gren is a next grep tool.
|
77
105
|
email:
|
78
106
|
- ongaeshi0621@gmail.com
|
79
107
|
executables:
|
80
108
|
- gren
|
81
109
|
- grendb
|
110
|
+
- grenweb
|
82
111
|
- mkgrendb
|
83
112
|
extensions: []
|
84
113
|
|
@@ -97,6 +126,7 @@ files:
|
|
97
126
|
- Rakefile
|
98
127
|
- bin/gren
|
99
128
|
- bin/grendb
|
129
|
+
- bin/grenweb
|
100
130
|
- bin/mkgrendb
|
101
131
|
- lib/common/display_util.rb
|
102
132
|
- lib/common/grenfiletest.rb
|
@@ -108,8 +138,20 @@ files:
|
|
108
138
|
- lib/findgrep/result.rb
|
109
139
|
- lib/gren.rb
|
110
140
|
- lib/gren/cli.rb
|
111
|
-
- lib/gren/findgrep.rb
|
112
141
|
- lib/grendb/cli.rb
|
142
|
+
- lib/grenweb/cli.rb
|
143
|
+
- lib/grenweb/database.rb
|
144
|
+
- lib/grenweb/grenweb.ru
|
145
|
+
- lib/grenweb/grep.rb
|
146
|
+
- lib/grenweb/help.rb
|
147
|
+
- lib/grenweb/home.rb
|
148
|
+
- lib/grenweb/html_renderer.rb
|
149
|
+
- lib/grenweb/public/css/gren.css
|
150
|
+
- lib/grenweb/public/images/gren-icon-mini.png
|
151
|
+
- lib/grenweb/public/images/gren-icon.png
|
152
|
+
- lib/grenweb/query.rb
|
153
|
+
- lib/grenweb/searcher.rb
|
154
|
+
- lib/grenweb/viewer.rb
|
113
155
|
- lib/mkgrendb/cli.rb
|
114
156
|
- lib/mkgrendb/mkgrendb.rb
|
115
157
|
- rake_rdoc_custom.rb
|
@@ -117,11 +159,12 @@ files:
|
|
117
159
|
- script/destroy
|
118
160
|
- script/generate
|
119
161
|
- test/test_gren.rb
|
120
|
-
- test/test_gren_cli.rb
|
121
162
|
- test/test_gren_util.rb
|
122
|
-
- test/
|
163
|
+
- test/test_grenweb_cli.rb
|
164
|
+
- test/test_grenweb_html_renderer.rb
|
165
|
+
- test/test_grenweb_query.rb
|
166
|
+
- test/test_grenweb_searcher.rb
|
123
167
|
- test/test_helper.rb
|
124
|
-
- test/test_mkgrendb_cli.rb
|
125
168
|
- test/test_string_snip.rb
|
126
169
|
has_rdoc: true
|
127
170
|
homepage: http://ongaeshi.github.com/gren
|
@@ -156,9 +199,10 @@ specification_version: 3
|
|
156
199
|
summary: gren is a next grep tool.
|
157
200
|
test_files:
|
158
201
|
- test/test_gren.rb
|
159
|
-
- test/test_gren_cli.rb
|
160
202
|
- test/test_gren_util.rb
|
161
|
-
- test/
|
203
|
+
- test/test_grenweb_cli.rb
|
204
|
+
- test/test_grenweb_html_renderer.rb
|
205
|
+
- test/test_grenweb_query.rb
|
206
|
+
- test/test_grenweb_searcher.rb
|
162
207
|
- test/test_helper.rb
|
163
|
-
- test/test_mkgrendb_cli.rb
|
164
208
|
- test/test_string_snip.rb
|
data/lib/gren/findgrep.rb
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'find'
|
3
|
-
require File.join(File.dirname(__FILE__), 'result')
|
4
|
-
require 'rubygems'
|
5
|
-
require 'termcolor'
|
6
|
-
|
7
|
-
module Gren
|
8
|
-
class FindGrep
|
9
|
-
IGNORE_FILE = /(\A#.*#\Z)|(~\Z)|(\A\.#)/
|
10
|
-
IGNORE_DIR = /(\A\.svn\Z)|(\A\.git\Z)|(\ACVS\Z)/
|
11
|
-
|
12
|
-
Option = Struct.new(:directory,
|
13
|
-
:depth,
|
14
|
-
:ignoreCase,
|
15
|
-
:colorHighlight,
|
16
|
-
:isSilent,
|
17
|
-
:debugMode,
|
18
|
-
:filePatterns,
|
19
|
-
:ignoreFiles,
|
20
|
-
:ignoreDirs)
|
21
|
-
|
22
|
-
def initialize(patterns, option)
|
23
|
-
@option = option
|
24
|
-
@patternRegexps = strs2regs(patterns, @option.ignoreCase)
|
25
|
-
@filePatterns = strs2regs(option.filePatterns)
|
26
|
-
@ignoreFiles = strs2regs(option.ignoreFiles)
|
27
|
-
@ignoreDirs = strs2regs(option.ignoreDirs)
|
28
|
-
@result = Result.new(option.directory)
|
29
|
-
end
|
30
|
-
|
31
|
-
def strs2regs(strs, ignore = false)
|
32
|
-
regs = []
|
33
|
-
|
34
|
-
strs.each do |v|
|
35
|
-
option = 0
|
36
|
-
option |= Regexp::IGNORECASE if (ignore)
|
37
|
-
regs << Regexp.new(v, option)
|
38
|
-
end
|
39
|
-
|
40
|
-
regs
|
41
|
-
end
|
42
|
-
|
43
|
-
def searchAndPrint(stdout)
|
44
|
-
searchAndPrintIN(stdout, @option.directory, 0)
|
45
|
-
|
46
|
-
@result.time_stop
|
47
|
-
|
48
|
-
unless (@option.isSilent)
|
49
|
-
if (@option.debugMode)
|
50
|
-
stdout.puts
|
51
|
-
stdout.puts "--- search --------"
|
52
|
-
print_fpaths stdout, @result.search_files
|
53
|
-
stdout.puts "--- match --------"
|
54
|
-
print_fpaths stdout, @result.match_files
|
55
|
-
stdout.puts "--- ignore-file --------"
|
56
|
-
print_fpaths stdout, @result.ignore_files
|
57
|
-
stdout.puts "--- ignore-dir --------"
|
58
|
-
print_fpaths stdout, @result.prune_dirs
|
59
|
-
stdout.puts "--- unreadable --------"
|
60
|
-
print_fpaths stdout, @result.unreadable_files
|
61
|
-
end
|
62
|
-
|
63
|
-
unless (@option.colorHighlight)
|
64
|
-
stdout.puts
|
65
|
-
else
|
66
|
-
stdout.puts TermColor.parse("<7>------------------------------------------------------------</7>")
|
67
|
-
end
|
68
|
-
|
69
|
-
@result.print(stdout)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def searchAndPrintIN(stdout, dir, depth)
|
74
|
-
if (@option.depth != -1 && depth > @option.depth)
|
75
|
-
return
|
76
|
-
end
|
77
|
-
|
78
|
-
Dir.foreach(dir) do |name|
|
79
|
-
next if (name == '.' || name == '..')
|
80
|
-
|
81
|
-
fpath = File.join(dir,name)
|
82
|
-
fpath_disp = fpath.gsub(/^.\//, "")
|
83
|
-
|
84
|
-
# 除外ディレクトリならばパス
|
85
|
-
if ignoreDir?(fpath)
|
86
|
-
@result.prune_dirs << fpath_disp if (@option.debugMode)
|
87
|
-
next;
|
88
|
-
end
|
89
|
-
|
90
|
-
# 読み込み不可ならばパス
|
91
|
-
unless FileTest.readable?(fpath)
|
92
|
-
@result.unreadable_files << fpath_disp if (@option.debugMode)
|
93
|
-
next
|
94
|
-
end
|
95
|
-
|
96
|
-
# ファイルならば中身を探索、ディレクトリならば再帰
|
97
|
-
case File.ftype(fpath)
|
98
|
-
when "directory"
|
99
|
-
searchAndPrintIN(stdout, fpath, depth + 1)
|
100
|
-
when "file"
|
101
|
-
searchFile(stdout, fpath, fpath_disp)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
private :searchAndPrintIN
|
106
|
-
|
107
|
-
def print_fpaths(stdout, data)
|
108
|
-
stdout.print data.join("\n")
|
109
|
-
stdout.puts if data.count > 0
|
110
|
-
stdout.puts "total: #{data.count}"
|
111
|
-
stdout.puts
|
112
|
-
end
|
113
|
-
private :print_fpaths
|
114
|
-
|
115
|
-
def ignoreDir?(fpath)
|
116
|
-
FileTest.directory?(fpath) &&
|
117
|
-
(IGNORE_DIR.match(File.basename(fpath)) || ignoreDirUser?(fpath))
|
118
|
-
end
|
119
|
-
private :ignoreDir?
|
120
|
-
|
121
|
-
def ignoreDirUser?(fpath)
|
122
|
-
@ignoreDirs.any? {|v| v.match File.basename(fpath) }
|
123
|
-
end
|
124
|
-
private :ignoreDirUser?
|
125
|
-
|
126
|
-
def ignoreFile?(fpath)
|
127
|
-
!correctFileUser?(fpath) ||
|
128
|
-
IGNORE_FILE.match(File.basename(fpath)) ||
|
129
|
-
ignoreFileUser?(fpath) ||
|
130
|
-
binary?(fpath)
|
131
|
-
end
|
132
|
-
private :ignoreFile?
|
133
|
-
|
134
|
-
def correctFileUser?(fpath)
|
135
|
-
@filePatterns.empty? ||
|
136
|
-
@filePatterns.any? {|v| v.match File.basename(fpath) }
|
137
|
-
end
|
138
|
-
private :correctFileUser?
|
139
|
-
|
140
|
-
def ignoreFileUser?(fpath)
|
141
|
-
@ignoreFiles.any? {|v| v.match File.basename(fpath) }
|
142
|
-
end
|
143
|
-
private :ignoreFileUser?
|
144
|
-
|
145
|
-
def binary?(file)
|
146
|
-
s = File.read(file, 1024) or return false
|
147
|
-
return s.index("\x00")
|
148
|
-
end
|
149
|
-
|
150
|
-
def searchFile(stdout, fpath, fpath_disp)
|
151
|
-
@result.count += 1
|
152
|
-
@result.size += FileTest.size(fpath)
|
153
|
-
|
154
|
-
# 除外ファイル
|
155
|
-
if ignoreFile?(fpath)
|
156
|
-
@result.ignore_files << fpath_disp if (@option.debugMode)
|
157
|
-
return
|
158
|
-
end
|
159
|
-
|
160
|
-
@result.search_count += 1
|
161
|
-
@result.search_size += FileTest.size(fpath)
|
162
|
-
|
163
|
-
# 検索本体
|
164
|
-
@result.search_files << fpath_disp if (@option.debugMode)
|
165
|
-
|
166
|
-
open(fpath, "r") { |file|
|
167
|
-
match_file = false
|
168
|
-
file.each() { |line|
|
169
|
-
line.chomp!
|
170
|
-
|
171
|
-
result, match_datas = match?(line)
|
172
|
-
|
173
|
-
if ( result )
|
174
|
-
unless (@option.colorHighlight)
|
175
|
-
stdout.puts "#{fpath_disp}:#{file.lineno}:#{line}"
|
176
|
-
else
|
177
|
-
header = "#{fpath_disp}:#{file.lineno}"
|
178
|
-
|
179
|
-
begin
|
180
|
-
stdout.puts TermColor.parse("<34>#{header}</34>:") + coloring(line, match_datas)
|
181
|
-
rescue REXML::ParseException
|
182
|
-
stdout.puts header + line
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
unless match_file
|
187
|
-
@result.match_file_count += 1
|
188
|
-
@result.match_files << fpath_disp if (@option.debugMode)
|
189
|
-
match_file = true
|
190
|
-
end
|
191
|
-
|
192
|
-
@result.match_count += 1
|
193
|
-
end
|
194
|
-
}
|
195
|
-
}
|
196
|
-
end
|
197
|
-
private :searchFile
|
198
|
-
|
199
|
-
def match?(line)
|
200
|
-
match_datas = []
|
201
|
-
@patternRegexps.each {|v| match_datas << v.match(line)}
|
202
|
-
return match_datas.all?, match_datas
|
203
|
-
end
|
204
|
-
private :match?
|
205
|
-
|
206
|
-
def coloring(line, match_datas)
|
207
|
-
match_datas.each do |m|
|
208
|
-
line = line.split(m[0]).join(TermColor.parse("<42>#{m[0]}</42>"))
|
209
|
-
end
|
210
|
-
line
|
211
|
-
end
|
212
|
-
private :coloring
|
213
|
-
|
214
|
-
end
|
215
|
-
end
|