ngworder 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/ngworder/version.rb +1 -1
- data/lib/ngworder.rb +47 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23598b09a95c1a5d1c7362d008a6fd720abedca91cd3c3203c785184f3e44c71
|
|
4
|
+
data.tar.gz: 980852622d530f10d99555c6f7ec15d4979882ca61b1d605cd92f19af914e5d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2b577059d5e7f2c6c0491f03ac5d89dda7ae0593fee619e43918c897734330b746e170370e3602b2ac7bb7f59066370a9ce56254643df3ab511129f6acc86b3
|
|
7
|
+
data.tar.gz: 2686e87281aab43bb92e6413a502bcc1fd6d733f446f3a1d8e8438790d48dae85bcdac3f985f50ddbfe5b117170b8b3e59ee9a2dbae91f22c92375fc9958a2d9
|
data/README.md
CHANGED
|
@@ -4,8 +4,7 @@ Simple CLI to extract NG words from Japanese text using a plain text rules file.
|
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
```
|
|
7
|
-
gem
|
|
8
|
-
gem install ./ngworder-0.1.0.gem
|
|
7
|
+
gem install ngworder
|
|
9
8
|
```
|
|
10
9
|
|
|
11
10
|
## Usage
|
|
@@ -13,6 +12,8 @@ gem install ./ngworder-0.1.0.gem
|
|
|
13
12
|
ngworder target.md
|
|
14
13
|
ngworder --rule=NGWORDS.txt target.md
|
|
15
14
|
ngworder --rg target.md
|
|
15
|
+
ngworder --no-line target.md
|
|
16
|
+
ngworder --color=auto target.md
|
|
16
17
|
ngworder --help
|
|
17
18
|
```
|
|
18
19
|
|
data/lib/ngworder/version.rb
CHANGED
data/lib/ngworder.rb
CHANGED
|
@@ -225,6 +225,8 @@ module Ngworder
|
|
|
225
225
|
opts.banner = "Usage: ngworder [--rule=NGWORDS.txt] <files...>"
|
|
226
226
|
opts.on("--rule=PATH", "Rules file path (default: NGWORDS.txt)") { |value| options[:rule] = value }
|
|
227
227
|
opts.on("--rg", "Use ripgrep for literal-only prefiltering") { options[:rg] = true }
|
|
228
|
+
opts.on("--[no-]line", "Print the entire line after each match") { |value| options[:line] = value }
|
|
229
|
+
opts.on("--color=MODE", "Colorize matches (auto, always, never)") { |value| options[:color] = value }
|
|
228
230
|
opts.on("-h", "--help", "Show help") do
|
|
229
231
|
puts opts
|
|
230
232
|
return 0
|
|
@@ -247,6 +249,42 @@ module Ngworder
|
|
|
247
249
|
rules = Parser.build_rules(rule_path)
|
|
248
250
|
warn "No rules loaded from #{rule_path}" if rules.empty?
|
|
249
251
|
|
|
252
|
+
line_enabled = options.key?(:line) ? options[:line] : true
|
|
253
|
+
|
|
254
|
+
color_mode = (options[:color] || "auto").downcase
|
|
255
|
+
unless %w[auto always never].include?(color_mode)
|
|
256
|
+
warn "Invalid color mode: #{color_mode} (use auto, always, or never)"
|
|
257
|
+
return 2
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
color_enabled = case color_mode
|
|
261
|
+
when "always"
|
|
262
|
+
true
|
|
263
|
+
when "never"
|
|
264
|
+
false
|
|
265
|
+
else
|
|
266
|
+
$stdout.tty?
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
colorize_match = lambda do |text|
|
|
270
|
+
return text unless color_enabled
|
|
271
|
+
|
|
272
|
+
"\e[35m#{text}\e[0m"
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
highlight_line = lambda do |line, span|
|
|
276
|
+
return line unless color_enabled
|
|
277
|
+
|
|
278
|
+
start_idx = span[0]
|
|
279
|
+
end_idx = span[1]
|
|
280
|
+
head = line[0, start_idx]
|
|
281
|
+
mid = line[start_idx, end_idx - start_idx]
|
|
282
|
+
tail = line[end_idx..-1]
|
|
283
|
+
return line if mid.nil?
|
|
284
|
+
|
|
285
|
+
"#{head}\e[35m#{mid}\e[0m#{tail}"
|
|
286
|
+
end
|
|
287
|
+
|
|
250
288
|
found = false
|
|
251
289
|
|
|
252
290
|
argv.each do |path|
|
|
@@ -284,7 +322,9 @@ module Ngworder
|
|
|
284
322
|
|
|
285
323
|
found = true
|
|
286
324
|
col_no = span[0] + 1
|
|
287
|
-
|
|
325
|
+
match_text = colorize_match.call(span[2])
|
|
326
|
+
puts "#{path}:#{line_no}:#{col_no} #{match_text} NG:#{rule.label}"
|
|
327
|
+
puts highlight_line.call(line, span) if line_enabled
|
|
288
328
|
end
|
|
289
329
|
end
|
|
290
330
|
end
|
|
@@ -312,7 +352,9 @@ module Ngworder
|
|
|
312
352
|
|
|
313
353
|
found = true
|
|
314
354
|
col_no = span[0] + 1
|
|
315
|
-
|
|
355
|
+
match_text = colorize_match.call(span[2])
|
|
356
|
+
puts "#{path}:#{line_no}:#{col_no} #{match_text} NG:#{rule.label}"
|
|
357
|
+
puts highlight_line.call(line, span) if line_enabled
|
|
316
358
|
end
|
|
317
359
|
end
|
|
318
360
|
|
|
@@ -329,7 +371,9 @@ module Ngworder
|
|
|
329
371
|
|
|
330
372
|
found = true
|
|
331
373
|
col_no = span[0] + 1
|
|
332
|
-
|
|
374
|
+
match_text = colorize_match.call(span[2])
|
|
375
|
+
puts "#{path}:#{line_no}:#{col_no} #{match_text} NG:#{rule.label}"
|
|
376
|
+
puts highlight_line.call(line, span) if line_enabled
|
|
333
377
|
end
|
|
334
378
|
end
|
|
335
379
|
end
|