Skip to content

Commit

Permalink
[ruby/irb] Fix dancing-ruby Ctrl+C stop
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored and hsbt committed Nov 8, 2023
1 parent d8e0337 commit c8d4b10
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/irb/easter-egg.rb
Expand Up @@ -115,7 +115,9 @@ def render_frame(i)
io.write easter_egg_logo(:large)
end
when :dancing
begin
STDOUT.cooked do
interrupted = false
prev_trap = trap("SIGINT") { interrupted = true }
canvas = Canvas.new(Reline.get_screen_size)
Reline::IOGate.set_winch_handler do
canvas = Canvas.new(Reline.get_screen_size)
Expand All @@ -131,10 +133,12 @@ def render_frame(i)
buff[0, 20] = "\e[0mPress Ctrl+C to stop\e[31m\e[1m"
print "\e[H" + buff
sleep 0.05
break if interrupted
end
rescue Interrupt
ensure
print "\e[0m\e[?1049l"
trap("SIGINT", prev_trap)
end
end
end
Expand Down

0 comments on commit c8d4b10

Please sign in to comment.