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

ruby-changes:67697

From: aycabta <ko1@a...>
Date: Fri, 10 Sep 2021 11:39:08 +0900 (JST)
Subject: [ruby-changes:67697] 5dc753df47 (master): [ruby/reline] Move #pointer from DialogRenderInfo to Dialog

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

From 5dc753df47739ce03d4ecaf1f37817858861e5cd Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Fri, 10 Sep 2021 11:23:42 +0900
Subject: [ruby/reline] Move #pointer from DialogRenderInfo to Dialog

https://github.com/ruby/reline/commit/92dbac0bff
---
 lib/reline.rb                            |  5 +++--
 lib/reline/line_editor.rb                | 18 +++++++++---------
 test/reline/yamatanooroti/multiline_repl | 14 +++++++-------
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/lib/reline.rb b/lib/reline.rb
index b331421..9746b35 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -37,7 +37,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L37
     alias_method :==, :match?
   end
   CursorPos = Struct.new(:x, :y)
-  DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, :scrollbar, keyword_init: true)
+  DialogRenderInfo = Struct.new(:pos, :contents, :bg_color, :width, :height, :scrollbar, keyword_init: true)
 
   class Core
     ATTR_READER_NAMES = %i(
@@ -241,7 +241,8 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L241
         context.clear
         context.push(cursor_pos_to_render, result, pointer, dialog)
       end
-      DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, scrollbar: true, height: 15)
+      dialog.pointer = pointer
+      DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, scrollbar: true, height: 15)
     }
     Reline::DEFAULT_DIALOG_CONTEXT = Array.new
 
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index b2f7728..da8787a 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -560,7 +560,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L560
 
   class Dialog
     attr_reader :name, :contents, :width
-    attr_accessor :scroll_top, :scrollbar_pos, :column, :vertical_offset, :lines_backup, :trap_key
+    attr_accessor :scroll_top, :scrollbar_pos, :pointer, :column, :vertical_offset, :lines_backup, :trap_key
 
     def initialize(name, config, proc_scope)
       @name = name
@@ -643,7 +643,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L643
     end
     old_dialog = dialog.clone
     dialog.contents = dialog_render_info.contents
-    pointer = dialog_render_info.pointer
+    pointer = dialog.pointer
     if dialog_render_info.width
       dialog.width = dialog_render_info.width
     else
@@ -652,15 +652,15 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L652
     height = dialog_render_info.height || DIALOG_HEIGHT
     height = dialog.contents.size if dialog.contents.size < height
     if dialog.contents.size > height
-      if dialog_render_info.pointer
-        if dialog_render_info.pointer < 0
+      if dialog.pointer
+        if dialog.pointer < 0
           dialog.scroll_top = 0
-        elsif (dialog_render_info.pointer - dialog.scroll_top) >= (height - 1)
-          dialog.scroll_top = dialog_render_info.pointer - (height - 1)
-        elsif (dialog_render_info.pointer - dialog.scroll_top) < 0
-          dialog.scroll_top = dialog_render_info.pointer
+        elsif (dialog.pointer - dialog.scroll_top) >= (height - 1)
+          dialog.scroll_top = dialog.pointer - (height - 1)
+        elsif (dialog.pointer - dialog.scroll_top) < 0
+          dialog.scroll_top = dialog.pointer
         end
-        pointer = dialog_render_info.pointer - dialog.scroll_top
+        pointer = dialog.pointer - dialog.scroll_top
       end
       dialog.contents = dialog.contents[dialog.scroll_top, height]
     end
diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl
index e8a4aa5..473d9d0 100755
--- a/test/reline/yamatanooroti/multiline_repl
+++ b/test/reline/yamatanooroti/multiline_repl
@@ -59,12 +59,12 @@ opt.on('--dialog VAL') { |v| https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/multiline_repl#L59
     if v.include?('scrollkey')
       dialog.trap_key = nil
       if key and key.match?(dialog.name)
-        if context.pointer.nil?
-          context.pointer = 0
-        elsif context.pointer >= (contents.size - 1)
-          context.pointer = 0
+        if dialog.pointer.nil?
+          dialog.pointer = 0
+        elsif dialog.pointer >= (contents.size - 1)
+          dialog.pointer = 0
         else
-          context.pointer += 1
+          dialog.pointer += 1
         end
       end
       dialog.trap_key = [?j.ord]
@@ -74,8 +74,8 @@ opt.on('--dialog VAL') { |v| https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/multiline_repl#L74
     if v.include?('scrollbar')
       scrollbar = true
     end
-    Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, pointer: context.pointer, scrollbar: scrollbar)
-  }, Struct.new(:pointer).new)
+    Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, scrollbar: scrollbar)
+  })
 }
 opt.on('--complete') {
   Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
-- 
cgit v1.1


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

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