Skip to content

Commit

Permalink
[ruby/reline] Fix the cause of test_yamatanooroti randomly failing
Browse files Browse the repository at this point in the history
(ruby/reline#474)

* Add repeated input-delete test that fails on HEAD

* Use raw mode while readmultiline
  • Loading branch information
tompng authored and hsbt committed Feb 27, 2023
1 parent ef5facf commit a1db25b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
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

0 comments on commit a1db25b

Please sign in to comment.