1 require 'nfoiled/terminal'
6 # See `README.markdown`.
11 attr_accessor :initialized; alias_method :initialized?, :initialized
12 attr_accessor :default_terminal
13 attr_accessor :current_terminal
16 # This module method is responsible for setting up the entirety of Nfoiled's
17 # overall environment. It will be called before any other Nfoiled
18 # functionality is allowed. In most cases, this will be called for you.
20 # This method also schedules `Nfoiled::finalize` to be automatically run
23 self.initialized = true
24 self.default_terminal = Terminal.new if Terminal.terminals.empty?
25 self.current_terminal = default_terminal unless current_terminal
26 at_exit { Nfoiled.finalize }
30 # This module method ensures that Nfoiled is initialized. It simply calls
31 # `Nfoiled::initialize!` if Nfoiled hasn't already been initialized.
33 initialize! unless initialized?
38 # This method is responsible for tearing down any environment set up by the
39 # `Ncurses::initialize!` method.
41 self.initialized = false
43 Terminal.terminals.each {|t| t.destroy! }
44 self.current_terminal, self.default_terminal = nil
48 # This module method ensures that Nfoiled is finalize. It simply calls
49 # `Nfoiled::finalize!` if Nfoiled hasn't already been finalized.
51 # TODO: Ensure finalization on fatal errors or interrupts
52 finalize! if initialized?