Skip to content

Commit

Permalink
Rerender and enter raw mode again by SIGCONT (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored Jun 25, 2024
1 parent 46b30b0 commit be45660
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/reline/io/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ def clear_screen

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
Expand All @@ -360,5 +367,6 @@ def deprep(otio)
# 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
19 changes: 19 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,25 @@ def test_thread_safe
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
Expand Down

0 comments on commit be45660

Please sign in to comment.