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

Call user defined sigwinch and sigcont handler #788

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented Nov 30, 2024

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}

Copy link
Member

@ima1zumi ima1zumi left a comment

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
40 checks passed
@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
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