Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IO#write instead of IO#print #126

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def readline(prompt = '', add_hist = false)
@ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
return if ambiguous_width
Reline::IOGate.move_cursor_column(0)
print "\u{25bd}"
output.write "\u{25bd}"
@ambiguous_width = Reline::IOGate.cursor_pos.x
Reline::IOGate.move_cursor_column(0)
Reline::IOGate.erase_after_cursor
Expand Down
14 changes: 7 additions & 7 deletions lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,37 +124,37 @@ def self.cursor_pos
end

def self.move_cursor_column(x)
print "\e[#{x + 1}G"
@@output.write "\e[#{x + 1}G"
end

def self.move_cursor_up(x)
if x > 0
print "\e[#{x}A" if x > 0
@@output.write "\e[#{x}A" if x > 0
elsif x < 0
move_cursor_down(-x)
end
end

def self.move_cursor_down(x)
if x > 0
print "\e[#{x}B" if x > 0
@@output.write "\e[#{x}B" if x > 0
elsif x < 0
move_cursor_up(-x)
end
end

def self.erase_after_cursor
print "\e[K"
@@output.write "\e[K"
end

def self.scroll_down(x)
return if x.zero?
print "\e[#{x}S"
@@output.write "\e[#{x}S"
end

def self.clear_screen
print "\e[2J"
print "\e[1;1H"
@@output.write "\e[2J"
@@output.write "\e[1;1H"
end

@@old_winch_handler = nil
Expand Down
4 changes: 2 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def rerender
@rerender_all = true
@menu_info.list.sort!.each do |item|
Reline::IOGate.move_cursor_column(0)
@output.print item
@output.write item
@output.flush
scroll_down(1)
end
Expand Down Expand Up @@ -516,7 +516,7 @@ def rerender
end
next
end
@output.print line
@output.write 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
Expand Down
4 changes: 2 additions & 2 deletions lib/reline/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def self.scroll_down(val)

def self.clear_screen
# TODO: Use FillConsoleOutputCharacter and FillConsoleOutputAttribute
print "\e[2J"
print "\e[1;1H"
write "\e[2J"
write "\e[1;1H"
end

def self.set_screen_size(rows, columns)
Expand Down