gavinlaking / vedeu

A framework written in Ruby for building GUI/TUI terminal/console applications.
Other
577 stars 35 forks source link

Win Compatibility: Signals #373

Closed romaslmd closed 8 years ago

romaslmd commented 8 years ago

Hi,

found new issue with Win compatibility: SIGWINCH is not supported by some OS as well as some others signals.. Is it possible to make Traps something like:

module Vedeu
  module Runtime
    module Traps
      def self.add_sig_trap(*keys, &block)
        keys.each do |key|
          Signal.trap(key.to_s, &block) if Signal.list.key?(key.to_s)
        end
      end

      # Change Terminal Size
      add_sig_trap(:SIGWINCH) { Vedeu.trigger(:_resize_) }
      # Stop Runtime
      add_sig_trap(:INT, :TERM) { exit(1) }
      # Read From Terminal
      add_sig_trap(:TTIN) {}
      # User
      add_sig_trap(:USR1, :USR2) {}
    end
  end
end

?

PS: Not Tested..

gavinlaking commented 8 years ago

Hi,

Thanks for the suggestion! I've implemented it, and will be available on the next release. I've not done too much with signal trapping before which is why this was previously sparse, but I hope to expand upon it in the future.

Gav