4 require 'nfoiled/terminal'
5 require 'nfoiled/window'
8 # See `README.markdown`.
13 attr_accessor :initialized; alias_method :initialized?, :initialized
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 Terminal.default = Terminal.new unless Terminal.current
26 ::Ncurses.noecho # Characters will not be printed to the terminal by Ncurses for us
27 ::Ncurses.cbreak # No character processing is done, each individual character will be returned to `#getch`
28 ::Ncurses.raw # Interrupt etc signals are all directed to us instead of handled by Ncurses
30 at_exit { Nfoiled.finalize }
34 # This module method ensures that Nfoiled is initialized. It simply calls
35 # `Nfoiled::initialize!` if Nfoiled hasn't already been initialized.
37 initialize! unless initialized?
42 # Causes an cycling of the physical window with the virtual window.
44 # Warning: You have to update the virtual window first!
46 # We need to ensure that the current input acceptor will have the cursor
47 # at all times, so we force a refresh on it (Ncurses leaves the cursor
48 # on the last window to be updated). See `doupdate(3X)`.
49 Terminal.current.acceptor.update
54 # This method is responsible for tearing down any environment set up by the
55 # `Ncurses::initialize!` method. See `endwin(3X)`.
57 self.initialized = false
59 Terminal.terminals.each {|t| t.destroy! }
60 Terminal.current, Terminal.default = nil
64 # This module method ensures that Nfoiled is finalize. It simply calls
65 # `Nfoiled::finalize!` if Nfoiled hasn't already been finalized.
67 # TODO: Ensure finalization on fatal errors or interrupts
68 finalize! if initialized?