cr.rb 4.0.0.alpha.2 → 4.0.0.alpha.4
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/bin/cr +50 -24
- data/lib/cr.rb +1 -1
- 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: 5c4ff483935b5b1015fb9d412056e041e81fd3fa7b94c47c8b5de8be517f8740
         | 
| 4 | 
            +
              data.tar.gz: 2a207377d5dc6bf441d3940d5c142965d944ba6f05de3de7053800bd7b59fb29
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ddd0207e0248b713e3304f6c6781b2f186a7ba3bdc02a4a4823e9def133cfd2209d8295987217d1df92733811efc0a2beb09daa904d85305aee97a9955dda146
         | 
| 7 | 
            +
              data.tar.gz: 51a67072c4631628d6a6f840e819665c2e26309cc62be9d060cc658b5b8eb19b512557c92d8840f56a32e3777211d6c114870a15208403b647bb7147ec4ca418
         | 
    
        data/bin/cr
    CHANGED
    
    | @@ -54,6 +54,15 @@ else | |
| 54 54 | 
             
            end
         | 
| 55 55 |  | 
| 56 56 |  | 
| 57 | 
            +
            # Prevent runtime error
         | 
| 58 | 
            +
            if not CR_EXTRA_LIBRARY.nil?
         | 
| 59 | 
            +
              if ! test('d', CR_EXTRA_LIBRARY)
         | 
| 60 | 
            +
                puts "FATAL: Your CRYPTIC_RESOLVER_CONFIG's option 'EXTRA_LIBRARY' is NOT a legal directory!"
         | 
| 61 | 
            +
                exit 1
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
            end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
             | 
| 57 66 | 
             
            # This is used to display what you are pulling when adding dicts
         | 
| 58 67 | 
             
            CR_DEFAULT_DICTS_USER_AND_NAMES = CR_DEFAULT_DICTS.map do |e|
         | 
| 59 68 | 
             
              user, repo = e.split('/').last(2)
         | 
| @@ -313,11 +322,11 @@ end | |
| 313 322 | 
             
            #                 # category
         | 
| 314 323 | 
             
            #
         | 
| 315 324 | 
             
            #   [blah]
         | 
| 316 | 
            -
            #   same = "XDG downloader  | 
| 325 | 
            +
            #   same = "XDG downloader =>xdg.Download" # this is correct
         | 
| 317 326 | 
             
            #
         | 
| 318 327 | 
             
            #   [blah]
         | 
| 319 328 | 
             
            #   name = "BlaH" # You may want to display a better name first
         | 
| 320 | 
            -
            #   same = "XDG downloader  | 
| 329 | 
            +
            #   same = "XDG downloader =>xdg.Download" # this is correct
         | 
| 321 330 | 
             
            #
         | 
| 322 331 | 
             
            #
         | 
| 323 332 | 
             
            def pp_same_info(library, dict, word, cache_content, same_key, own_name)
         | 
| @@ -339,13 +348,13 @@ def pp_same_info(library, dict, word, cache_content, same_key, own_name) | |
| 339 348 | 
             
              # 
         | 
| 340 349 | 
             
              # 'jump to' will output to user, so this is important not only inside our sheet.
         | 
| 341 350 | 
             
              #   
         | 
| 342 | 
            -
              #     same = "XDM downloader | 
| 351 | 
            +
              #     same = "XDM downloader=>xdm.Download"
         | 
| 343 352 | 
             
              #
         | 
| 344 | 
            -
              # We split 'same' key into two parts via spaceship symbol  | 
| 353 | 
            +
              # We split 'same' key into two parts via spaceship symbol `=>`, first part will
         | 
| 345 354 | 
             
              # output to user, the second part is for internal jump.
         | 
| 346 355 | 
             
              #
         | 
| 347 356 |  | 
| 348 | 
            -
              jump_to, same = same_key.split(" | 
| 357 | 
            +
              jump_to, same = same_key.split("=>")
         | 
| 349 358 | 
             
              same =  jump_to if same.nil?
         | 
| 350 359 |  | 
| 351 360 | 
             
              unless own_name
         | 
| @@ -517,7 +526,7 @@ def resolve_word(word) | |
| 517 526 | 
             
              index = word.chr
         | 
| 518 527 | 
             
              case index 
         | 
| 519 528 | 
             
              when '0'..'9' 
         | 
| 520 | 
            -
                index = ' | 
| 529 | 
            +
                index = '0-9'
         | 
| 521 530 | 
             
              end
         | 
| 522 531 |  | 
| 523 532 | 
             
              # cache lookup's results
         | 
| @@ -543,9 +552,12 @@ cr: Not found anything. | |
| 543 552 |  | 
| 544 553 | 
             
            You may 
         | 
| 545 554 | 
             
              1. Use `cr -u` to update all dicts 
         | 
| 546 | 
            -
             | 
| 547 | 
            -
              
         | 
| 548 | 
            -
             | 
| 555 | 
            +
             | 
| 556 | 
            +
              2. Use 
         | 
| 557 | 
            +
                  
         | 
| 558 | 
            +
                `cr -l`  to list available official dicts
         | 
| 559 | 
            +
                
         | 
| 560 | 
            +
                `cr -a repo`  to add some dicts
         | 
| 549 561 |  | 
| 550 562 | 
             
              3. Contribute to theses dicts
         | 
| 551 563 |  | 
| @@ -558,18 +570,35 @@ NotFound | |
| 558 570 | 
             
            end
         | 
| 559 571 |  | 
| 560 572 |  | 
| 573 | 
            +
            #
         | 
| 574 | 
            +
            # Delegate to `search_word_internal`
         | 
| 575 | 
            +
            #
         | 
| 576 | 
            +
            def search_word(pattern)
         | 
| 577 | 
            +
              found_or_not1 = false
         | 
| 578 | 
            +
              found_or_not2 = false
         | 
| 579 | 
            +
             | 
| 580 | 
            +
              found_or_not1 = search_word_internal(pattern, CR_DEFAULT_LIBRARY)
         | 
| 581 | 
            +
              if CR_EXTRA_LIBRARY
         | 
| 582 | 
            +
                found_or_not2 = search_word_internal(pattern, CR_EXTRA_LIBRARY)
         | 
| 583 | 
            +
              end
         | 
| 584 | 
            +
             | 
| 585 | 
            +
              if (found_or_not1 == false) && (found_or_not2 == false)
         | 
| 586 | 
            +
                puts red("cr: No words match with #{pattern.inspect}")
         | 
| 587 | 
            +
                puts
         | 
| 588 | 
            +
              end
         | 
| 589 | 
            +
            end
         | 
| 561 590 |  | 
| 562 591 | 
             
            #
         | 
| 563 | 
            -
            # This ` | 
| 592 | 
            +
            # This `search_word_internal` routine is quite like `resolve_word`
         | 
| 564 593 | 
             
            # Notice:
         | 
| 565 594 | 
             
            #   We handle two cases
         | 
| 566 595 | 
             
            #   
         | 
| 567 596 | 
             
            #   1. the 'pattern' is the regexp itself
         | 
| 568 | 
            -
            #   2. the 'pattern' is like '/ | 
| 597 | 
            +
            #   2. the 'pattern' is like '/blah/'
         | 
| 569 598 | 
             
            #                       
         | 
| 570 599 | 
             
            #  The second is what Ruby and Perl users like to do, handle it!
         | 
| 571 600 | 
             
            #
         | 
| 572 | 
            -
            def  | 
| 601 | 
            +
            def search_word_internal(pattern, library)
         | 
| 573 602 |  | 
| 574 603 | 
             
              if pattern.nil? 
         | 
| 575 604 | 
             
                puts bold(red("cr: Need an argument!"))
         | 
| @@ -584,24 +613,24 @@ def search_word(pattern) | |
| 584 613 | 
             
                regexp = %r[#{pattern}]
         | 
| 585 614 | 
             
              end
         | 
| 586 615 |  | 
| 587 | 
            -
               | 
| 616 | 
            +
              found_or_not = false
         | 
| 588 617 |  | 
| 589 618 | 
             
              #
         | 
| 590 619 | 
             
              # Try to match every word in all dicts
         | 
| 591 620 | 
             
              #
         | 
| 592 | 
            -
              Dir.children( | 
| 593 | 
            -
                sheets = Dir.children(File.join( | 
| 621 | 
            +
              Dir.children(library).each do |dict|
         | 
| 622 | 
            +
                sheets = Dir.children(File.join(library, dict)).select do
         | 
| 594 623 | 
             
                  _1.end_with?('.toml')
         | 
| 595 624 | 
             
                end
         | 
| 596 625 |  | 
| 597 626 | 
             
                similar_words_in_a_dict = []
         | 
| 598 627 |  | 
| 599 628 | 
             
                sheets.each do |sheet|
         | 
| 600 | 
            -
                  sheet_content = load_sheet(dict, File.basename(sheet,'.toml'))
         | 
| 629 | 
            +
                  sheet_content = load_sheet(library, dict, File.basename(sheet,'.toml'))
         | 
| 601 630 |  | 
| 602 631 | 
             
                  sheet_content.keys.each do 
         | 
| 603 632 | 
             
                    if _1 =~ regexp
         | 
| 604 | 
            -
                       | 
| 633 | 
            +
                      found_or_not = true
         | 
| 605 634 | 
             
                      similar_words_in_a_dict << _1
         | 
| 606 635 | 
             
                    end
         | 
| 607 636 | 
             
                  end
         | 
| @@ -617,10 +646,7 @@ def search_word(pattern) | |
| 617 646 | 
             
                  puts 
         | 
| 618 647 | 
             
                end
         | 
| 619 648 | 
             
              end
         | 
| 620 | 
            -
               | 
| 621 | 
            -
                puts red("cr: No words match with #{regexp.inspect}")
         | 
| 622 | 
            -
                puts
         | 
| 623 | 
            -
              end
         | 
| 649 | 
            +
              return found_or_not
         | 
| 624 650 | 
             
            end
         | 
| 625 651 |  | 
| 626 652 |  | 
| @@ -634,11 +660,11 @@ Usage: | |
| 634 660 | 
             
              cr emacs          => Edit macros: A feature-rich editor
         | 
| 635 661 | 
             
              cr -c             => Print word count
         | 
| 636 662 | 
             
              cr -l             => List local dicts and official dicts
         | 
| 637 | 
            -
              cr -u             => Update all dicts in  | 
| 663 | 
            +
              cr -u             => Update all dicts in Default library
         | 
| 638 664 |  | 
| 639 665 | 
             
              cr -a repo.git    => Add a new dict
         | 
| 640 666 | 
             
              cr -a user/repo   => Add a new dict from Github
         | 
| 641 | 
            -
              cr -a   | 
| 667 | 
            +
              cr -a  repo       => Add an official dict from Github
         | 
| 642 668 |  | 
| 643 669 | 
             
              cr -d cryptic_xx  => Delete a dict
         | 
| 644 670 | 
             
              cr -s pattern     => Search words matched with pattern
         | 
| @@ -728,7 +754,7 @@ def word_count(p:) | |
| 728 754 | 
             
                end
         | 
| 729 755 | 
             
              end
         | 
| 730 756 |  | 
| 731 | 
            -
             | 
| 757 | 
            +
             | 
| 732 758 | 
             
              if CR_EXTRA_LIBRARY
         | 
| 733 759 | 
             
                extra_lib = Dir.children(CR_EXTRA_LIBRARY)
         | 
| 734 760 | 
             
                # Count extra library
         | 
    
        data/lib/cr.rb
    CHANGED