aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-02-01 02:59:46 +0900
committeraycabta <aycabta@gmail.com>2020-02-02 03:28:20 +0900
commit06c37fa5b4834c81470213a04dc73a63e69e9776 (patch)
tree59d18c7c47759ae90706b422402f013332a9df30 /lib
parent16d4774da1f0c5f5a78dff752780e77ebdf9b2f8 (diff)
downloadruby-06c37fa5b4834c81470213a04dc73a63e69e9776.tar.gz
[ruby/reline] Bypass cursor down when a char is rendered at eol on Windows
A newline is automatically inserted if a character is rendered at eol on Windows command prompt. https://github.com/ruby/reline/commit/4bfea07e4a
Diffstat (limited to 'lib')
-rw-r--r--lib/reline/ansi.rb4
-rw-r--r--lib/reline/general_io.rb4
-rw-r--r--lib/reline/line_editor.rb14
-rw-r--r--lib/reline/windows.rb4
4 files changed, 23 insertions, 3 deletions
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb
index 33b74f51af..33bb1e4650 100644
--- a/lib/reline/ansi.rb
+++ b/lib/reline/ansi.rb
@@ -5,6 +5,10 @@ class Reline::ANSI
Encoding.default_external
end
+ def self.win?
+ false
+ end
+
RAW_KEYSTROKE_CONFIG = {
[27, 91, 65] => :ed_prev_history, # ↑
[27, 91, 66] => :ed_next_history, # ↓
diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb
index 08b9d9c3ae..85f1f13eed 100644
--- a/lib/reline/general_io.rb
+++ b/lib/reline/general_io.rb
@@ -5,6 +5,10 @@ class Reline::GeneralIO
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
end
+ def self.win?
+ false
+ end
+
RAW_KEYSTROKE_CONFIG = {}
@@buf = []
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 9ee361ec78..c68847d1d4 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -507,12 +507,20 @@ class Reline::LineEditor
Reline::IOGate.move_cursor_column(0)
visual_lines.each_with_index do |line, index|
if line.nil?
- Reline::IOGate.erase_after_cursor
- move_cursor_down(1)
- Reline::IOGate.move_cursor_column(0)
+ if Reline::IOGate.win? and calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last
+ # A newline is automatically inserted if a character is rendered at eol on command prompt.
+ else
+ Reline::IOGate.erase_after_cursor
+ move_cursor_down(1)
+ Reline::IOGate.move_cursor_column(0)
+ end
next
end
@output.print line
+ if Reline::IOGate.win? and calculate_width(line, true) == Reline::IOGate.get_screen_size.last
+ # A newline is automatically inserted if a character is rendered at eol on command prompt.
+ @rest_height -= 1 if @rest_height > 0
+ end
@output.flush
if @first_prompt
@first_prompt = false
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index 2492dffd27..22a009ea66 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -5,6 +5,10 @@ class Reline::Windows
Encoding::UTF_8
end
+ def self.win?
+ true
+ end
+
RAW_KEYSTROKE_CONFIG = {
[224, 72] => :ed_prev_history, # ↑
[224, 80] => :ed_next_history, # ↓