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

Rerender and enter raw mode again by SIGCONT #727

Merged
merged 1 commit into from
Jun 25, 2024
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Set @resized to true using set_signal_handlers, and rerender with handle_resized.

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
Loading