summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2023-02-27 17:43:51 +0900
committergit <[email protected]>2023-02-27 08:44:02 +0000
commit92ed8e6f3f561ea25c411f94d6469497e9cb9204 (patch)
tree977f5ffd50143bbaf03abb146266c828e6b9c648
parent494c274b82d267ace9878202a65fb100cb5f62f7 (diff)
[ruby/reline] Fix the cause of test_yamatanooroti randomly failing
(https://github.com/ruby/reline/pull/474) * Add repeated input-delete test that fails on HEAD * Use raw mode while readmultiline
-rw-r--r--lib/reline.rb24
-rw-r--r--lib/reline/ansi.rb4
-rw-r--r--lib/reline/general_io.rb4
-rw-r--r--lib/reline/line_editor.rb2
-rw-r--r--lib/reline/windows.rb4
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb10
6 files changed, 36 insertions, 12 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index c11d4a7b93..210f33478f 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -266,19 +266,21 @@ module Reline
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)
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb
index 3c6997e0f8..42a3913387 100644
--- a/lib/reline/ansi.rb
+++ b/lib/reline/ansi.rb
@@ -143,6 +143,10 @@ class Reline::ANSI
@@output = val
end
+ def self.with_raw_input
+ @@input.raw { yield }
+ end
+
@@buf = []
def self.inner_getc
unless @@buf.empty?
diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb
index 92c76cbba1..9929846568 100644
--- a/lib/reline/general_io.rb
+++ b/lib/reline/general_io.rb
@@ -31,6 +31,10 @@ class Reline::GeneralIO
@@input = val
end
+ def self.with_raw_input
+ yield
+ end
+
def self.getc
unless @@buf.empty?
return @@buf.shift
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 16e99e087a..40f89f22c8 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -457,7 +457,7 @@ class Reline::LineEditor
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
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index b952329911..7ea2a00f63 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -291,6 +291,10 @@ class Reline::Windows
end
end
+ def self.with_raw_input
+ yield
+ end
+
def self.getc
check_input_event
@@output_buf.shift
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 1e46701664..90cd3b52c9 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -1425,6 +1425,16 @@ begin
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