8000 Bypass cursor down when a char is rendered at eol on Windows · ruby/reline@4bfea07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bfea07

Browse files
committed
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.
1 parent 225670d commit 4bfea07

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

lib/reline/ansi.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ def self.encoding
55
Encoding.default_external
66
end
77

8+
def self.win?
9+
false
10+
end
11+
812
RAW_KEYSTROKE_CONFIG = {
913
[27, 91, 65] => :ed_prev_history, # ↑
1014
[27, 91, 66] => :ed_next_history, # ↓

lib/reline/general_io.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ def self.encoding
55
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
66
end
77

8+
def self.win?
9+
false
10+
end
11+
812
RAW_KEYSTROKE_CONFIG = {}
913

1014
@@buf = []

lib/reline/line_editor.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,20 @@ def rerender
507507
Reline::IOGate.move_cursor_column(0)
508508
visual_lines.each_with_index do |line, index|
509509
if line.nil?
510< 8000 span class="diff-text-marker">-
Reline::IOGate.erase_after_cursor
511-
move_cursor_down(1)
512-
Reline::IOGate.move_cursor_column(0)
510+
if Reline::IOGate.win? and calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last
511+
# A newline is automatically inserted if a character is rendered at eol on command prompt.
512+
else
513+
Reline::IOGate.erase_after_cursor
514+
move_cursor_down(1)
515+
Reline::IOGate.move_cursor_column(0)
516+
end
513517
next
514518
end
515519
@output.print line
520+
if Reline::IOGate.win? and calculate_width(line, true) == Reline::IOGate.get_screen_size.last
521+
# A newline is automatically inserted if a character is rendered at eol on command prompt.
522+
@rest_height -= 1 if @rest_height > 0
523+
end
516524
@output.flush
517525
if @first_prompt
518526
@first_prompt = false

lib/reline/windows.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ def self.encoding
55
Encoding::UTF_8
66
end
77

8+
def self.win?
9+
true
10+
end
11+
812
RAW_KEYSTROKE_CONFIG = {
913
[224, 72] => :ed_prev_history, # ↑
1014
[224, 80] => :ed_next_history, # ↓

0 commit comments

Comments
 (0)
0