mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[ruby/reline] Call user defined sigwinch and sigcont handler
(https://github.com/ruby/reline/pull/788)
7d44770c84
This commit is contained in:
parent
569f27b425
commit
0fc70022e6
2 changed files with 41 additions and 4 deletions
|
@ -284,11 +284,15 @@ class Reline::ANSI < Reline::IO
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_winch_handler(&handler)
|
def set_winch_handler(&handler)
|
||||||
@old_winch_handler = Signal.trap('WINCH', &handler)
|
@old_winch_handler = Signal.trap('WINCH') do |arg|
|
||||||
@old_cont_handler = Signal.trap('CONT') do
|
handler.call
|
||||||
|
@old_winch_handler.call(arg) if @old_winch_handler.respond_to?(:call)
|
||||||
|
end
|
||||||
|
@old_cont_handler = Signal.trap('CONT') do |arg|
|
||||||
@input.raw!(intr: true) if @input.tty?
|
@input.raw!(intr: true) if @input.tty?
|
||||||
# Rerender the screen. Note that screen size might be changed while suspended.
|
# Rerender the screen. Note that screen size might be changed while suspended.
|
||||||
handler.call
|
handler.call
|
||||||
|
@old_cont_handler.call(arg) if @old_cont_handler.respond_to?(:call)
|
||||||
end
|
end
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
# Signal.trap may raise an ArgumentError if the platform doesn't support the signal.
|
# Signal.trap may raise an ArgumentError if the platform doesn't support the signal.
|
||||||
|
|
|
@ -1795,16 +1795,47 @@ begin
|
||||||
close
|
close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_user_defined_winch
|
||||||
|
omit if Reline.core.io_gate.win?
|
||||||
|
pidfile = Tempfile.create('pidfile')
|
||||||
|
rubyfile = Tempfile.create('rubyfile')
|
||||||
|
rubyfile.write <<~RUBY
|
||||||
|
File.write(#{pidfile.path.inspect}, Process.pid)
|
||||||
|
winch_called = false
|
||||||
|
Signal.trap(:WINCH, ->(_arg){ winch_called = true })
|
||||||
|
p Reline.readline('>')
|
||||||
|
puts "winch: \#{winch_called}"
|
||||||
|
RUBY
|
||||||
|
rubyfile.close
|
||||||
|
|
||||||
|
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib -rreline #{rubyfile.path}})
|
||||||
|
assert_screen(/^>/)
|
||||||
|
write 'a'
|
||||||
|
assert_screen(/^>a/)
|
||||||
|
pid = pidfile.tap(&:rewind).read.to_i
|
||||||
|
Process.kill(:WINCH, pid) unless pid.zero?
|
||||||
|
write "b\n"
|
||||||
|
assert_screen(/"ab"\nwinch: true/)
|
||||||
|
close
|
||||||
|
ensure
|
||||||
|
File.delete(rubyfile.path) if rubyfile
|
||||||
|
pidfile.close if pidfile
|
||||||
|
File.delete(pidfile.path) if pidfile
|
||||||
|
end
|
||||||
|
|
||||||
def test_stop_continue
|
def test_stop_continue
|
||||||
omit if Reline.core.io_gate.win?
|
omit if Reline.core.io_gate.win?
|
||||||
pidfile = Tempfile.create('pidfile')
|
pidfile = Tempfile.create('pidfile')
|
||||||
rubyfile = Tempfile.create('rubyfile')
|
rubyfile = Tempfile.create('rubyfile')
|
||||||
rubyfile.write <<~RUBY
|
rubyfile.write <<~RUBY
|
||||||
File.write(#{pidfile.path.inspect}, Process.pid)
|
File.write(#{pidfile.path.inspect}, Process.pid)
|
||||||
p Reline.readmultiline('>'){false}
|
cont_called = false
|
||||||
|
Signal.trap(:CONT, ->(_arg){ cont_called = true })
|
||||||
|
Reline.readmultiline('>'){|input| input.match?(/ghi/) }
|
||||||
|
puts "cont: \#{cont_called}"
|
||||||
RUBY
|
RUBY
|
||||||
rubyfile.close
|
rubyfile.close
|
||||||
start_terminal(40, 50, ['bash'])
|
start_terminal(10, 50, ['bash'])
|
||||||
write "ruby -I#{@pwd}/lib -rreline #{rubyfile.path}\n"
|
write "ruby -I#{@pwd}/lib -rreline #{rubyfile.path}\n"
|
||||||
assert_screen(/^>/)
|
assert_screen(/^>/)
|
||||||
write "abc\ndef\nhi"
|
write "abc\ndef\nhi"
|
||||||
|
@ -1814,6 +1845,8 @@ begin
|
||||||
assert_screen(/fg\n.*>/m)
|
assert_screen(/fg\n.*>/m)
|
||||||
write "\ebg"
|
write "\ebg"
|
||||||
assert_screen(/>abc\n>def\n>ghi\n/)
|
assert_screen(/>abc\n>def\n>ghi\n/)
|
||||||
|
write "\n"
|
||||||
|
assert_screen(/cont: true/)
|
||||||
close
|
close
|
||||||
ensure
|
ensure
|
||||||
File.delete(rubyfile.path) if rubyfile
|
File.delete(rubyfile.path) if rubyfile
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue