From 06c37fa5b4834c81470213a04dc73a63e69e9776 Mon Sep 17 00:00:00 2001 From: aycabta Date: Sat, 1 Feb 2020 02:59:46 +0900 Subject: [PATCH] [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 --- lib/reline/ansi.rb | 4 ++++ lib/reline/general_io.rb | 4 ++++ lib/reline/line_editor.rb | 14 +++++++++++--- lib/reline/windows.rb | 4 ++++ 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, # ↓