3 # An `Nfoiled::Terminal` is a specific set of Nfoiled windows and
4 # configuration. In the vast majority of cases, you only need one of these,
5 # and that one will be created for you by `Nfoiled::initialize`. A general
6 # user shouldn't need to deal with `Terminal` at all.
10 # An array of known `Terminal` instances
11 attr_reader :terminals
12 def terminals; @terminals ||= Array.new; end
14 # The currently active `Terminal` instance
15 attr_accessor :current
17 # The initial `Terminal` instance, if Nfoiled is initialized without an
18 # existing `Terminal`.
19 attr_accessor :default
22 # The IO object to which output will be managed
25 # The IO object on which input will be watched
28 # The type of the terminal ('vt102', 'xterm', etc)
31 # The actual terminal object as returned by Ncurses
34 # An array of known windows belonging to this Terminal
36 def windows; @windows ||= Array.new; end
39 # Responsible for creating a new `Terminal`. See `newterm(3X)`.
40 def initialize opts = Hash.new
41 { :output => STDOUT, :input => STDIN }.merge opts
42 @output = opts[:output]
46 @wrapee = ::Ncurses.newterm(opts[:term], opts[:out], opts[:in])
47 Terminal.current = self
48 Terminal.terminals << self
53 # 'Activates' a `Terminal`, destroying all windows and environment from
54 # the current `Terminal` and replacing it with those of this one.
56 ::Ncurses.set_term(@wrapee)
57 previous, Terminal.current = Terminal.current, self
62 # Simply calls `#activate!` if this `Terminal` isn't already active.
64 activate! unless active?
68 # Simply cheks if `Terminal.current == self`
70 Terminal.current == self
74 # Destroys the `wrapee` of this `Terminal`, and removes this `Terminal`
75 # from `Terminal.terminals`
79 ::Ncurses.delscreen(@wrapee)
80 Terminal.terminals.delete self
82 old_term.activate if old_term