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

ruby-changes:70381

From: aycabta <ko1@a...>
Date: Tue, 21 Dec 2021 00:13:32 +0900 (JST)
Subject: [ruby-changes:70381] c3a3f65b45 (master): [ruby/reline] Split off set_signal_handler method

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

From c3a3f65b4575898ae2ae457bc4f56d1e6bdb169f Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Mon, 20 Dec 2021 18:46:57 +0900
Subject: [ruby/reline] Split off set_signal_handler method

In some tests, the LineEditor#reset method is always called, but doesn't
need to set the signal handlers there, so cuts it out to a separate
method.

https://github.com/ruby/reline/commit/b143c4f5f9
---
 lib/reline.rb             |  1 +
 lib/reline/line_editor.rb | 57 +++++++++++++++++++++++++----------------------
 2 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/lib/reline.rb b/lib/reline.rb
index e5c722fe53e..88f1df3995a 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -290,6 +290,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L290
 
       may_req_ambiguous_char_width
       line_editor.reset(prompt, encoding: Reline::IOGate.encoding)
+      line_editor.set_signal_handlers
       if multiline
         line_editor.multiline_on
         if block_given?
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 657b3e70182..2c458388cdd 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -151,33 +151,6 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L151
     @screen_size = Reline::IOGate.get_screen_size
     @screen_height = @screen_size.first
     reset_variables(prompt, encoding: encoding)
-    @old_trap = Signal.trap('INT') {
-      clear_dialog
-      if @scroll_partial_screen
-        move_cursor_down(@screen_height - (@line_index - @scroll_partial_screen) - 1)
-      else
-        move_cursor_down(@highest_in_all - @line_index - 1)
-      end
-      Reline::IOGate.move_cursor_column(0)
-      scroll_down(1)
-      case @old_trap
-      when 'DEFAULT', 'SYSTEM_DEFAULT'
-        raise Interrupt
-      when 'IGNORE'
-        # Do nothing
-      when 'EXIT'
-        exit
-      else
-        @old_trap.call
-      end
-    }
-    begin
-      @old_tstp_trap = Signal.trap('TSTP') {
-        Reline::IOGate.ungetc("\C-z".ord)
-        @old_tstp_trap.call if @old_tstp_trap.respond_to?(:call)
-      }
-    rescue ArgumentError
-    end
     Reline::IOGate.set_winch_handler do
       @resized = true
     end
@@ -244,6 +217,36 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L217
     end
   end
 
+  def set_signal_handlers
+    @old_trap = Signal.trap('INT') {
+      clear_dialog
+      if @scroll_partial_screen
+        move_cursor_down(@screen_height - (@line_index - @scroll_partial_screen) - 1)
+      else
+        move_cursor_down(@highest_in_all - @line_index - 1)
+      end
+      Reline::IOGate.move_cursor_column(0)
+      scroll_down(1)
+      case @old_trap
+      when 'DEFAULT', 'SYSTEM_DEFAULT'
+        raise Interrupt
+      when 'IGNORE'
+        # Do nothing
+      when 'EXIT'
+        exit
+      else
+        @old_trap.call
+      end
+    }
+    begin
+      @old_tstp_trap = Signal.trap('TSTP') {
+        Reline::IOGate.ungetc("\C-z".ord)
+        @old_tstp_trap.call if @old_tstp_trap.respond_to?(:call)
+      }
+    rescue ArgumentError
+    end
+  end
+
   def finalize
     Signal.trap('INT', @old_trap)
     begin
-- 
cgit v1.2.1


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

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