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

ruby-changes:67301

From: aycabta <ko1@a...>
Date: Sun, 29 Aug 2021 20:30:40 +0900 (JST)
Subject: [ruby-changes:67301] 02a61fe33f (master): [ruby/reline] Hide cursor when rendering dialog

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

From 02a61fe33f422d7e041531cac1a5a45a14ca5752 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sun, 22 Aug 2021 01:31:21 +0900
Subject: [ruby/reline] Hide cursor when rendering dialog

https://github.com/ruby/reline/commit/a9050cf676
---
 lib/reline/ansi.rb        | 16 ++++++++++++++++
 lib/reline/line_editor.rb |  4 ++++
 lib/reline/windows.rb     |  8 ++++++++
 3 files changed, 28 insertions(+)

diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb
index 09bd956..f642060 100644
--- a/lib/reline/ansi.rb
+++ b/lib/reline/ansi.rb
@@ -274,6 +274,22 @@ class Reline::ANSI https://github.com/ruby/ruby/blob/trunk/lib/reline/ansi.rb#L274
     end
   end
 
+  def self.hide_cursor
+    if Reline::Terminfo.enabled?
+      @@output.write Reline::Terminfo.tigetstr('civis')
+    else
+      # ignored
+    end
+  end
+
+  def self.show_cursor
+    if Reline::Terminfo.enabled?
+      @@output.write Reline::Terminfo.tigetstr('cnorm')
+    else
+      # ignored
+    end
+  end
+
   def self.erase_after_cursor
     @@output.write "\e[K"
   end
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index f275f7c..d8e2842 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -562,6 +562,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L562
       @dialog_updown = :down
       @dialog_vertical_offset = 1
     end
+    Reline::IOGate.hide_cursor
     reset_dialog(old_dialog_contents, old_dialog_contents_width, old_dialog_column, old_dialog_vertical_offset, old_dialog_updown)
     case @dialog_updown
     when :down
@@ -581,6 +582,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L582
       move_cursor_up(@dialog_contents.size)
     when :up
     end
+    Reline::IOGate.show_cursor
     @dialog_lines_backup = {
       lines: modify_lines(whole_lines),
       line_index: @line_index,
@@ -683,6 +685,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L685
       visual_lines.concat(vl)
     }
     visual_lines_under_dialog = visual_lines[visual_start, @dialog_contents.size]
+    Reline::IOGate.hide_cursor
     move_cursor_down(@dialog_vertical_offset)
     dialog_vertical_size = @dialog_contents.size
     dialog_vertical_size.times do |i|
@@ -698,6 +701,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L701
     end
     move_cursor_up(dialog_vertical_size - 1 + @dialog_vertical_offset)
     Reline::IOGate.move_cursor_column(prompt_width + @cursor)
+    Reline::IOGate.show_cursor
   end
 
   private def calculate_scroll_partial_screen(highest_in_all, cursor_y)
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index 8665f3b..ae87b38 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -343,6 +343,14 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L343
     raise NotImplementedError
   end
 
+  def self.hide_cursor
+    # ignored
+  end
+
+  def self.show_cursor
+    # ignored
+  end
+
   def self.set_winch_handler(&handler)
     @@winch_handler = handler
   end
-- 
cgit v1.1


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

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