1 require 'nfoiled/terminal'
2 require 'nfoiled/window'
7 # See `README.markdown`.
12 attr_accessor :initialized; alias_method :initialized?, :initialized
15 # This module method is responsible for setting up the entirety of Nfoiled's
16 # overall environment. It will be called before any other Nfoiled
17 # functionality is allowed. In most cases, this will be called for you.
19 # This method also schedules `Nfoiled::finalize` to be automatically run
22 self.initialized = true
23 Terminal.default = Terminal.new unless Terminal.current
25 ::Ncurses.noecho # Characters will not be printed to the terminal by Ncurses for us
26 ::Ncurses.cbreak # No character processing is done, each individual character will be returned to `#getch`
27 ::Ncurses.raw # Interrupt etc signals are all directed to us instead of handled by Ncurses
29 at_exit { Nfoiled.finalize }
33 # This module method ensures that Nfoiled is initialized. It simply calls
34 # `Nfoiled::initialize!` if Nfoiled hasn't already been initialized.
36 initialize! unless initialized?
41 # Causes an cycling of the physical window with the virtual window.
43 # Warning: You have to update the virtual window first!
45 # We need to ensure that the current input acceptor will have the cursor
46 # at all times, so we force a refresh on it (Ncurses leaves the cursor
47 # on the last window to be updated). See `doupdate(3X)`.
48 Terminal.current.acceptor.update
53 # This method is responsible for tearing down any environment set up by the
54 # `Ncurses::initialize!` method. See `endwin(3X)`.
56 self.initialized = false
58 Terminal.terminals.each {|t| t.destroy! }
59 Terminal.current, Terminal.default = nil
63 # This module method ensures that Nfoiled is finalize. It simply calls
64 # `Nfoiled::finalize!` if Nfoiled hasn't already been finalized.
66 # TODO: Ensure finalization on fatal errors or interrupts
67 finalize! if initialized?