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

ruby-changes:67322

From: aycabta <ko1@a...>
Date: Sun, 29 Aug 2021 20:31:09 +0900 (JST)
Subject: [ruby-changes:67322] 4cd344c958 (master): [ruby/reline] Add the ability to handle context between dialogs

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

From 4cd344c958a0886fc02238f7f397188dbfca27bd Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Fri, 27 Aug 2021 21:33:22 +0900
Subject: [ruby/reline] Add the ability to handle context between dialogs

https://github.com/ruby/reline/commit/063d9c70d9
---
 lib/reline.rb             |  8 ++++----
 lib/reline/line_editor.rb | 11 ++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/reline.rb b/lib/reline.rb
index 81c5f9e..842f6ba 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -132,10 +132,10 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L132
       @dig_perfect_match_proc = p
     end
 
-    def add_dialog_proc(name_sym, p)
+    def add_dialog_proc(name_sym, p, context = nil)
       raise ArgumentError unless p.respond_to?(:call) or p.nil?
       raise ArgumentError unless name_sym.instance_of?(Symbol)
-      @dialog_proc_list << [name_sym, p]
+      @dialog_proc_list << [name_sym, p, context]
     end
 
     def input=(val)
@@ -273,8 +273,8 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L273
       line_editor.dig_perfect_match_proc = dig_perfect_match_proc
       line_editor.pre_input_hook = pre_input_hook
       @dialog_proc_list.each do |d|
-        name_sym, dialog_proc = d
-        line_editor.add_dialog_proc(name_sym, dialog_proc)
+        name_sym, dialog_proc, context = d
+        line_editor.add_dialog_proc(name_sym, dialog_proc, context)
       end
 
       unless config.test_mode
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index c888474..6783ff9 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -478,12 +478,17 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L478
   end
 
   class DialogProcScope
-    def initialize(line_editor, proc_to_exec)
+    def initialize(line_editor, proc_to_exec, context)
       @line_editor = line_editor
       @proc_to_exec = proc_to_exec
+      @context = context
       @cursor_pos = Reline::CursorPos.new
     end
 
+    def context
+      @context
+    end
+
     def retrieve_completion_block(set_completion_quote_character = false)
       @line_editor.retrieve_completion_block(set_completion_quote_character)
     end
@@ -536,9 +541,9 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L541
     end
   end
 
-  def add_dialog_proc(name, p)
+  def add_dialog_proc(name, p, context = nil)
     return if @dialogs.any? { |d| d.name == name }
-    @dialogs << Dialog.new(name, DialogProcScope.new(self, p))
+    @dialogs << Dialog.new(name, DialogProcScope.new(self, p, context))
   end
 
   DIALOG_HEIGHT = 20
-- 
cgit v1.1


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

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