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

ruby-changes:62900

From: aycabta <ko1@a...>
Date: Sat, 12 Sep 2020 08:38:52 +0900 (JST)
Subject: [ruby-changes:62900] ce389ade45 (master): [ruby/reline] Move cursor to currect vertical pos after rendering a logical line

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

From ce389ade45f412351d7c91db60eaa5e19fcd8c5f Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Fri, 11 Sep 2020 05:48:59 +0900
Subject: [ruby/reline] Move cursor to currect vertical pos after rendering a
 logical line

https://github.com/ruby/reline/commit/9b932df544

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index ede9132..edea2fa 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -524,12 +524,14 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L524
     end
     Reline::IOGate.erase_after_cursor
     if with_control
-      move_cursor_up(height - 1)
+      # Just after rendring, so the cursor is on the last line.
       if finished?
-        move_cursor_down(@started_from)
+        Reline::IOGate.move_cursor_column(0)
+      else
+        # Moves up from bottom of lines to the cursor position.
+        move_cursor_up(height - 1 - @started_from)
+        Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
       end
-      move_cursor_down(@started_from)
-      Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
     end
     height
   end
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index d348b87..effeb7c 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -64,6 +64,42 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L64
       EOC
     end
 
+    def test_finish_autowrapped_line
+      start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl})
+      sleep 0.5
+      write("[{'user'=>{'email'=>'a@a', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]\n")
+      close
+      assert_screen(<<~EOC)
+        Multiline REPL.
+        prompt> [{'user'=>{'email'=>'a@a', 'id'=
+        >'ABC'}, 'version'=>4, 'status'=>'succee
+        ded'}]
+        => [{"user"=>{"email"=>"a@a", "id"=>"ABC
+        "}, "version"=>4, "status"=>"succeeded"}
+        ]
+        prompt>
+      EOC
+    end
+
+    def test_finish_autowrapped_line_in_the_middle_of_lines
+      start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl})
+      sleep 0.5
+      write("[{'user'=>{'email'=>'abcdef@abcdef', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]#{"\C-b"*7}\n")
+      close
+      assert_screen(<<~EOC)
+        Multiline REPL.
+        prompt> [{'user'=>{'email'=>'a
+        bcdef@abcdef', 'id'=>'ABC'}, '
+        version'=>4, 'status'=>'succee
+        ded'}]
+        => [{"user"=>{"email"=>"abcdef
+        @abcdef", "id"=>"ABC"}, "versi
+        on"=>4, "status"=>"succeeded"}
+        ]
+        prompt>
+      EOC
+    end
+
     def test_prompt
       File.open(@inputrc_file, 'w') do |f|
         f.write <<~'LINES'
-- 
cgit v0.10.2


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

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