[前][次][番号順一覧][スレッド一覧]

ruby-changes:67321

From: aycabta <ko1@a...>
Date: Sun, 29 Aug 2021 20:31:08 +0900 (JST)
Subject: [ruby-changes:67321] acffb0b068 (master): [ruby/reline] Cut out the autocomplete callback

https://git.ruby-lang.org/ruby.git/commit/?id=acffb0b068

From acffb0b0683decd2e99ab7414f9c73fb3e135d2c Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Fri, 27 Aug 2021 03:45:27 +0900
Subject: [ruby/reline] Cut out the autocomplete callback

https://github.com/ruby/reline/commit/46aa2694da
---
 lib/reline.rb | 64 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 33 insertions(+), 31 deletions(-)

diff --git a/lib/reline.rb b/lib/reline.rb
index eb99bd5..8c72d69 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -177,41 +177,43 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L177
       Reline::IOGate.get_screen_size
     end
 
+    DEFAULT_DIALOG_PROC_AUTOCOMPLETE = ->() {
+      # autocomplete
+      if just_cursor_moving and completion_journey_data.nil?
+        # Auto complete starts only when edited
+        return nil
+      end
+      pre, target, post= retrieve_completion_block(true)
+      if target.nil? or target.empty?# or target.size <= 3
+        return nil
+      end
+      if completion_journey_data and completion_journey_data.list
+        result = completion_journey_data.list.dup
+        result.shift
+        pointer = completion_journey_data.pointer - 1
+      else
+        result = call_completion_proc_with_checking_args(pre, target, post)
+        pointer = nil
+      end
+      if result and result.size == 1 and result[0] == target
+        result = nil
+      end
+      target_width = Reline::Unicode.calculate_width(target)
+      x = cursor_pos.x - target_width
+      if x < 0
+        x = screen_width + x
+        y = -1
+      else
+        y = 0
+      end
+      [Reline::CursorPos.new(x, y), result, pointer]
+    }
+
     def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
       unless confirm_multiline_termination
         raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
       end
-      @dialog_proc = ->() {
-        # autocomplete
-        if just_cursor_moving and completion_journey_data.nil?
-          # Auto complete starts only when edited
-          return nil
-        end
-        pre, target, post= retrieve_completion_block(true)
-        if target.nil? or target.empty?
-          return nil
-        end
-        if completion_journey_data and completion_journey_data.list
-          result = completion_journey_data.list.dup
-          result.shift
-          pointer = completion_journey_data.pointer - 1
-        else
-          result = call_completion_proc_with_checking_args(pre, target, post)
-          pointer = nil
-        end
-        if result and result.size == 1 and result[0] == target
-          result = nil
-        end
-        target_width = Reline::Unicode.calculate_width(target)
-        x = cursor_pos.x - target_width
-        if x < 0
-          x = screen_width + x
-          y = -1
-        else
-          y = 0
-        end
-        [Reline::CursorPos.new(x, y), result, pointer]
-      }
+      @dialog_proc = DEFAULT_DIALOG_PROC_AUTOCOMPLETE
       inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
 
       whole_buffer = line_editor.whole_buffer.dup
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]