yap-rawline 0.3.1 → 0.3.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/lib/rawline/completer.rb +12 -1
 - data/lib/rawline/editor.rb +39 -2
 - data/lib/rawline/version.rb +1 -1
 - metadata +15 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e7e26721726b5b17c08f75808f5ecec3973f372d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0447b1df3bb95f8af568416037514e16f4ca78c0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 666f67533fc55e170cb5831c96fb11160dd7fd0ea80b196ab385f37f2fc382c386b61a213a01e8bb20bee03a5c0a7e08b8e3697ce1cb6f7a2bb29dc94ea9b152
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 21a383d655e8d302133603fa727a6ebf7f0580f66376a1aa379bcb0404bfec147db52aa4e45da87bdace60f2ec9032c6d298f9144fb31e18d380d18c7a5f9e67
         
     | 
    
        data/lib/rawline/completer.rb
    CHANGED
    
    | 
         @@ -1,12 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module RawLine
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
              class Completer
         
     | 
| 
       4 
     | 
    
         
            -
                def initialize(char:, line:, completion:, completion_found:, completion_not_found:, done:, keys:)
         
     | 
| 
      
 4 
     | 
    
         
            +
                def initialize(char:, line:, completion:, completion_found:, completion_not_found:, completion_selected:, done:, keys:)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  @completion_char = char
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @line = line
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @completion_proc = completion
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @completion_found_proc = completion_found
         
     | 
| 
       9 
9 
     | 
    
         
             
                  @completion_not_found_proc = completion_not_found
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @completion_selected_proc = completion_selected
         
     | 
| 
       10 
11 
     | 
    
         
             
                  @done_proc = done
         
     | 
| 
       11 
12 
     | 
    
         
             
                  @keys = keys
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
         @@ -44,6 +45,7 @@ module RawLine 
     | 
|
| 
       44 
45 
     | 
    
         
             
                        .split(/\s+/)
         
     | 
| 
       45 
46 
     | 
    
         
             
                        .delete_if(&:empty?)
         
     | 
| 
       46 
47 
     | 
    
         
             
                      word_index = words.index(word)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      Treefell['editor'].puts "completer, looking for completions word=#{word.inspect} words=#{words.inspect} word_index=#{word_index}"
         
     | 
| 
       47 
49 
     | 
    
         
             
                      matches = @completion_proc.call(
         
     | 
| 
       48 
50 
     | 
    
         
             
                        word,
         
     | 
| 
       49 
51 
     | 
    
         
             
                        words,
         
     | 
| 
         @@ -55,6 +57,14 @@ module RawLine 
     | 
|
| 
       55 
57 
     | 
    
         
             
                    if matches.any?
         
     | 
| 
       56 
58 
     | 
    
         
             
                      @completion_matches.resize(matches.length)
         
     | 
| 
       57 
59 
     | 
    
         
             
                      matches.each { |w| @completion_matches << w }
         
     | 
| 
      
 60 
     | 
    
         
            +
                    end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                    if matches.length == 1
         
     | 
| 
      
 63 
     | 
    
         
            +
                      Treefell['editor'].puts "completer, exactly one possible completion found: #{matches.inspect}"
         
     | 
| 
      
 64 
     | 
    
         
            +
                      @completion_selected_proc.call(@completion_matches.first)
         
     | 
| 
      
 65 
     | 
    
         
            +
                      @done_proc.call
         
     | 
| 
      
 66 
     | 
    
         
            +
                    elsif matches.length > 1
         
     | 
| 
      
 67 
     | 
    
         
            +
                      Treefell['editor'].puts "completer, more than one possible completion found: #{matches.inspect}"
         
     | 
| 
       58 
68 
     | 
    
         | 
| 
       59 
69 
     | 
    
         
             
                      # Get first match
         
     | 
| 
       60 
70 
     | 
    
         
             
                      @completion_matches.back
         
     | 
| 
         @@ -64,6 +74,7 @@ module RawLine 
     | 
|
| 
       64 
74 
     | 
    
         
             
                      # a user would expect
         
     | 
| 
       65 
75 
     | 
    
         
             
                      @completion_found_proc.call(completion: match, possible_completions: @completion_matches.reverse)
         
     | 
| 
       66 
76 
     | 
    
         
             
                    else
         
     | 
| 
      
 77 
     | 
    
         
            +
                      Treefell['editor'].puts "completer, no possible completions found"
         
     | 
| 
       67 
78 
     | 
    
         
             
                      @completion_not_found_proc.call
         
     | 
| 
       68 
79 
     | 
    
         
             
                      @done_proc.call
         
     | 
| 
       69 
80 
     | 
    
         
             
                    end
         
     | 
    
        data/lib/rawline/editor.rb
    CHANGED
    
    | 
         @@ -152,6 +152,9 @@ module RawLine 
     | 
|
| 
       152 
152 
     | 
    
         
             
                attr_reader :keyboard_input_processors
         
     | 
| 
       153 
153 
     | 
    
         | 
| 
       154 
154 
     | 
    
         
             
                def env ; @env_stack.last ; end
         
     | 
| 
      
 155 
     | 
    
         
            +
                def new_env ; Environment.new ; end
         
     | 
| 
      
 156 
     | 
    
         
            +
                def push_env(env) ; @env_stack.push env ; end
         
     | 
| 
      
 157 
     | 
    
         
            +
                def pop_env(env) ; @env_stack.pop ; end
         
     | 
| 
       155 
158 
     | 
    
         | 
| 
       156 
159 
     | 
    
         
             
                def completion_class ; env.completion_class ; end
         
     | 
| 
       157 
160 
     | 
    
         
             
                def history ; env.history ; end
         
     | 
| 
         @@ -651,6 +654,9 @@ module RawLine 
     | 
|
| 
       651 
654 
     | 
    
         
             
                    completion_not_found: -> {
         
     | 
| 
       652 
655 
     | 
    
         
             
                      completion_not_found
         
     | 
| 
       653 
656 
     | 
    
         
             
                    },
         
     | 
| 
      
 657 
     | 
    
         
            +
                    completion_selected: -> (completion) {
         
     | 
| 
      
 658 
     | 
    
         
            +
                      completion_selected(completion)
         
     | 
| 
      
 659 
     | 
    
         
            +
                    },
         
     | 
| 
       654 
660 
     | 
    
         
             
                    done: -> (*leftover_bytes){
         
     | 
| 
       655 
661 
     | 
    
         
             
                      completion_done
         
     | 
| 
       656 
662 
     | 
    
         
             
                      leftover_bytes = leftover_bytes.flatten
         
     | 
| 
         @@ -667,43 +673,70 @@ module RawLine 
     | 
|
| 
       667 
673 
     | 
    
         
             
                end
         
     | 
| 
       668 
674 
     | 
    
         | 
| 
       669 
675 
     | 
    
         
             
                def completion_found(completion:, possible_completions:)
         
     | 
| 
      
 676 
     | 
    
         
            +
                  Treefell['editor'].puts "word-completion-found: #{completion.inspect} possible_completions: #{possible_completions.inspect}"
         
     | 
| 
       670 
677 
     | 
    
         
             
                  if @on_word_complete
         
     | 
| 
       671 
678 
     | 
    
         
             
                    word = @line.word[:text]
         
     | 
| 
       672 
679 
     | 
    
         
             
                    sub_word = @line.text[@line.word[:start]..@line.position-1] || ""
         
     | 
| 
       673 
680 
     | 
    
         
             
                    @on_word_complete.call(name: "word-completion", payload: { sub_word: sub_word, word: word, completion: completion, possible_completions: possible_completions })
         
     | 
| 
       674 
681 
     | 
    
         
             
                  end
         
     | 
| 
       675 
682 
     | 
    
         | 
| 
      
 683 
     | 
    
         
            +
                  completion_selected(completion)
         
     | 
| 
      
 684 
     | 
    
         
            +
                end
         
     | 
| 
      
 685 
     | 
    
         
            +
             
     | 
| 
      
 686 
     | 
    
         
            +
                def completion_selected(completion)
         
     | 
| 
      
 687 
     | 
    
         
            +
                  Treefell['editor'].puts "word-completion-selected #{completion}"
         
     | 
| 
       676 
688 
     | 
    
         
             
                  move_to_position @line.word[:end]
         
     | 
| 
       677 
689 
     | 
    
         
             
                  delete_n_characters(@line.word[:end] - @line.word[:start], true)
         
     | 
| 
       678 
690 
     | 
    
         
             
                  write completion.to_s
         
     | 
| 
      
 691 
     | 
    
         
            +
             
     | 
| 
      
 692 
     | 
    
         
            +
                  if @on_word_completion_selected
         
     | 
| 
      
 693 
     | 
    
         
            +
                    Treefell['editor'].puts "word-completion-selected callback called with #{completion}"
         
     | 
| 
      
 694 
     | 
    
         
            +
                    @on_word_completion_selected.call(name: "word-completion-selected", payload: { completion: completion })
         
     | 
| 
      
 695 
     | 
    
         
            +
                  end
         
     | 
| 
       679 
696 
     | 
    
         
             
                end
         
     | 
| 
       680 
697 
     | 
    
         | 
| 
       681 
698 
     | 
    
         
             
                def completion_not_found
         
     | 
| 
      
 699 
     | 
    
         
            +
                  Treefell['editor'].puts 'word-completion-not-found'
         
     | 
| 
       682 
700 
     | 
    
         
             
                  if @on_word_complete_no_match
         
     | 
| 
       683 
701 
     | 
    
         
             
                    word = @line.word[:text]
         
     | 
| 
       684 
702 
     | 
    
         
             
                    sub_word = @line.text[@line.word[:start]..@line.position-1] || ""
         
     | 
| 
       685 
     | 
    
         
            -
                     
     | 
| 
      
 703 
     | 
    
         
            +
                    payload = { sub_word: sub_word, word: word }
         
     | 
| 
      
 704 
     | 
    
         
            +
                    Treefell['editor'].puts "word-completion-not-found calling callback with payload: #{payload.inspect}"
         
     | 
| 
      
 705 
     | 
    
         
            +
                    @on_word_complete_no_match.call(name: "word-completion-no-match", payload: payload)
         
     | 
| 
      
 706 
     | 
    
         
            +
                  else
         
     | 
| 
      
 707 
     | 
    
         
            +
                    Treefell['editor'].puts 'word-completion-not-found no on_word_complete_no_match callback to call'
         
     | 
| 
       686 
708 
     | 
    
         
             
                  end
         
     | 
| 
       687 
709 
     | 
    
         
             
                end
         
     | 
| 
       688 
710 
     | 
    
         | 
| 
       689 
711 
     | 
    
         
             
                def completion_done
         
     | 
| 
       690 
712 
     | 
    
         
             
                  if @on_word_complete_done
         
     | 
| 
      
 713 
     | 
    
         
            +
                    Treefell['editor'].puts "word-completion-done calling on_word_complete_done callback"
         
     | 
| 
       691 
714 
     | 
    
         
             
                    @on_word_complete_done.call
         
     | 
| 
      
 715 
     | 
    
         
            +
                  else
         
     | 
| 
      
 716 
     | 
    
         
            +
                    Treefell['editor'].puts 'word-completion-done no on_word_complete_done callback to call'
         
     | 
| 
       692 
717 
     | 
    
         
             
                  end
         
     | 
| 
       693 
718 
     | 
    
         
             
                end
         
     | 
| 
       694 
719 
     | 
    
         | 
| 
       695 
720 
     | 
    
         
             
                def on_word_complete(&blk)
         
     | 
| 
      
 721 
     | 
    
         
            +
                  Treefell['editor'].puts "setting on_word_complete callback"
         
     | 
| 
       696 
722 
     | 
    
         
             
                  @on_word_complete = blk
         
     | 
| 
       697 
723 
     | 
    
         
             
                end
         
     | 
| 
       698 
724 
     | 
    
         | 
| 
       699 
725 
     | 
    
         
             
                def on_word_complete_no_match(&blk)
         
     | 
| 
      
 726 
     | 
    
         
            +
                  Treefell['editor'].puts "setting on_word_complete_no_match callback"
         
     | 
| 
       700 
727 
     | 
    
         
             
                  @on_word_complete_no_match = blk
         
     | 
| 
       701 
728 
     | 
    
         
             
                end
         
     | 
| 
       702 
729 
     | 
    
         | 
| 
       703 
730 
     | 
    
         
             
                def on_word_complete_done(&blk)
         
     | 
| 
      
 731 
     | 
    
         
            +
                  Treefell['editor'].puts "setting on_word_complete_done callback"
         
     | 
| 
       704 
732 
     | 
    
         
             
                  @on_word_complete_done = blk
         
     | 
| 
       705 
733 
     | 
    
         
             
                end
         
     | 
| 
       706 
734 
     | 
    
         | 
| 
      
 735 
     | 
    
         
            +
                def on_word_completion_selected(&blk)
         
     | 
| 
      
 736 
     | 
    
         
            +
                  Treefell['editor'].puts "setting on_word_completion_selected callback"
         
     | 
| 
      
 737 
     | 
    
         
            +
                  @on_word_completion_selected = blk
         
     | 
| 
      
 738 
     | 
    
         
            +
                end
         
     | 
| 
      
 739 
     | 
    
         
            +
             
     | 
| 
       707 
740 
     | 
    
         
             
                #
         
     | 
| 
       708 
741 
     | 
    
         
             
                # Complete file and directory names.
         
     | 
| 
       709 
742 
     | 
    
         
             
                # Hidden files and directories are matched only if <tt>@match_hidden_files</tt> is true.
         
     | 
| 
         @@ -735,7 +768,11 @@ module RawLine 
     | 
|
| 
       735 
768 
     | 
    
         
             
                def show_history
         
     | 
| 
       736 
769 
     | 
    
         
             
                  pos = @line.position
         
     | 
| 
       737 
770 
     | 
    
         
             
                  text = @line.text
         
     | 
| 
       738 
     | 
    
         
            -
                  history. 
     | 
| 
      
 771 
     | 
    
         
            +
                  max_index_width = history.length.to_s.length
         
     | 
| 
      
 772 
     | 
    
         
            +
                  history.each_with_index do |item, i|
         
     | 
| 
      
 773 
     | 
    
         
            +
                    @terminal.puts sprintf("%-#{max_index_width}d %s\n", i+1, item)
         
     | 
| 
      
 774 
     | 
    
         
            +
                  end
         
     | 
| 
      
 775 
     | 
    
         
            +
                  render(reset: true)
         
     | 
| 
       739 
776 
     | 
    
         
             
                  overwrite_line(text, pos)
         
     | 
| 
       740 
777 
     | 
    
         
             
                end
         
     | 
| 
       741 
778 
     | 
    
         | 
    
        data/lib/rawline/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: yap-rawline
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Fabio Cevasco
         
     | 
| 
         @@ -59,6 +59,20 @@ dependencies: 
     | 
|
| 
       59 
59 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       60 
60 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       61 
61 
     | 
    
         
             
                    version: 1.3.0
         
     | 
| 
      
 62 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 63 
     | 
    
         
            +
              name: treefell
         
     | 
| 
      
 64 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 65 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 66 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 67 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 68 
     | 
    
         
            +
                    version: 0.2.3
         
     | 
| 
      
 69 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 70 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 71 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 72 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 73 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 74 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 75 
     | 
    
         
            +
                    version: 0.2.3
         
     | 
| 
       62 
76 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       63 
77 
     | 
    
         
             
              name: rspec
         
     | 
| 
       64 
78 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |