Skip to content

Call user defined sigwinch and sigcont handler - #788

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
tompng:user_defined_sigwinch_sigcont
Nov 30, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
tompng:user_defined_sigwinch_sigcont

Conversation

@tompng

@tompng tompng commented Nov 30, 2024

Copy link
Copy Markdown
Member

Fixes #735

Considering this kind of code. This code doesn't work well.

height, width = STDIN.winsize
Signal.trap(:WINCH){ height, width = STDIN.winsize }

loop do
  cui_game_render(width, height)
  if game_requires_user_text_input
    user_input = Reline.readline('>')
  end
end

User defined WINCH handler won't be called when window size is changed while reading input in Reline.readline. Same for SIGCONT.
This pull request fixes it.

We don't need to consider about user-defined WINCH handler prints something and corrupt Reline's screen. User-defined handler is expected to never print to STDOUT.

Signal.trap(:WINCH) do
  # This code has a possibility of `deadlock; recursive locking (ThreadError)`
  puts "winsize changed"
  clear_screen
  rerender_game_screen
end
loop{print "\e[H";sleep 0.0001}

@ima1zumi ima1zumi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@ima1zumi
ima1zumi merged commit 7d44770 into ruby:master Nov 30, 2024
@tompng
tompng deleted the user_defined_sigwinch_sigcont branch November 30, 2024 17:30
@ima1zumi ima1zumi added the bug Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't compose user terminal resize logic with Reline's terminal resize logic

2 participants