ruby-zoom 5.0.4 → 5.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed447d52e95f3056faa7eb4732325680cf8d9104a7eb4f9ef9bca516e652d33e
4
- data.tar.gz: 7d180d018ecad354a0d52178fd4ba1c4cea3f17553ebdc8db32487800c052745
3
+ metadata.gz: 715a46499be98c374a04e1bb17fa2356cbe3bee6e5750f5797c8b0093fbfb4af
4
+ data.tar.gz: af7f4f2561cd87d0d47946093ec1ef47a3f93433051148db1d03712c2ea824f2
5
5
  SHA512:
6
- metadata.gz: 3d0a5ba1faf770b17e4fe1f5c74b836b4980b37d8fefec8353004074b4a31c0edfd1d0bbb0314c9d00348938e4435a0894e1faff474fbcfc2588f3ffc1214be8
7
- data.tar.gz: f7e73219d98dc8136feadcdc57a3318e8b6e20f1a5e0310cc4222815868e004f655106439909e2a8422ed9bc8778ca28fb6617115194a71e06478b9154c72c17
6
+ metadata.gz: dafe4fa2a2443b2815bee0d9e42d89b3ad78f9add3a4ea2e10ffbaf9ef45ecbda8d12bb3dbf81f83cad7f5364c2a7a142895f93143436000f7a39206adfa95dc
7
+ data.tar.gz: 260228d8cff988427ec57d8f86bb6b5a2800167a11812bde1bfa0bbad8f086a96e7321d2523125c5e5821b84697d6ed4b098d9a76d46000ad27a56de46690d8c
data/bin/z CHANGED
@@ -329,7 +329,7 @@ begin
329
329
 
330
330
  case options["action"]
331
331
  when "cache"
332
- zoom.cache.shortcut(zoom.config)
332
+ zoom.cache.shortcut
333
333
  when "configure"
334
334
  Zoom.hilight(false)
335
335
  djinni = Djinni.new
data/bin/zc CHANGED
@@ -329,7 +329,7 @@ begin
329
329
 
330
330
  case options["action"]
331
331
  when "cache"
332
- zoom.cache.shortcut(zoom.config)
332
+ zoom.cache.shortcut
333
333
  when "configure"
334
334
  Zoom.hilight(false)
335
335
  djinni = Djinni.new
data/bin/zf CHANGED
@@ -329,7 +329,7 @@ begin
329
329
 
330
330
  case options["action"]
331
331
  when "cache"
332
- zoom.cache.shortcut(zoom.config)
332
+ zoom.cache.shortcut
333
333
  when "configure"
334
334
  Zoom.hilight(false)
335
335
  djinni = Djinni.new
data/bin/zg CHANGED
@@ -329,7 +329,7 @@ begin
329
329
 
330
330
  case options["action"]
331
331
  when "cache"
332
- zoom.cache.shortcut(zoom.config)
332
+ zoom.cache.shortcut
333
333
  when "configure"
334
334
  Zoom.hilight(false)
335
335
  djinni = Djinni.new
data/bin/zl CHANGED
@@ -329,7 +329,7 @@ begin
329
329
 
330
330
  case options["action"]
331
331
  when "cache"
332
- zoom.cache.shortcut(zoom.config)
332
+ zoom.cache.shortcut
333
333
  when "configure"
334
334
  Zoom.hilight(false)
335
335
  djinni = Djinni.new
data/bin/zr CHANGED
@@ -329,7 +329,7 @@ begin
329
329
 
330
330
  case options["action"]
331
331
  when "cache"
332
- zoom.cache.shortcut(zoom.config)
332
+ zoom.cache.shortcut
333
333
  when "configure"
334
334
  Zoom.hilight(false)
335
335
  djinni = Djinni.new
@@ -86,8 +86,8 @@ class Zoom
86
86
  end
87
87
 
88
88
  def initialize(cache = nil, rc = nil)
89
- @cache = Zoom::Cache.new(cache)
90
89
  @config = Zoom::Config.new(rc)
90
+ @cache = Zoom::Cache.new(@config, cache)
91
91
  @@hilight = @config.hilight
92
92
  end
93
93
 
@@ -132,7 +132,7 @@ class Zoom
132
132
  @cache.write(profile.exe(header), header["regex"])
133
133
 
134
134
  # Display results from cache
135
- @cache.shortcut(@config) if (shortcut)
135
+ @cache.shortcut if (shortcut)
136
136
  rescue Interrupt
137
137
  # ^C
138
138
  end
@@ -71,10 +71,11 @@ class Zoom::Cache
71
71
  end
72
72
  end
73
73
 
74
- def initialize(file = nil)
74
+ def initialize(config, file = nil)
75
75
  file = "~/.cache/zoom/cache" if (file.nil?)
76
76
 
77
77
  @cache_file = Pathname.new(file).expand_path
78
+ @config = config
78
79
  @results = nil
79
80
  @thread = nil
80
81
  @header = Hash.new
@@ -128,6 +129,8 @@ class Zoom::Cache
128
129
  tag = 1
129
130
  @thread.kill if (@thread)
130
131
  @thread = Thread.new do
132
+ profile = nil
133
+
131
134
  # Read in cache
132
135
  File.open(@cache_file) do |cache|
133
136
  cache.each do |line|
@@ -136,12 +139,25 @@ class Zoom::Cache
136
139
  @header = JSON.parse(
137
140
  line.gsub("ZOOM_HEADER=", "")
138
141
  )
142
+
143
+ if (!@config.has_profile?(profile_name))
144
+ raise
145
+ Zoom::Error::ProfileDoesNotExist.new(
146
+ profile_name
147
+ )
148
+ end
149
+ profile = @config.get_profile(profile_name)
139
150
  elsif (line.match(/^-?-?$/))
140
151
  # Ignore dividers when searching with context
141
152
  # and empty lines
142
153
  else
143
154
  @results.push(
144
- Zoom::Cache::Result.new(tag, line, self)
155
+ Zoom::Cache::Result.new(
156
+ tag,
157
+ line,
158
+ self,
159
+ profile.grep_like_tags?
160
+ )
145
161
  )
146
162
  tag += 1
147
163
  end
@@ -155,15 +171,15 @@ class Zoom::Cache
155
171
  return @header["regex"]
156
172
  end
157
173
 
158
- def shortcut(config)
174
+ def shortcut
159
175
  return if (empty?)
160
176
 
161
- config.validate_colors
162
- if (!config.has_profile?(profile_name))
177
+ @config.validate_colors
178
+ if (!@config.has_profile?(profile_name))
163
179
  raise Zoom::Error::ProfileDoesNotExist.new(profile_name)
164
180
  end
165
181
 
166
- profile = config.get_profile(profile_name)
182
+ profile = @config.get_profile(profile_name)
167
183
  if (!profile.taggable)
168
184
  get_results.each do |result|
169
185
  puts result.contents
@@ -176,30 +192,30 @@ class Zoom::Cache
176
192
  if (result.grep_like?)
177
193
  if (result.filename != curr_filename)
178
194
  puts if (curr_filename)
179
- puts config.hilight_filename(result.filename)
195
+ puts @config.hilight_filename(result.filename)
180
196
  curr_filename = result.filename
181
197
  end
182
198
 
183
199
  puts [
184
- config.hilight_tag("[#{result.tag}]"),
185
- "#{config.hilight_lineno(result.lineno)}:",
200
+ @config.hilight_tag("[#{result.tag}]"),
201
+ "#{@config.hilight_lineno(result.lineno)}:",
186
202
  result.match.gsub(
187
203
  /(#{regex})/i,
188
- config.hilight_match("\\1")
204
+ @config.hilight_match("\\1")
189
205
  )
190
206
  ].join(" ")
191
207
  else
192
208
  if (result.filename)
193
209
  if (result.filename != curr_filename)
194
210
  puts if (curr_filename)
195
- puts config.hilight_filename(result.filename)
211
+ puts @config.hilight_filename(result.filename)
196
212
  curr_filename = result.filename
197
213
  end
198
214
  end
199
215
 
200
216
  tag = result.tag
201
217
  line = result.contents
202
- puts [config.hilight_tag("[#{tag}]"), line].join(" ")
218
+ puts [@config.hilight_tag("[#{tag}]"), line].join(" ")
203
219
  end
204
220
  end
205
221
  end
@@ -9,7 +9,7 @@ class Zoom::Cache::Result
9
9
  return @grep_like
10
10
  end
11
11
 
12
- def initialize(tag, contents, cache)
12
+ def initialize(tag, contents, cache, grep_like_tags)
13
13
  @cache = cache
14
14
  @contents = contents.unpack("C*").pack("U*").gsub(
15
15
  /([\u0080-\u00ff]+)/,
@@ -21,21 +21,23 @@ class Zoom::Cache::Result
21
21
  @match = nil
22
22
  @tag = tag
23
23
 
24
- case @contents
25
- when /^Binary file (.+) matches\.$/
26
- @contents.match(/^Binary file (.+) matches\.$/) do |m|
27
- next if (m.nil?)
28
- @filename = "Binary file"
29
- @contents = m[1]
30
- end
31
- when /^([^:]+)[:-](\d+)[:-](.*)$/
32
- @contents.match(/^([^:]+)[:-](\d+)[:-](.*)$/) do |m|
33
- next if (m.nil?)
24
+ if (grep_like_tags)
25
+ case @contents
26
+ when /^Binary file (.+) matches\.$/
27
+ @contents.match(/^Binary file (.+) matches\.$/) do |m|
28
+ next if (m.nil?)
29
+ @filename = "Binary file"
30
+ @contents = m[1]
31
+ end
32
+ when /^([^:]+)[:-](\d+)[:-](.*)$/
33
+ @contents.match(/^([^:]+)[:-](\d+)[:-](.*)$/) do |m|
34
+ next if (m.nil?)
34
35
 
35
- @grep_like = true
36
- @filename = m[1].gsub(/^\.\//, "")
37
- @lineno = m[2]
38
- @match = m[3]
36
+ @grep_like = true
37
+ @filename = m[1].gsub(/^\.\//, "")
38
+ @lineno = m[2]
39
+ @match = m[3]
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -86,6 +86,10 @@ class Zoom::Profile < Hash
86
86
  @taggable = false # Should results be tagged like grep
87
87
  end
88
88
 
89
+ def grep_like_tags?
90
+ return @grep_like_tags
91
+ end
92
+
89
93
  def hilight_after(str)
90
94
  return str if (!Zoom.hilight?)
91
95
  return str.yellow
@@ -148,6 +152,7 @@ class Zoom::Profile < Hash
148
152
 
149
153
  # In case someone overrides grep_like_format_flags
150
154
  @format_flags = ""
155
+ @grep_like_tags = true
151
156
  @taggable = false
152
157
 
153
158
  grep_like_format_flags
@@ -23,6 +23,7 @@ class Zoom::Profile::Find < Zoom::Profile
23
23
 
24
24
  def grep_like_format_flags(all = false)
25
25
  super
26
+ @grep_like_tags = false
26
27
  @taggable = true
27
28
  end
28
29
 
@@ -41,9 +42,12 @@ class Zoom::Profile::Find < Zoom::Profile
41
42
  header["regex"] = ""
42
43
  end
43
44
 
44
- # If regex was provided then assume it's an iname search
45
+ # If regex was provided then assume it's an iregex search
45
46
  if (!header["regex"].empty?)
46
- header["regex"] = "-iregex \"#{header["regex"]}\""
47
+ header["regex"] = [
48
+ "-regextype posix-extended",
49
+ "-iregex \".*#{header["regex"]}.*\""
50
+ ].join(" ")
47
51
  end
48
52
 
49
53
  return header
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-zoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.4
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Whittaker