summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-06-25 09:55:02 +0900
committergit <svn-admin@ruby-lang.org>2024-06-25 00:55:07 +0000
commit691d85d3429891f659e9ebfab6286fa65615be03 (patch)
treed7d82a0400504148f9d2719c939485477555768f
parentae0c7faa79029ebe615487d23c8ee1ca44ce4a36 (diff)
[ruby/reline] Rerender and enter raw mode again by SIGCONT
(https://github.com/ruby/reline/pull/727) https://github.com/ruby/reline/commit/be45660c83
-rw-r--r--lib/reline/io/ansi.rb8
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb19
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb
index 30a89bc471..a730a953f7 100644
--- a/lib/reline/io/ansi.rb
+++ b/lib/reline/io/ansi.rb
@@ -347,6 +347,13 @@ class Reline::ANSI < Reline::IO
def set_winch_handler(&handler)
@old_winch_handler = Signal.trap('WINCH', &handler)
+ @old_cont_handler = Signal.trap('CONT') do
+ @input.raw!(intr: true) if @input.tty?
+ # Rerender the screen. Note that screen size might be changed while suspended.
+ handler.call
+ end
+ rescue ArgumentError
+ # Signal.trap may raise an ArgumentError if the platform doesn't support the signal.
end
def prep
@@ -360,5 +367,6 @@ class Reline::ANSI < Reline::IO
# Disable bracketed paste
@output.write "\e[?2004l" if Reline.core.config.enable_bracketed_paste && both_tty?
Signal.trap('WINCH', @old_winch_handler) if @old_winch_handler
+ Signal.trap('CONT', @old_cont_handler) if @old_cont_handler
end
end
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index f119d686cd..3722a28620 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -1840,6 +1840,25 @@ begin
EOC
end
+ def test_stop_continue
+ pidfile = Tempfile.create('pidfile')
+ rubyfile = Tempfile.create('rubyfile')
+ rubyfile.write <<~RUBY
+ File.write(#{pidfile.path.inspect}, Process.pid)
+ p Reline.readmultiline('>'){false}
+ RUBY
+ rubyfile.close
+ start_terminal(40, 50, ['bash'])
+ write "ruby -I#{@pwd}/lib -rreline #{rubyfile.path}\n"
+ write "abc\ndef\nhi"
+ pid = pidfile.tap(&:rewind).read.to_i
+ Process.kill(:STOP, pid) unless pid.zero?
+ write "fg\n"
+ write "\ebg"
+ close
+ assert_include result.join("\n"), ">abc\n>def\n>ghi\n"
+ end
+
def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content