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
19 # The Y co-ordinate of the top left corner of this `Window`'s bounding box
21 # The X co-ordinate of the top left corner of this `Window`'s bounding box
23 # The height in lines of this `Window`'s bounding box
25 # The width in columns of this `Window`'s bounding box
28 # The actual window object as returned by Ncurses
31 # The `Terminal` that this `Window` pertains to
34 # ====================
35 # = Setup / Teardown =
36 # ====================
39 # Responsible for creating a new `Window`, this will also take care of
40 # initializing Ncurses if necessary.
41 def initialize opts = Hash.new
44 @wrapee = ::Ncurses.newwin(
45 opts[:height] ? @height = opts[:height] : ::Ncurses.LINES,
46 opts[:width] ? @width = opts[:width] : ::Ncurses.COLS,
47 opts[:top] ? @top = opts[:top] : 0,
48 opts[:left] ? @left = opts[:left] : 0)
50 (@owner = Terminal.current).windows << self
54 # Destroys the `wrapee` of this `Window`, and removes this `Window`
55 # from its owning `Terminal`'s `#windows`.
57 ::Ncurses.delwin(@wrapee)
59 @owner.windows.delete self
67 # Prints a string to the window
74 # Prints a string, followed by a newline, to the window
76 self.print string.to_s + "\n"