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

Fix the cause of test_yamatanooroti randomly failing #474

Merged
merged 2 commits into from
Feb 27, 2023
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
24 changes: 13 additions & 11 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,21 @@ def get_screen_size
Reline::DEFAULT_DIALOG_CONTEXT = Array.new

def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
unless confirm_multiline_termination
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
end
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
Reline::IOGate.with_raw_input do
unless confirm_multiline_termination
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
end
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)

whole_buffer = line_editor.whole_buffer.dup
whole_buffer.taint if RUBY_VERSION < '2.7'
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
Reline::HISTORY << whole_buffer
end
whole_buffer = line_editor.whole_buffer.dup
whole_buffer.taint if RUBY_VERSION < '2.7'
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
Reline::HISTORY << whole_buffer
end

line_editor.reset_line if line_editor.whole_buffer.nil?
whole_buffer
line_editor.reset_line if line_editor.whole_buffer.nil?
whole_buffer
end
end

def readline(prompt = '', add_hist = false)
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def self.output=(val)
@@output = val
end

def self.with_raw_input
@@input.raw { yield }
end

@@buf = []
def self.inner_getc
unless @@buf.empty?
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/general_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def self.input=(val)
@@input = val
end

def self.with_raw_input
yield
end

def self.getc
unless @@buf.empty?
return @@buf.shift
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def rerender
new_lines = whole_lines
end
modify_lines(new_lines).each_with_index do |line, index|
@output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\n"
@output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\r\n"
Reline::IOGate.erase_after_cursor
end
@output.flush
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def self.check_input_event
end
end

def self.with_raw_input
yield
end

def self.getc
check_input_event
@@output_buf.shift
Expand Down
10 changes: 10 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,16 @@ def test_bracket_newline_indent
EOC
end

def test_repeated_input_delete
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("a\C-h" * 4000)
close
assert_screen(<<~'EOC')
Multiline REPL.
prompt>
EOC
end

def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content
Expand Down