3 # An `Nfoiled::Window` is a "box" in the terminal to which output can be
4 # printed and from which input can be received. A basic Nfoiled application
5 # will utilize only one of these, a single `Window` covering the entirety
6 # of the `Terminal`'s available area.
10 # This is simply an accessor for all the windows on the current Terminal.
12 def windows; Terminal.current.windows; end
15 # The Y co-ordinate of the top left corner of this `Window`'s bounding box
17 # The X co-ordinate of the top left corner of this `Window`'s bounding box
19 # The height in lines of this `Window`'s bounding box
21 # The width in columns of this `Window`'s bounding box
24 # The actual window object as returned by Ncurses
27 # The `Terminal` that this `Window` pertains to
31 # Responsible for creating a new `Window`, this will also take care of
32 # initializing Ncurses if necessary.
33 def initialize opts = Hash.new
36 @wrapee = ::Ncurses.newwin(
37 opts[:height] ? @height = opts[:height] : ::Ncurses.LINES,
38 opts[:width] ? @width = opts[:width] : ::Ncurses.COLS,
39 opts[:top] ? @top = opts[:top] : 0,
40 opts[:left] ? @left = opts[:left] : 0)
42 (@owner = Terminal.current).windows << self
46 # Prints a string to the window
53 # Prints a string, followed by a newline, to the window
55 self.print string.to_s + "\n"
59 # Destroys the `wrapee` of this `Window`, and removes this `Window`
60 # from its owning `Terminal`'s `#windows`.
62 ::Ncurses.delwin(@wrapee)
64 @owner.windows.delete self