Skip to content

Commit

Permalink
[ruby/reline] Bypass cursor down when a char is rendered at eol on Wi…
Browse files Browse the repository at this point in the history
…ndows

A newline is automatically inserted if a character is rendered at eol on
Windows command prompt.

ruby/reline@4bfea07e4a
  • Loading branch information
aycabta committed Feb 1, 2020
1 parent 16d4774 commit 06c37fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/reline/ansi.rb
Expand Up @@ -5,6 +5,10 @@ def self.encoding
Encoding.default_external
end

def self.win?
false
end

RAW_KEYSTROKE_CONFIG = {
[27, 91, 65] => :ed_prev_history, # ↑
[27, 91, 66] => :ed_next_history, # ↓
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/general_io.rb
Expand Up @@ -5,6 +5,10 @@ def self.encoding
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
end

def self.win?
false
end

RAW_KEYSTROKE_CONFIG = {}

@@buf = []
Expand Down
14 changes: 11 additions & 3 deletions lib/reline/line_editor.rb
Expand Up @@ -507,12 +507,20 @@ def rerender
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
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/windows.rb
Expand Up @@ -5,6 +5,10 @@ def self.encoding
Encoding::UTF_8
end

def self.win?
true
end

RAW_KEYSTROKE_CONFIG = {
[224, 72] => :ed_prev_history, # ↑
[224, 80] => :ed_next_history, # ↓
Expand Down

0 comments on commit 06c37fa

Please sign in to comment.