rufio 1.5.1 → 1.6.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 +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +8 -3
- data/README_ja.md +7 -3
- data/Rakefile +5 -0
- data/SECURITY.md +2 -2
- data/docs/guide.md +41 -8
- data/docs/guide_ja.md +41 -8
- data/docs/native_fuzzy_search_design_ja.md +684 -0
- data/info/help.md +13 -4
- data/info/keybindings.md +5 -3
- data/info/welcome.md +2 -2
- data/lib/rufio/config.rb +0 -2
- data/lib/rufio/config_loader.rb +24 -4
- data/lib/rufio/fuzzy_candidate_block.rb +131 -0
- data/lib/rufio/fuzzy_candidate_cache.rb +258 -0
- data/lib/rufio/fuzzy_file_source.rb +180 -0
- data/lib/rufio/fuzzy_finder.rb +313 -0
- data/lib/rufio/fuzzy_preview_loader.rb +107 -0
- data/lib/rufio/fuzzy_search.rb +327 -0
- data/lib/rufio/fuzzy_search_session.rb +426 -0
- data/lib/rufio/global_search.rb +292 -51
- data/lib/rufio/health_checker.rb +0 -22
- data/lib/rufio/help_menu.rb +5 -4
- data/lib/rufio/keybind_handler.rb +6 -5
- data/lib/rufio/native/aarch64-linux-gnu/librufio_zig.so +0 -0
- data/lib/rufio/native/aarch64-linux-musl/librufio_zig.so +0 -0
- data/lib/rufio/native/aarch64-macos/librufio_zig.dylib +0 -0
- data/lib/rufio/native/aarch64-windows/rufio_zig.dll +0 -0
- data/lib/rufio/native/x86_64-linux-gnu/librufio_zig.so +0 -0
- data/lib/rufio/native/x86_64-linux-musl/librufio_zig.so +0 -0
- data/lib/rufio/native/x86_64-macos/librufio_zig.dylib +0 -0
- data/lib/rufio/native/x86_64-windows/rufio_zig.dll +0 -0
- data/lib/rufio/native_content_search.rb +43 -7
- data/lib/rufio/native_scanner_zig.rb +17 -0
- data/lib/rufio/rga_result_source.rb +89 -0
- data/lib/rufio/screen.rb +5 -1
- data/lib/rufio/search_controller.rb +56 -54
- data/lib/rufio/terminal_ui.rb +70 -8
- data/lib/rufio/ui_renderer.rb +1 -1
- data/lib/rufio/version.rb +1 -1
- data/lib/rufio.rb +6 -0
- data/lib_zig/rufio_native/Makefile +16 -2
- data/lib_zig/rufio_native/build.zig +8 -0
- data/lib_zig/rufio_native/src/fuzzy.zig +520 -0
- data/lib_zig/rufio_native/src/fuzzy_test.zig +212 -0
- data/lib_zig/rufio_native/src/main.zig +27 -0
- data/lib_zig/rufio_native/src/search.zig +221 -44
- metadata +13 -2
data/lib/rufio/global_search.rb
CHANGED
|
@@ -5,15 +5,22 @@ require_relative 'text_utils'
|
|
|
5
5
|
require_relative 'config_loader'
|
|
6
6
|
require_relative 'document_text_extractor'
|
|
7
7
|
require_relative 'native_content_search'
|
|
8
|
+
require_relative 'fuzzy_search_session'
|
|
9
|
+
require_relative 'fuzzy_candidate_block'
|
|
8
10
|
|
|
9
11
|
module Rufio
|
|
10
12
|
# ブックマーク配下のファイル名・テキスト内容をバックグラウンドで横断検索する。
|
|
13
|
+
# ファイル名は s と同じあいまい検索(FuzzySearchSession)、本文は大文字小文字を無視したリテラル検索。
|
|
11
14
|
class GlobalSearch
|
|
12
15
|
SPINNER_FRAMES = ['|', '/', '-', '\\'].freeze
|
|
13
16
|
SPINNER_INTERVAL = 0.12
|
|
14
17
|
# 検索語に一致した部分の表示(黒の太字・黄色背景)
|
|
15
18
|
MATCH_FG = "\e[30m\e[1m"
|
|
16
19
|
MATCH_BG = "\e[43m"
|
|
20
|
+
# ファイル名検索で一覧に保持する上位件数
|
|
21
|
+
FILE_RESULT_LIMIT = 1_000
|
|
22
|
+
# 一致位置は上位のこの件数だけ照合時に求め、それより下の行は表示するときに求める
|
|
23
|
+
FILE_POSITION_LIMIT = 100
|
|
17
24
|
|
|
18
25
|
attr_reader :query, :results, :errors, :selected_index, :search_type, :skipped_files
|
|
19
26
|
|
|
@@ -31,6 +38,7 @@ module Rufio
|
|
|
31
38
|
@active = false
|
|
32
39
|
@scanning = false
|
|
33
40
|
@worker = nil
|
|
41
|
+
@session = nil
|
|
34
42
|
@document_extractor = DocumentTextExtractor.new
|
|
35
43
|
@document_cache = DocumentTextCache.new(extractor: @document_extractor)
|
|
36
44
|
end
|
|
@@ -58,37 +66,14 @@ module Rufio
|
|
|
58
66
|
def close
|
|
59
67
|
@active = false
|
|
60
68
|
@scanning = false
|
|
61
|
-
|
|
62
|
-
@worker&.join
|
|
63
|
-
@worker = nil
|
|
69
|
+
stop_search
|
|
64
70
|
end
|
|
65
71
|
|
|
66
72
|
# 1フレーム当たりの処理量を制限し、検索中も入力を受け付ける。
|
|
67
73
|
def poll
|
|
68
74
|
return false unless active?
|
|
69
75
|
|
|
70
|
-
changed =
|
|
71
|
-
256.times do
|
|
72
|
-
event = begin
|
|
73
|
-
@events.pop(true)
|
|
74
|
-
rescue ThreadError
|
|
75
|
-
break
|
|
76
|
-
end
|
|
77
|
-
changed = true
|
|
78
|
-
type, value = event
|
|
79
|
-
case type
|
|
80
|
-
when :entry
|
|
81
|
-
@entries << value
|
|
82
|
-
@results << value if @search_type == :content || matches_query?(value)
|
|
83
|
-
when :entries
|
|
84
|
-
# Zig 実装の結果はまとめて届くので、1 フレーム 256 件の上限に縛られない
|
|
85
|
-
@entries.concat(value)
|
|
86
|
-
@results.concat(@search_type == :content || @query.empty? ? value : value.select { |entry| matches_query?(entry) })
|
|
87
|
-
when :error then @errors << value
|
|
88
|
-
when :skipped then @skipped_files += value || 1
|
|
89
|
-
when :done then @scanning = false
|
|
90
|
-
end
|
|
91
|
-
end
|
|
76
|
+
changed = @session ? poll_session : poll_events
|
|
92
77
|
if scanning?
|
|
93
78
|
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
94
79
|
if now - @last_spinner_update >= SPINNER_INTERVAL
|
|
@@ -107,20 +92,21 @@ module Rufio
|
|
|
107
92
|
@search_type = @search_type == :filename ? :content : :filename
|
|
108
93
|
start_scan
|
|
109
94
|
when "\r" then return @results[@selected_index]
|
|
110
|
-
when :down then @selected_index
|
|
111
|
-
when :up then @selected_index
|
|
95
|
+
when :down then select_index(@selected_index + 1)
|
|
96
|
+
when :up then select_index(@selected_index - 1)
|
|
112
97
|
when "\x0a", "\x0e" then handle_key(:down) # Ctrl+J / Ctrl+N
|
|
113
98
|
when "\x0b", "\x10" then handle_key(:up) # Ctrl+K / Ctrl+P
|
|
114
99
|
when "\x15" then update_query('') # Ctrl+U
|
|
115
100
|
when "\u007f", "\b" then update_query(@query[0...-1])
|
|
116
101
|
else
|
|
117
|
-
update_query(@query + key) if key.is_a?(String) && !key.empty? && key.
|
|
102
|
+
update_query(@query + key) if key.is_a?(String) && !key.empty? && key.valid_encoding? &&
|
|
103
|
+
key.each_codepoint.all? { |c| c >= 32 && c != 127 }
|
|
118
104
|
end
|
|
119
105
|
nil
|
|
120
106
|
end
|
|
121
107
|
|
|
122
108
|
def draw(screen)
|
|
123
|
-
screen.clear
|
|
109
|
+
screen.clear(mark_dirty: true)
|
|
124
110
|
width = screen.width
|
|
125
111
|
type = @search_type == :content ? 'Content' : 'File names'
|
|
126
112
|
write_line(screen, 0, "G mode - #{type} | Tab: Switch name/content search", width, "\e[1;36m")
|
|
@@ -133,7 +119,8 @@ module Rufio
|
|
|
133
119
|
'Search complete'
|
|
134
120
|
end
|
|
135
121
|
color = scanning? ? "\e[1;33m" : "\e[32m"
|
|
136
|
-
|
|
122
|
+
matches = @session ? @total_matches : @results.length
|
|
123
|
+
write_line(screen, 2, "#{state} | #{@bookmark_count} bookmarks | #{matches} matches | #{@errors.length} errors | #{@skipped_files} skipped", width, color)
|
|
137
124
|
row_height = @search_type == :content ? 2 : 1
|
|
138
125
|
capacity = [screen.height - 6, 0].max / row_height
|
|
139
126
|
first = [@selected_index - capacity + 1, 0].max
|
|
@@ -149,9 +136,9 @@ module Rufio
|
|
|
149
136
|
''
|
|
150
137
|
end
|
|
151
138
|
y = index * row_height + 3
|
|
152
|
-
#
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
# ファイル名検索はあいまい検索の一致位置、本文検索はスニペットの一致箇所をハイライトする
|
|
140
|
+
write_line(screen, y, text, width, selected ? "\e[1;36m" : nil)
|
|
141
|
+
highlight_positions(screen, y, prefix, entry, width) if @search_type == :filename
|
|
155
142
|
write_line(screen, y + 1, " #{entry[:match_text]}", width, highlight_from: 4) if entry[:match_text]
|
|
156
143
|
end
|
|
157
144
|
if @results.empty?
|
|
@@ -161,7 +148,7 @@ module Rufio
|
|
|
161
148
|
'Searching bookmarked directories...'
|
|
162
149
|
elsif @search_type == :content && @query.empty?
|
|
163
150
|
'Type a string to search inside text files.'
|
|
164
|
-
elsif !@errors.empty? &&
|
|
151
|
+
elsif !@errors.empty? && candidate_count.zero?
|
|
165
152
|
'No readable files in bookmarked directories.'
|
|
166
153
|
else
|
|
167
154
|
'No matching files. Edit your search to try again.'
|
|
@@ -174,32 +161,48 @@ module Rufio
|
|
|
174
161
|
|
|
175
162
|
private
|
|
176
163
|
|
|
177
|
-
|
|
164
|
+
# 本文検索の走査スレッドとファイル名検索のセッションを止める。セッションは待たずに閉じる
|
|
165
|
+
def stop_search
|
|
178
166
|
@worker&.kill
|
|
179
167
|
@worker&.join
|
|
180
168
|
@worker = nil
|
|
169
|
+
@session&.close
|
|
170
|
+
@session = nil
|
|
171
|
+
@file_source = nil
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def candidate_count
|
|
175
|
+
@session ? @candidate_count : @entries.length
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def start_scan
|
|
179
|
+
stop_search
|
|
181
180
|
@entries = []
|
|
182
181
|
@results = []
|
|
182
|
+
@result_ids = []
|
|
183
183
|
@errors = []
|
|
184
184
|
@skipped_files = 0
|
|
185
185
|
@selected_index = 0
|
|
186
|
+
@selected_id = nil
|
|
187
|
+
@total_matches = 0
|
|
188
|
+
@candidate_count = 0
|
|
189
|
+
@shown = nil
|
|
186
190
|
@events = SizedQueue.new(256)
|
|
187
191
|
@spinner_index = 0
|
|
188
192
|
@last_spinner_update = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
189
193
|
@scanning = !(@search_type == :content && @query.empty?)
|
|
190
194
|
return unless @scanning
|
|
195
|
+
return start_file_name_session if @search_type == :filename
|
|
191
196
|
|
|
192
|
-
roots, events,
|
|
197
|
+
roots, events, query = @roots, @events, @query.downcase
|
|
193
198
|
native = self.class.native_search?
|
|
194
|
-
native_cache = native
|
|
199
|
+
native_cache = native ? (@native_cache ||= NativeContentSearch::Cache.new) : nil
|
|
195
200
|
@worker = Thread.new do
|
|
196
201
|
begin
|
|
197
|
-
if native &&
|
|
202
|
+
if native && NativeContentSearch.supports_query?(query)
|
|
198
203
|
scan_roots_natively(roots, events, query, native_cache)
|
|
199
|
-
elsif native && type == :filename && NativeContentSearch.files_available?
|
|
200
|
-
scan_files_natively(roots, events)
|
|
201
204
|
else
|
|
202
|
-
scan_roots(roots, events,
|
|
205
|
+
scan_roots(roots, events, :content, query)
|
|
203
206
|
end
|
|
204
207
|
rescue StandardError => e
|
|
205
208
|
events << [:error, e.message]
|
|
@@ -208,20 +211,103 @@ module Rufio
|
|
|
208
211
|
end
|
|
209
212
|
end
|
|
210
213
|
|
|
214
|
+
# ファイル名は走査と照合を FuzzySearchSession のワーカーに任せ、UI スレッドでは絞り込まない
|
|
215
|
+
def start_file_name_session
|
|
216
|
+
@file_source = FileNameSource.new(self, @roots, self.class.native_search?)
|
|
217
|
+
@session = FuzzySearchSession.new(source: @file_source, limit: FILE_RESULT_LIMIT,
|
|
218
|
+
position_limit: FILE_POSITION_LIMIT).start
|
|
219
|
+
@session.update_query(@query) unless @query.empty?
|
|
220
|
+
# 開いた直後の状態は描画済みなので、変化があったときだけ poll で再描画させる
|
|
221
|
+
@shown = @session.snapshot
|
|
222
|
+
end
|
|
223
|
+
|
|
211
224
|
def update_query(query)
|
|
212
225
|
@query = query
|
|
213
226
|
@selected_index = 0
|
|
214
|
-
@
|
|
227
|
+
@selected_id = nil
|
|
228
|
+
return start_scan if @search_type == :content || @session.nil?
|
|
229
|
+
|
|
230
|
+
# 前の検索語の結果を選べないよう、新しい結果が届くまで一覧を空にする
|
|
231
|
+
@session.update_query(query)
|
|
232
|
+
@results = []
|
|
233
|
+
@result_ids = []
|
|
234
|
+
@scanning = true
|
|
235
|
+
rescue IOError
|
|
236
|
+
nil
|
|
215
237
|
end
|
|
216
238
|
|
|
217
|
-
def
|
|
218
|
-
|
|
219
|
-
@
|
|
220
|
-
@selected_index = [[@selected_index, @results.length - 1].min, 0].max
|
|
239
|
+
def select_index(index)
|
|
240
|
+
@selected_index = index.clamp(0, [@results.length - 1, 0].max)
|
|
241
|
+
@selected_id = @result_ids&.[](@selected_index)
|
|
221
242
|
end
|
|
222
243
|
|
|
223
|
-
def
|
|
224
|
-
|
|
244
|
+
def poll_session
|
|
245
|
+
@session.poll
|
|
246
|
+
state = @session.snapshot
|
|
247
|
+
@skipped_files = @file_source.skipped
|
|
248
|
+
@scanning = state.scanning || state.searching
|
|
249
|
+
return false if state.equal?(@shown)
|
|
250
|
+
|
|
251
|
+
@shown = state
|
|
252
|
+
@results = state.results.map { |result| result[:entry].merge(positions: result[:positions]) }
|
|
253
|
+
@result_ids = state.results.map { |result| result[:id] }
|
|
254
|
+
@errors = state.errors
|
|
255
|
+
@total_matches = state.total_matches
|
|
256
|
+
@candidate_count = state.candidate_count
|
|
257
|
+
# 候補の追加で順位が変わっても、選択中のファイルを追い続ける
|
|
258
|
+
index = @selected_id && @result_ids.index(@selected_id)
|
|
259
|
+
@selected_index = (index || @selected_index).clamp(0, [@results.length - 1, 0].max)
|
|
260
|
+
true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# 本文検索の走査スレッドからのイベントを 1 フレーム当たり最大 256 件取り込む
|
|
264
|
+
def poll_events
|
|
265
|
+
changed = false
|
|
266
|
+
256.times do
|
|
267
|
+
event = begin
|
|
268
|
+
@events.pop(true)
|
|
269
|
+
rescue ThreadError
|
|
270
|
+
break
|
|
271
|
+
end
|
|
272
|
+
changed = true
|
|
273
|
+
type, value = event
|
|
274
|
+
case type
|
|
275
|
+
when :entry
|
|
276
|
+
@entries << value
|
|
277
|
+
@results << value
|
|
278
|
+
when :entries
|
|
279
|
+
# Zig 実装の結果はまとめて届くので、1 フレーム 256 件の上限に縛られない
|
|
280
|
+
@entries.concat(value)
|
|
281
|
+
@results.concat(value)
|
|
282
|
+
when :error then @errors << value
|
|
283
|
+
when :skipped then @skipped_files += value || 1
|
|
284
|
+
when :done then @scanning = false
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
changed
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# あいまい検索の一致位置(UTF-8 の先頭バイトオフセット)を表示桁に変換してハイライトする
|
|
291
|
+
def highlight_positions(screen, y, prefix, entry, width)
|
|
292
|
+
offsets = entry[:positions]
|
|
293
|
+
# 照合時に位置を求めなかった下位の行は、表示する行だけここで求める(照合と同じ位置になる)
|
|
294
|
+
offsets = FuzzySearch.positions(entry[:text], @shown.query) if offsets.nil? && @shown
|
|
295
|
+
return if offsets.nil? || offsets.empty?
|
|
296
|
+
|
|
297
|
+
targets = offsets.each_with_object({}) { |offset, set| set[offset] = true }
|
|
298
|
+
line = "#{prefix}#{entry[:text]}"
|
|
299
|
+
limit = TextUtils.display_width(line) > width ? width - TextUtils::ELLIPSIS_MIN_WIDTH : width
|
|
300
|
+
x = TextUtils.display_width(prefix)
|
|
301
|
+
byte = 0
|
|
302
|
+
entry[:text].each_char do |char|
|
|
303
|
+
shown = char.match?(/[[:cntrl:]]/) ? ' ' : char
|
|
304
|
+
char_width = TextUtils.display_width(shown)
|
|
305
|
+
break if x + char_width > limit
|
|
306
|
+
|
|
307
|
+
screen.put(x, y, shown, fg: MATCH_FG, bg: MATCH_BG, width: char_width) if targets[byte]
|
|
308
|
+
x += char_width
|
|
309
|
+
byte += char.bytesize
|
|
310
|
+
end
|
|
225
311
|
end
|
|
226
312
|
|
|
227
313
|
def scan_roots(roots, events, type, query)
|
|
@@ -272,7 +358,7 @@ module Rufio
|
|
|
272
358
|
end
|
|
273
359
|
|
|
274
360
|
# Zig 実装でブックマーク配下のファイル一覧を並列走査する
|
|
275
|
-
def scan_files_natively(roots, events)
|
|
361
|
+
def scan_files_natively(roots, events, cancelled: nil)
|
|
276
362
|
valid_roots = []
|
|
277
363
|
roots.each do |name, root|
|
|
278
364
|
root = File.expand_path(root)
|
|
@@ -284,12 +370,22 @@ module Rufio
|
|
|
284
370
|
end
|
|
285
371
|
return if valid_roots.empty?
|
|
286
372
|
|
|
373
|
+
# ラベル列を受け取れる相手(FileNameSource::Sink)には、ファイルごとのイベントを作らずに渡す
|
|
374
|
+
labels = events.respond_to?(:add_labels) && NativeContentSearch.labels_available?
|
|
287
375
|
engine = NativeContentSearch.new(roots: valid_roots.map(&:last), query: nil,
|
|
288
|
-
excluded_extensions: @excluded_extensions)
|
|
289
|
-
|
|
376
|
+
excluded_extensions: @excluded_extensions, labels: labels)
|
|
377
|
+
# 大きな取り出しは分けて受け取り、解析の合間に検索ワーカーと UI が動けるようにする
|
|
378
|
+
engine.each_batch(cancelled: cancelled, max_events: FileNameSource::BLOCK_SIZE) do |batch|
|
|
290
379
|
entries = []
|
|
291
380
|
batch.each do |kind, *args|
|
|
292
381
|
case kind
|
|
382
|
+
when :labels
|
|
383
|
+
unless entries.empty?
|
|
384
|
+
events << [:entries, entries]
|
|
385
|
+
entries = []
|
|
386
|
+
end
|
|
387
|
+
name, root = valid_roots[args[0]]
|
|
388
|
+
events.add_labels(name, root, args[1], args[2])
|
|
293
389
|
when :file, :match
|
|
294
390
|
name, root = valid_roots[args[0]]
|
|
295
391
|
path = args[1]
|
|
@@ -408,5 +504,150 @@ module Rufio
|
|
|
408
504
|
end
|
|
409
505
|
ranges
|
|
410
506
|
end
|
|
507
|
+
|
|
508
|
+
# ファイル名検索の候補を FuzzySearchSession に流す。既存の走査(Zig / Ruby)のイベントを
|
|
509
|
+
# バッチに変換し、停止要求があれば次のイベントで走査を打ち切る。
|
|
510
|
+
class FileNameSource
|
|
511
|
+
BLOCK_SIZE = 4096
|
|
512
|
+
Cancelled = Class.new(StandardError)
|
|
513
|
+
|
|
514
|
+
attr_reader :skipped
|
|
515
|
+
|
|
516
|
+
def initialize(search, roots, native)
|
|
517
|
+
@search = search
|
|
518
|
+
@roots = roots
|
|
519
|
+
@native = native
|
|
520
|
+
@skipped = 0
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
def each_batch(cancelled:, on_error:, &emit)
|
|
524
|
+
sink = Sink.new(self, cancelled, on_error, emit)
|
|
525
|
+
if @native && NativeContentSearch.files_available?
|
|
526
|
+
@search.send(:scan_files_natively, @roots, sink, cancelled: cancelled)
|
|
527
|
+
else
|
|
528
|
+
@search.send(:scan_roots, @roots, sink, :filename, '')
|
|
529
|
+
end
|
|
530
|
+
sink.flush
|
|
531
|
+
rescue Cancelled
|
|
532
|
+
nil
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
def add_skipped(count)
|
|
536
|
+
@skipped += count
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
# 「ブックマークのルート + 相対パス」から行を作る。scrub した候補だけ元のパスと相対パスを別に持つ
|
|
540
|
+
class Rows
|
|
541
|
+
def initialize(prefix, bookmark, encoding, exceptions)
|
|
542
|
+
@prefix = prefix
|
|
543
|
+
@bookmark = bookmark
|
|
544
|
+
@encoding = encoding
|
|
545
|
+
@exceptions = exceptions
|
|
546
|
+
freeze
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
def call(index, text)
|
|
550
|
+
path, relative = @exceptions && @exceptions[index]
|
|
551
|
+
relative ||= @encoding == Encoding::UTF_8 ? text : text.b.force_encoding(@encoding).freeze
|
|
552
|
+
{ text: text, path: path || (@prefix + text.b).force_encoding(@encoding).freeze,
|
|
553
|
+
bookmark: @bookmark, relative_path: relative }
|
|
554
|
+
end
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
# scan_roots / scan_files_natively が使う events << [種類, 値] を受け取る。
|
|
558
|
+
# 候補は行(Hash)にせず、同じブックマークが続く間は 1 つの FuzzyCandidateBlock に詰める。
|
|
559
|
+
class Sink
|
|
560
|
+
def initialize(source, cancelled, on_error, emit)
|
|
561
|
+
@source = source
|
|
562
|
+
@cancelled = cancelled
|
|
563
|
+
@on_error = on_error
|
|
564
|
+
@emit = emit
|
|
565
|
+
@builder = FuzzyCandidateBlock::Builder.new
|
|
566
|
+
@exceptions = nil
|
|
567
|
+
@prefix_text = nil
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
def <<(event)
|
|
571
|
+
raise Cancelled if @cancelled.call
|
|
572
|
+
|
|
573
|
+
type, value = event
|
|
574
|
+
case type
|
|
575
|
+
when :entry then add(value)
|
|
576
|
+
when :entries then value.each { |entry| add(entry) }
|
|
577
|
+
when :error then @on_error.call(value)
|
|
578
|
+
when :skipped then @source.add_skipped(value || 1)
|
|
579
|
+
end
|
|
580
|
+
flush if type == :entries
|
|
581
|
+
self
|
|
582
|
+
end
|
|
583
|
+
|
|
584
|
+
# Zig のラベル列(ルートからの相対パス NUL の連結)をそのままブロックにして渡す
|
|
585
|
+
def add_labels(bookmark, root, packed, count)
|
|
586
|
+
raise Cancelled if @cancelled.call
|
|
587
|
+
|
|
588
|
+
flush
|
|
589
|
+
prefix = (root.end_with?(File::SEPARATOR) ? root : root + File::SEPARATOR).b.freeze
|
|
590
|
+
rows = Rows.new(prefix, frozen(bookmark), Encoding.find('filesystem'), nil)
|
|
591
|
+
@emit.call(FuzzyCandidateBlock.new(packed.freeze, count, rows: rows, checked: true))
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
def flush
|
|
595
|
+
return if @builder.empty?
|
|
596
|
+
|
|
597
|
+
rows = Rows.new(@prefix, @bookmark, @encoding, @exceptions&.freeze)
|
|
598
|
+
block = @builder.build(rows)
|
|
599
|
+
@builder = FuzzyCandidateBlock::Builder.new
|
|
600
|
+
@exceptions = nil
|
|
601
|
+
@emit.call(block)
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
private
|
|
605
|
+
|
|
606
|
+
def frozen(value)
|
|
607
|
+
value.is_a?(String) && !value.frozen? ? value.dup.freeze : value
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
def add(entry)
|
|
611
|
+
relative = entry[:relative_path]
|
|
612
|
+
path = entry[:path]
|
|
613
|
+
text = relative.encoding == Encoding::UTF_8 ? relative : relative.dup.force_encoding(Encoding::UTF_8)
|
|
614
|
+
scrubbed = !text.valid_encoding?
|
|
615
|
+
text = text.scrub if scrubbed
|
|
616
|
+
if text.bytesize > FuzzyCandidateBlock::MAX_TEXT_BYTES || text.include?("\0")
|
|
617
|
+
@on_error.call("#{text[0, 200]}: file name cannot be searched")
|
|
618
|
+
return
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
tail = tail?(path, relative)
|
|
622
|
+
start_block(entry, path, tail ? path.bytesize - relative.bytesize : 0) unless fits?(entry, path, relative)
|
|
623
|
+
index = @builder.add(text)
|
|
624
|
+
# 「接頭辞 + 表示名」で組み立て直せない候補は、元の文字列をそのまま持つ
|
|
625
|
+
if scrubbed || !tail || relative.encoding != @encoding
|
|
626
|
+
(@exceptions ||= {})[index] = [frozen(path), frozen(relative)].freeze
|
|
627
|
+
end
|
|
628
|
+
flush if @builder.size >= BLOCK_SIZE
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
def tail?(path, relative)
|
|
632
|
+
path.end_with?(relative)
|
|
633
|
+
rescue Encoding::CompatibilityError
|
|
634
|
+
false
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
# 詰めている途中のブロックと同じブックマーク・同じルートの候補か
|
|
638
|
+
def fits?(entry, path, relative)
|
|
639
|
+
@prefix_text && entry[:bookmark] == @bookmark && path.encoding == @encoding &&
|
|
640
|
+
path.bytesize == @prefix_text.bytesize + relative.bytesize && path.start_with?(@prefix_text)
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
def start_block(entry, path, prefix_length)
|
|
644
|
+
flush
|
|
645
|
+
@bookmark = frozen(entry[:bookmark])
|
|
646
|
+
@encoding = path.encoding
|
|
647
|
+
@prefix_text = path.byteslice(0, prefix_length).freeze
|
|
648
|
+
@prefix = @prefix_text.b.freeze
|
|
649
|
+
end
|
|
650
|
+
end
|
|
651
|
+
end
|
|
411
652
|
end
|
|
412
653
|
end
|
data/lib/rufio/health_checker.rb
CHANGED
|
@@ -18,7 +18,6 @@ module Rufio
|
|
|
18
18
|
checks = [
|
|
19
19
|
{ name: ConfigLoader.message('health.ruby_version'), method: :check_ruby_version },
|
|
20
20
|
{ name: ConfigLoader.message('health.required_gems'), method: :check_required_gems },
|
|
21
|
-
{ name: ConfigLoader.message('health.fzf'), method: :check_fzf },
|
|
22
21
|
{ name: ConfigLoader.message('health.rga'), method: :check_rga },
|
|
23
22
|
{ name: ConfigLoader.message('health.zoxide'), method: :check_zoxide },
|
|
24
23
|
{ name: ConfigLoader.message('health.bat'), method: :check_bat },
|
|
@@ -86,23 +85,6 @@ module Rufio
|
|
|
86
85
|
end
|
|
87
86
|
end
|
|
88
87
|
|
|
89
|
-
def check_fzf
|
|
90
|
-
if system("which fzf > /dev/null 2>&1")
|
|
91
|
-
version = `fzf --version 2>/dev/null`.strip
|
|
92
|
-
{
|
|
93
|
-
status: :ok,
|
|
94
|
-
message: "fzf #{version}",
|
|
95
|
-
details: nil
|
|
96
|
-
}
|
|
97
|
-
else
|
|
98
|
-
{
|
|
99
|
-
status: :warning,
|
|
100
|
-
message: "fzf #{ConfigLoader.message('health.tool_not_found')}",
|
|
101
|
-
details: install_instruction_for('fzf')
|
|
102
|
-
}
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
88
|
def check_rga
|
|
107
89
|
if system("which rga > /dev/null 2>&1")
|
|
108
90
|
version = `rga --version 2>/dev/null | head -1`.strip
|
|
@@ -192,8 +174,6 @@ module Rufio
|
|
|
192
174
|
case RUBY_PLATFORM
|
|
193
175
|
when /darwin/
|
|
194
176
|
case tool
|
|
195
|
-
when 'fzf'
|
|
196
|
-
"#{ConfigLoader.message('health.install_brew')} fzf"
|
|
197
177
|
when 'rga'
|
|
198
178
|
"#{ConfigLoader.message('health.install_brew')} rga"
|
|
199
179
|
when 'zoxide'
|
|
@@ -203,8 +183,6 @@ module Rufio
|
|
|
203
183
|
end
|
|
204
184
|
when /linux/
|
|
205
185
|
case tool
|
|
206
|
-
when 'fzf'
|
|
207
|
-
"#{ConfigLoader.message('health.install_apt')} fzf (Ubuntu/Debian) or check your package manager"
|
|
208
186
|
when 'rga'
|
|
209
187
|
ConfigLoader.message('health.rga_releases')
|
|
210
188
|
when 'zoxide'
|
data/lib/rufio/help_menu.rb
CHANGED
|
@@ -71,9 +71,10 @@ module Rufio
|
|
|
71
71
|
"#{key(:create_file)}/#{key(:create_dir)}: Create file / directory",
|
|
72
72
|
'', 'Search and bookmarks',
|
|
73
73
|
"#{key(:filter)}: Filter | Enter: Apply | ESC: Clear",
|
|
74
|
-
"#{key(:
|
|
75
|
-
"#{key(:rga_search)}: Content search (rga)",
|
|
76
|
-
|
|
74
|
+
"#{key(:file_search)} or #{key(:file_search_alt)}: Fuzzy file name search",
|
|
75
|
+
"#{key(:rga_search)}: Content search (rga), then pick a result",
|
|
76
|
+
'In search: Ctrl+R rescans; wide screens show a preview',
|
|
77
|
+
"#{key(:global_search)}: Fuzzy file names or literal contents across all bookmarks",
|
|
77
78
|
"#{key(:add_bookmark)}/#{key(:bookmark_menu)}: Add / manage bookmarks",
|
|
78
79
|
'Tab / Shift+Tab: Next / previous bookmark',
|
|
79
80
|
"1-9: Jump to bookmark | #{key(:start_dir)}: Start directory",
|
|
@@ -91,7 +92,7 @@ module Rufio
|
|
|
91
92
|
"#{key(:navigate_parent)}: Parent directory; leaving config returns to Files.",
|
|
92
93
|
'', "[#{key(:global_search)}] Global search",
|
|
93
94
|
'Search file names or text inside every bookmarked directory.',
|
|
94
|
-
'Tab: Switch File names / Content (literal, case insensitive)',
|
|
95
|
+
'Tab: Switch File names (fuzzy, as s) / Content (literal, case insensitive)',
|
|
95
96
|
'Content results show file, line number and matching text.',
|
|
96
97
|
'Documents: .pdf (page), .xlsx (sheet/cell), .pptx (slide)',
|
|
97
98
|
'Ruby extracts document text; no Python or Office is needed.',
|
|
@@ -137,8 +137,8 @@ module Rufio
|
|
|
137
137
|
nil, @dialog_renderer, @selection_manager, @job_manager, @notification_manager
|
|
138
138
|
)
|
|
139
139
|
|
|
140
|
-
# SearchController
|
|
141
|
-
@search_controller = SearchController.new(nil, @file_opener)
|
|
140
|
+
# SearchController(内蔵ファジー検索・rga検索を担当)
|
|
141
|
+
@search_controller = SearchController.new(nil, @file_opener, @dialog_renderer)
|
|
142
142
|
|
|
143
143
|
# Help mode
|
|
144
144
|
@in_help_mode = false
|
|
@@ -168,6 +168,7 @@ module Rufio
|
|
|
168
168
|
@file_op_controller.set_terminal_ui(terminal_ui)
|
|
169
169
|
@archive_controller.set_terminal_ui(terminal_ui)
|
|
170
170
|
@bookmark_controller.set_terminal_ui(terminal_ui)
|
|
171
|
+
@search_controller.set_terminal_ui(terminal_ui)
|
|
171
172
|
# terminal_ui が設定されたら、bookmark_manager と zoxide_integration にも渡す
|
|
172
173
|
@bookmark_manager.set_terminal_ui(terminal_ui)
|
|
173
174
|
@zoxide_integration.set_terminal_ui(terminal_ui)
|
|
@@ -493,7 +494,7 @@ module Rufio
|
|
|
493
494
|
else
|
|
494
495
|
@nav_controller.start_filter_mode
|
|
495
496
|
end
|
|
496
|
-
when :
|
|
497
|
+
when :file_search, :file_search_alt then file_search
|
|
497
498
|
when :rga_search then rga_search
|
|
498
499
|
when :add_bookmark then add_bookmark
|
|
499
500
|
when :bookmark_menu then show_bookmark_menu
|
|
@@ -522,8 +523,8 @@ module Rufio
|
|
|
522
523
|
:quit_cd
|
|
523
524
|
end
|
|
524
525
|
|
|
525
|
-
def
|
|
526
|
-
@search_controller.
|
|
526
|
+
def file_search
|
|
527
|
+
@search_controller.file_search
|
|
527
528
|
end
|
|
528
529
|
|
|
529
530
|
def rga_search
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|