cr.rb 3.21.0 → 4.0.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cr +183 -133
- data/lib/cr.rb +18 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86ac16436cda04a1ca727329c6508f8c228d5049beb47ba02da193a684b1174d
|
4
|
+
data.tar.gz: f303ed5311033dbcab4a66eec6ad786633c02e4967e286711681b77b4a01a726
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52f6b13011db64ac7c439e323ccf2093656b6dcc2e337815f68323a9bd5f79f3d33f0a2f1f2f6906c7d3d6e4e954c8a8573884268990c99ad7bd6426682de21e
|
7
|
+
data.tar.gz: 1474e51ef60c31035104a0c66b168a1545f90085b13d3d8e468aa182f67885b8af3dbd7f1ed462b7b1251f847240255f8e0bf817bf2b94c1fbf88a3ef15ff0c2
|
data/bin/cr
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# File : cr.rb
|
5
5
|
# Authors : ccmywish <ccmywish@qq.com>
|
6
6
|
# Created on : <2021-07-08>
|
7
|
-
# Last modified : <2022-
|
7
|
+
# Last modified : <2022-11-27>
|
8
8
|
#
|
9
9
|
# cr:
|
10
10
|
#
|
@@ -18,14 +18,53 @@ require 'cr'
|
|
18
18
|
require 'tomlrb'
|
19
19
|
require 'fileutils'
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
CR_DEFAULT_LIBRARY = File.expand_path("~/.cryptic-resolver")
|
22
|
+
|
23
|
+
$CR_DEFAULT_DICTS = [
|
24
|
+
"https://github.com/cryptic-resolver/cryptic_common.git",
|
25
|
+
"https://github.com/cryptic-resolver/cryptic_computer.git",
|
26
|
+
"https://github.com/cryptic-resolver/cryptic_windows.git",
|
27
|
+
"https://github.com/cryptic-resolver/cryptic_linux.git",
|
28
|
+
"https://github.com/cryptic-resolver/cryptic_electronics"
|
29
|
+
]
|
30
|
+
|
31
|
+
# The config file will override the default dicts, but not default library!
|
32
|
+
if ENV['CRYPTIC_RESOLVER_CONFIG']
|
33
|
+
file = ENV['CRYPTIC_RESOLVER_CONFIG']
|
34
|
+
if test('f', file)
|
35
|
+
config = Tomlrb.load_file file
|
36
|
+
|
37
|
+
CR_EXTRA_LIBRARY ||= config['EXTRA_LIBRARY']
|
38
|
+
|
39
|
+
if config['DEFAULT_DICTS']
|
40
|
+
CR_DEFAULT_DICTS = config['DEFAULT_DICTS']
|
41
|
+
else
|
42
|
+
CR_DEFAULT_DICTS = $CR_DEFAULT_DICTS
|
43
|
+
end
|
44
|
+
|
45
|
+
else
|
46
|
+
puts "FATAL: Your CRYPTIC_RESOLVER_CONFIG is NOT a file!"
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
else
|
51
|
+
# if user doesn't specify, we use the hard-coded defaults
|
52
|
+
CR_EXTRA_LIBRARY = nil
|
53
|
+
CR_DEFAULT_DICTS = $CR_DEFAULT_DICTS
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# This is used to display what you are pulling when adding dicts
|
58
|
+
CR_DEFAULT_DICTS_USER_AND_NAMES = CR_DEFAULT_DICTS.map do |e|
|
59
|
+
user, repo = e.split('/').last(2)
|
60
|
+
repo = repo.split('.').first
|
61
|
+
user + '/' + repo
|
62
|
+
end
|
63
|
+
|
64
|
+
# Same with the pulled repo dirs' names in CR_DEFAULT_LIBRARY
|
65
|
+
CR_DEFAULT_DICTS_NAMES = CR_DEFAULT_DICTS.map do |e|
|
66
|
+
e.split('/').last.split('.').first
|
67
|
+
end
|
29
68
|
|
30
69
|
|
31
70
|
####################
|
@@ -47,31 +86,31 @@ def cyan(str) "\e[36m#{str}\e[0m" end
|
|
47
86
|
####################
|
48
87
|
|
49
88
|
def is_there_any_dict?
|
50
|
-
unless Dir.exist?
|
51
|
-
Dir.mkdir
|
89
|
+
unless Dir.exist? CR_DEFAULT_LIBRARY
|
90
|
+
Dir.mkdir CR_DEFAULT_LIBRARY
|
52
91
|
end
|
53
92
|
|
54
|
-
!Dir.empty?
|
93
|
+
!Dir.empty? CR_DEFAULT_LIBRARY
|
55
94
|
end
|
56
95
|
|
57
96
|
|
58
97
|
def add_default_dicts_if_none_exists
|
59
98
|
unless is_there_any_dict?
|
60
|
-
puts "cr: Adding default
|
99
|
+
puts "cr: Adding default dicts..."
|
61
100
|
|
62
101
|
begin
|
63
102
|
if RUBY_PLATFORM.include? "mingw"
|
64
103
|
# Windows doesn't have fork
|
65
|
-
|
66
|
-
puts "cr: Pulling
|
67
|
-
`git -C #{
|
104
|
+
CR_DEFAULT_DICTS_USER_AND_NAMES.each_with_index do |name, i|
|
105
|
+
puts "cr: Pulling #{name}..."
|
106
|
+
`git -C #{CR_DEFAULT_LIBRARY} clone #{CR_DEFAULT_DICTS[i]} -q`
|
68
107
|
end
|
69
108
|
else
|
70
|
-
# *nix
|
71
|
-
|
109
|
+
# *nix-like
|
110
|
+
CR_DEFAULT_DICTS_USER_AND_NAMES.each_with_index do |name, i|
|
72
111
|
fork do
|
73
|
-
puts "cr: Pulling
|
74
|
-
`git -C #{
|
112
|
+
puts "cr: Pulling #{name}..."
|
113
|
+
`git -C #{CR_DEFAULT_LIBRARY} clone #{CR_DEFAULT_DICTS[i]} -q`
|
75
114
|
end
|
76
115
|
end
|
77
116
|
Process.waitall
|
@@ -85,7 +124,7 @@ def add_default_dicts_if_none_exists
|
|
85
124
|
puts "cr: Add done"
|
86
125
|
word_count(p: false)
|
87
126
|
puts
|
88
|
-
puts "#{$
|
127
|
+
puts "#{$TwoLibWordCount} words added"
|
89
128
|
|
90
129
|
# Really added
|
91
130
|
return true
|
@@ -95,26 +134,27 @@ def add_default_dicts_if_none_exists
|
|
95
134
|
end
|
96
135
|
|
97
136
|
|
137
|
+
# Notice that we only update the Default library, not Extra library
|
98
138
|
def update_dicts()
|
99
139
|
return if add_default_dicts_if_none_exists
|
100
140
|
|
101
141
|
word_count(p: false)
|
102
|
-
old_wc =
|
142
|
+
old_wc = $DefaultLibWordCount
|
103
143
|
|
104
|
-
puts "cr: Updating all
|
144
|
+
puts "cr: Updating all dicts in Default library..."
|
105
145
|
|
106
146
|
begin
|
107
|
-
Dir.chdir
|
147
|
+
Dir.chdir CR_DEFAULT_LIBRARY do
|
108
148
|
|
109
149
|
if RUBY_PLATFORM.include? "mingw"
|
110
150
|
# Windows doesn't have fork
|
111
|
-
Dir.children(
|
151
|
+
Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
|
112
152
|
puts "cr: Wait to update #{dict}..."
|
113
153
|
`git -C ./#{dict} pull -q`
|
114
154
|
end
|
115
155
|
else
|
116
156
|
# *nix
|
117
|
-
Dir.children(
|
157
|
+
Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
|
118
158
|
fork do
|
119
159
|
puts "cr: Wait to update #{dict}..."
|
120
160
|
`git -C ./#{dict} pull -q`
|
@@ -130,21 +170,17 @@ def update_dicts()
|
|
130
170
|
exit 1
|
131
171
|
end
|
132
172
|
|
133
|
-
|
134
173
|
puts "cr: Update done"
|
135
174
|
|
136
175
|
# clear
|
137
|
-
$
|
176
|
+
$DefaultLibWordCount = 0
|
138
177
|
# recount
|
139
178
|
word_count(p: false)
|
140
|
-
|
141
|
-
|
142
|
-
new_wc.each_with_index do
|
143
|
-
diff[_2] = _1 - old_wc[_2]
|
144
|
-
end
|
179
|
+
|
180
|
+
new_wc = $DefaultLibWordCount
|
145
181
|
|
146
182
|
puts
|
147
|
-
puts "#{
|
183
|
+
puts "#{new_wc - old_wc} words added in Default library"
|
148
184
|
|
149
185
|
end
|
150
186
|
|
@@ -156,16 +192,20 @@ def add_dict(repo)
|
|
156
192
|
end
|
157
193
|
|
158
194
|
# Ensure the cr home dir exists
|
159
|
-
FileUtils.mkdir_p(
|
195
|
+
FileUtils.mkdir_p(CR_DEFAULT_LIBRARY)
|
160
196
|
|
161
197
|
# Simplify adding dictionary
|
162
198
|
if !repo.start_with?("https://") and !repo.start_with?("git@")
|
163
|
-
|
199
|
+
if repo.include?('/')
|
200
|
+
repo = "https://github.com/#{repo}.git"
|
201
|
+
else
|
202
|
+
repo = "https://github.com/cryptic-resolver/cryptic_#{repo}.git"
|
203
|
+
end
|
164
204
|
end
|
165
205
|
|
166
206
|
begin
|
167
207
|
puts "cr: Adding new dictionary..."
|
168
|
-
`git -C #{
|
208
|
+
`git -C #{CR_DEFAULT_LIBRARY} clone #{repo} -q`
|
169
209
|
rescue Interrupt
|
170
210
|
puts "cr: Cancel add dict"
|
171
211
|
exit 1
|
@@ -177,7 +217,7 @@ def add_dict(repo)
|
|
177
217
|
dict = repo.split('/')[-1].delete_suffix('.git')
|
178
218
|
count_dict_words(dict)
|
179
219
|
puts
|
180
|
-
puts "#$
|
220
|
+
puts "#$TwoLibWordCount words added"
|
181
221
|
|
182
222
|
end
|
183
223
|
|
@@ -187,7 +227,7 @@ def del_dict(repo)
|
|
187
227
|
puts bold(red("cr: Need an argument!"))
|
188
228
|
exit -1
|
189
229
|
end
|
190
|
-
Dir.chdir
|
230
|
+
Dir.chdir CR_DEFAULT_LIBRARY do
|
191
231
|
begin
|
192
232
|
# Dir.rmdir repo # Can't rm a filled dir
|
193
233
|
# FileUtils.rmdir repo # Can't rm a filled dir
|
@@ -195,14 +235,14 @@ def del_dict(repo)
|
|
195
235
|
puts "cr: Delete dictionary #{bold(green(repo))} done"
|
196
236
|
rescue Exception => e
|
197
237
|
puts bold(red("cr: #{e}"))
|
198
|
-
|
238
|
+
list_dicts
|
199
239
|
end
|
200
240
|
end
|
201
241
|
end
|
202
242
|
|
203
243
|
|
204
|
-
def load_sheet(dict, sheet_name)
|
205
|
-
file =
|
244
|
+
def load_sheet(library, dict, sheet_name)
|
245
|
+
file = library + "/#{dict}/#{sheet_name}.toml"
|
206
246
|
|
207
247
|
if File.exist? file
|
208
248
|
return Tomlrb.load_file file # gem 'tomlrb'
|
@@ -252,7 +292,7 @@ def pp_info(info)
|
|
252
292
|
puts
|
253
293
|
end
|
254
294
|
|
255
|
-
# Print default cryptic_
|
295
|
+
# Print default cryptic_ dicts
|
256
296
|
def pp_dict(dict)
|
257
297
|
puts green("From: #{dict}")
|
258
298
|
end
|
@@ -280,7 +320,7 @@ end
|
|
280
320
|
# same = "XDG downloader <=>xdg.Download" # this is correct
|
281
321
|
#
|
282
322
|
#
|
283
|
-
def pp_same_info(dict, word, cache_content, same_key, own_name)
|
323
|
+
def pp_same_info(library, dict, word, cache_content, same_key, own_name)
|
284
324
|
|
285
325
|
# If it's a synonym for anther word,
|
286
326
|
# we should lookup into this dict again, but maybe with a different file
|
@@ -337,7 +377,7 @@ def pp_same_info(dict, word, cache_content, same_key, own_name)
|
|
337
377
|
# No need to load another dictionary if match
|
338
378
|
sheet_content = cache_content
|
339
379
|
else
|
340
|
-
sheet_content = load_sheet(dict, same.chr.downcase)
|
380
|
+
sheet_content = load_sheet(library, dict, same.chr.downcase)
|
341
381
|
end
|
342
382
|
|
343
383
|
if category.nil?
|
@@ -354,7 +394,7 @@ def pp_same_info(dict, word, cache_content, same_key, own_name)
|
|
354
394
|
# double or more jumps
|
355
395
|
elsif same_key = info['same']
|
356
396
|
own_name = info['name']
|
357
|
-
return pp_same_info(dict, same, cache_content, same_key, own_name)
|
397
|
+
return pp_same_info(library, dict, same, cache_content, same_key, own_name)
|
358
398
|
else
|
359
399
|
pp_info(info)
|
360
400
|
return true
|
@@ -376,8 +416,8 @@ end
|
|
376
416
|
# 2.2 with category specifier
|
377
417
|
# [abcd.tYPe]
|
378
418
|
#
|
379
|
-
def lookup(dict, file, word)
|
380
|
-
sheet_content = load_sheet(dict, file)
|
419
|
+
def lookup(library, dict, file, word)
|
420
|
+
sheet_content = load_sheet(library, dict, file)
|
381
421
|
return false if sheet_content.nil?
|
382
422
|
|
383
423
|
info = sheet_content[word]
|
@@ -392,7 +432,6 @@ def lookup(dict, file, word)
|
|
392
432
|
end
|
393
433
|
|
394
434
|
|
395
|
-
|
396
435
|
# Word with no category specifier
|
397
436
|
# We call this meaning as type 1
|
398
437
|
type_1_exist_flag = false
|
@@ -404,7 +443,7 @@ def lookup(dict, file, word)
|
|
404
443
|
if same_key = info['same']
|
405
444
|
own_name = info['name']
|
406
445
|
pp_dict(dict)
|
407
|
-
pp_same_info(dict, word, sheet_content, same_key, own_name)
|
446
|
+
pp_same_info(library, dict, word, sheet_content, same_key, own_name)
|
408
447
|
# It's also a type 1
|
409
448
|
type_1_exist_flag = true
|
410
449
|
is_jump = true
|
@@ -441,7 +480,7 @@ def lookup(dict, file, word)
|
|
441
480
|
info0 = sheet_content[word][meaning]
|
442
481
|
if same_key = info0['same']
|
443
482
|
own_name = info0['name']
|
444
|
-
pp_same_info(dict, word, sheet_content, same_key, own_name)
|
483
|
+
pp_same_info(library, dict, word, sheet_content, same_key, own_name)
|
445
484
|
else
|
446
485
|
pp_info(info0)
|
447
486
|
end
|
@@ -460,15 +499,16 @@ end
|
|
460
499
|
|
461
500
|
#
|
462
501
|
# The main procedure of `cr`
|
463
|
-
#
|
464
|
-
#
|
502
|
+
#
|
503
|
+
# 1. Search the default library first
|
504
|
+
# 2. Search the extra library if it does exist
|
465
505
|
#
|
466
506
|
# The `search` is done via the `lookup` function. It will print
|
467
507
|
# the info while finding. If `lookup` always return false then
|
468
|
-
# means lacking of this word in our
|
508
|
+
# means lacking of this word in our dicts. So a welcomed
|
469
509
|
# contribution is printed on the screen.
|
470
510
|
#
|
471
|
-
def
|
511
|
+
def resolve_word(word)
|
472
512
|
|
473
513
|
add_default_dicts_if_none_exists
|
474
514
|
|
@@ -479,21 +519,22 @@ def solve_word(word)
|
|
479
519
|
when '0'..'9'
|
480
520
|
index = '0123456789'
|
481
521
|
end
|
482
|
-
|
483
|
-
# Default's first should be 1st to consider
|
484
|
-
first_dict = "cryptic_" + CRYPTIC_DEFAULT_DICTS.keys[0].to_s # When Ruby3, We can use DICTS.key(0)
|
485
522
|
|
486
|
-
# cache lookup results
|
523
|
+
# cache lookup's results
|
487
524
|
results = []
|
488
|
-
|
489
|
-
#
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
525
|
+
|
526
|
+
# First consider the default library
|
527
|
+
default = Dir.children(CR_DEFAULT_LIBRARY)
|
528
|
+
default.each do |dict|
|
529
|
+
results << lookup(CR_DEFAULT_LIBRARY,dict,index,word)
|
530
|
+
end
|
531
|
+
|
532
|
+
# Then is the extra library
|
533
|
+
if CR_EXTRA_LIBRARY
|
534
|
+
extra = Dir.children(CR_EXTRA_LIBRARY)
|
535
|
+
extra.each do |dict|
|
536
|
+
results << lookup(CR_EXTRA_LIBRARY,dict,index,word)
|
537
|
+
end
|
497
538
|
end
|
498
539
|
|
499
540
|
unless results.include? true
|
@@ -519,7 +560,7 @@ end
|
|
519
560
|
|
520
561
|
|
521
562
|
#
|
522
|
-
#
|
563
|
+
# This `search_word` routine is quite like `resolve_word`
|
523
564
|
# Notice:
|
524
565
|
# We handle two cases
|
525
566
|
#
|
@@ -546,10 +587,10 @@ def search_word(pattern)
|
|
546
587
|
found = false
|
547
588
|
|
548
589
|
#
|
549
|
-
# Try to match every word in all
|
590
|
+
# Try to match every word in all dicts
|
550
591
|
#
|
551
|
-
Dir.children(
|
552
|
-
sheets = Dir.children(File.join(
|
592
|
+
Dir.children(CR_DEFAULT_LIBRARY).each do |dict|
|
593
|
+
sheets = Dir.children(File.join(CR_DEFAULT_LIBRARY, dict)).select do
|
553
594
|
_1.end_with?('.toml')
|
554
595
|
end
|
555
596
|
|
@@ -585,19 +626,21 @@ end
|
|
585
626
|
|
586
627
|
def help
|
587
628
|
word_count(p: false)
|
588
|
-
user_words = $WordCount - $DefaultWordCount
|
589
629
|
puts <<-HELP
|
590
|
-
cr: Cryptic Resolver v#{CR_GEM_VERSION} (#{$
|
630
|
+
cr: Cryptic Resolver v#{CR_GEM_VERSION} (#{$TwoLibWordCount} words: Default lib/#{$DefaultLibWordCount} && Extra lib/#{$ExtraLibWordCount})
|
591
631
|
|
592
|
-
|
632
|
+
Usage:
|
593
633
|
|
594
|
-
cr emacs => Edit macros:
|
634
|
+
cr emacs => Edit macros: A feature-rich editor
|
595
635
|
cr -c => Print word count
|
596
|
-
cr -l => List local
|
597
|
-
cr -u => Update all
|
598
|
-
|
599
|
-
cr -a
|
600
|
-
cr -
|
636
|
+
cr -l => List local dicts and official dicts
|
637
|
+
cr -u => Update all dicts in default library
|
638
|
+
|
639
|
+
cr -a repo.git => Add a new dict
|
640
|
+
cr -a user/repo => Add a new dict from Github
|
641
|
+
cr -a reponame => Add an official dict from Github
|
642
|
+
|
643
|
+
cr -d cryptic_xx => Delete a dict
|
601
644
|
cr -s pattern => Search words matched with pattern
|
602
645
|
cr -v => Print version
|
603
646
|
cr -h => Print this help
|
@@ -614,91 +657,98 @@ def print_version
|
|
614
657
|
end
|
615
658
|
|
616
659
|
|
617
|
-
|
618
|
-
|
619
|
-
|
660
|
+
#
|
661
|
+
# 1. List Default library's dicts
|
662
|
+
# 2. List Extra library's dicts
|
663
|
+
# 3. List official dicts
|
664
|
+
#
|
665
|
+
def list_dicts
|
666
|
+
Dir.chdir CR_DEFAULT_LIBRARY do
|
667
|
+
puts blue("=> Default library: #{CR_DEFAULT_LIBRARY}")
|
668
|
+
Dir.children(CR_DEFAULT_LIBRARY).each_with_index do |dict,i|
|
620
669
|
puts "#{blue(i+1)}. #{bold(green(dict))}"
|
621
670
|
end
|
622
671
|
end
|
672
|
+
|
673
|
+
if CR_EXTRA_LIBRARY
|
674
|
+
puts
|
675
|
+
Dir.chdir CR_EXTRA_LIBRARY do
|
676
|
+
puts blue("=> Extra library: #{CR_EXTRA_LIBRARY}")
|
677
|
+
Dir.children(CR_EXTRA_LIBRARY).each_with_index do |dict,i|
|
678
|
+
puts "#{blue(i+1)}. #{bold(green(dict))}"
|
679
|
+
end
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
puts
|
684
|
+
puts blue("=> Official dicts: (Add it by 'cr -a xxx')")
|
685
|
+
puts CR_OFFICIAL_DICTS
|
686
|
+
|
623
687
|
end
|
624
688
|
|
625
689
|
|
626
|
-
#
|
627
|
-
$
|
628
|
-
# Default
|
629
|
-
$
|
690
|
+
# Two libraries word count (Default library + Extra library)
|
691
|
+
$TwoLibWordCount = 0
|
692
|
+
# Default library word count
|
693
|
+
$DefaultLibWordCount = 0
|
694
|
+
# Extra library word count
|
695
|
+
$ExtraLibWordCount = 0
|
630
696
|
|
631
|
-
def count_dict_words(dict)
|
697
|
+
def count_dict_words(library, dict)
|
632
698
|
|
633
|
-
dict_dir =
|
699
|
+
dict_dir = library + "/#{dict}"
|
634
700
|
|
635
701
|
wc = 0
|
636
702
|
|
637
703
|
Dir.children(dict_dir).each do |entry|
|
638
704
|
next unless entry.end_with?('.toml')
|
639
|
-
sheet_content = load_sheet(dict, entry.delete_suffix('.toml'))
|
705
|
+
sheet_content = load_sheet(library, dict, entry.delete_suffix('.toml'))
|
640
706
|
count = sheet_content.keys.count
|
641
|
-
|
642
|
-
# puts "#{entry}: #{count}"
|
707
|
+
|
643
708
|
wc = wc + count
|
644
709
|
end
|
645
|
-
|
646
|
-
$WordCount += wc
|
647
|
-
|
648
710
|
return wc
|
649
|
-
|
650
711
|
end
|
651
712
|
|
652
713
|
|
653
714
|
def word_count(p:)
|
654
|
-
|
655
715
|
# Always check before Dir.children (this method creates dir if not exists)
|
656
716
|
is_there_any_dict?
|
657
717
|
|
658
|
-
|
659
|
-
locals = []
|
660
|
-
Dir.children(CRYPTIC_RESOLVER_HOME).each do |dict|
|
661
|
-
locals << dict
|
662
|
-
end
|
663
|
-
|
664
|
-
# pre-defined default
|
665
|
-
defaults = CRYPTIC_DEFAULT_DICTS.keys.map do |s|
|
666
|
-
"cryptic_#{s}"
|
667
|
-
end
|
668
|
-
|
669
|
-
# user may delete some default dicts
|
670
|
-
defaults &= locals
|
718
|
+
default_lib = Dir.children(CR_DEFAULT_LIBRARY)
|
671
719
|
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
720
|
+
# Count default library
|
721
|
+
unless default_lib.empty?
|
722
|
+
puts(bold(green("Default library: "))) if p
|
723
|
+
default_lib.each do |s|
|
724
|
+
wc = count_dict_words(CR_DEFAULT_LIBRARY,s)
|
725
|
+
$DefaultLibWordCount += wc
|
677
726
|
# With color, ljust not works, so we disable color
|
678
727
|
puts(" #{s.ljust(17)}: #{wc}") if p
|
679
728
|
end
|
680
729
|
end
|
681
730
|
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
731
|
+
|
732
|
+
if CR_EXTRA_LIBRARY
|
733
|
+
extra_lib = Dir.children(CR_EXTRA_LIBRARY)
|
734
|
+
# Count extra library
|
735
|
+
unless extra_lib.empty?
|
736
|
+
wc = 0
|
737
|
+
puts(bold(blue("\nExtra library:"))) if p
|
738
|
+
extra_lib.each do |s|
|
739
|
+
wc = count_dict_words(CR_EXTRA_LIBRARY,s)
|
740
|
+
$ExtraLibWordCount += wc
|
741
|
+
puts(" #{s.ljust(17)}: #{wc}") if p
|
742
|
+
end
|
692
743
|
end
|
693
|
-
|
694
|
-
user_words = $WordCount - $DefaultWordCount
|
695
744
|
end
|
745
|
+
$TwoLibWordCount = $DefaultLibWordCount + $ExtraLibWordCount
|
696
746
|
|
697
747
|
if p
|
698
748
|
puts
|
699
|
-
puts "#{$
|
700
|
-
puts "#{
|
701
|
-
puts "#{$
|
749
|
+
puts "#{$DefaultLibWordCount.to_s.rjust(4)} words in Default library"
|
750
|
+
puts "#{$ExtraLibWordCount.to_s.rjust(4) } words in Extra library"
|
751
|
+
puts "#{$TwoLibWordCount.to_s.rjust(4) } words altogether"
|
702
752
|
end
|
703
753
|
end
|
704
754
|
|
@@ -712,7 +762,7 @@ case arg
|
|
712
762
|
when nil then help
|
713
763
|
when '-v' then print_version
|
714
764
|
when '-h' then help
|
715
|
-
when '-l' then
|
765
|
+
when '-l' then list_dicts
|
716
766
|
when '-c' then word_count(p: true)
|
717
767
|
when '-u' then update_dicts
|
718
768
|
when '-s' then search_word ARGV.shift
|
@@ -721,6 +771,6 @@ when '-d' then del_dict ARGV.shift
|
|
721
771
|
when '--help'
|
722
772
|
help
|
723
773
|
else
|
724
|
-
|
774
|
+
resolve_word arg
|
725
775
|
end
|
726
776
|
|
data/lib/cr.rb
CHANGED
@@ -2,12 +2,27 @@
|
|
2
2
|
# File : cr.rb
|
3
3
|
# Authors : ccmywish <ccmywish@qq.com>
|
4
4
|
# Created on : <2022-04-15>
|
5
|
-
# Last modified : <2022-
|
5
|
+
# Last modified : <2022-11-27>
|
6
6
|
#
|
7
7
|
# cr:
|
8
8
|
#
|
9
|
-
# This file is
|
9
|
+
# This file is the lib of `cr.rb``
|
10
10
|
#
|
11
11
|
# ------------------------------------------------------
|
12
12
|
|
13
|
-
CR_GEM_VERSION = "
|
13
|
+
CR_GEM_VERSION = "4.0.0.alpha.2"
|
14
|
+
|
15
|
+
|
16
|
+
CR_OFFICIAL_DICTS = <<-EOF
|
17
|
+
Default:
|
18
|
+
common computer windows
|
19
|
+
linux electronics
|
20
|
+
|
21
|
+
Field:
|
22
|
+
economy medicine math
|
23
|
+
mechanical science
|
24
|
+
|
25
|
+
Specific:
|
26
|
+
dos x86 signal
|
27
|
+
|
28
|
+
EOF
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cr.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ccmywish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|
@@ -66,9 +66,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- - "
|
69
|
+
- - ">"
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: 1.3.1
|
72
72
|
requirements: []
|
73
73
|
rubygems_version: 3.3.7
|
74
74
|
signing_key:
|