Class: WindowTerminal::WindowManager
- Inherits:
-
Object
- Object
- WindowTerminal::WindowManager
- Defined in:
- lib/accu-window.rb
Overview
Makes handling and switching between Window objects simpler by creating an API that allows for objects to be assigned to pages, which can, in turn, be displayed, hidden, or deleted at leisure.
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
-
#display_page(num = 1) ⇒ Object
Displays the page at the number specified; defaults to one.
-
#get_page_text(num) ⇒ Object
Gets all Text and Text subclass objects on the page given and returns them all as an array.
-
#hide ⇒ Object
An alias for hide_page which always passes the current displayed page number, if it exists.
-
#hide_page(num = nil) ⇒ Object
Hides a page by a number, defaults to doing nothing.
-
#initialize ⇒ WindowManager
constructor
Initializes a WindowManager object.
-
#new_page(*items) ⇒ Object
Creates a new page with the passed arguments and returns the page number.
-
#remove_page(num) ⇒ Object
Delete a page by page number.
-
#render ⇒ Object
An alias for the WindowTerminal method screen_render.
-
#show(num = 1) ⇒ Object
Alias for display_page.
Constructor Details
#initialize ⇒ WindowManager
Initializes a WindowManager object.
450 451 452 453 |
# File 'lib/accu-window.rb', line 450 def initialize() @pages = [] @displayed_page = nil end |
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
447 448 449 |
# File 'lib/accu-window.rb', line 447 def pages @pages end |
Instance Method Details
#display_page(num = 1) ⇒ Object
Displays the page at the number specified; defaults to one.
470 471 472 473 474 475 476 477 |
# File 'lib/accu-window.rb', line 470 def display_page(num=1) raise(ArgumentError, "Argument 1 must be a valid integer!") if (not (num.is_a? Fixnum)) hide_page(@displayed_page) @pages[num-1].each { |item| WindowTerminal.add_window(item) } @displayed_page = num end |
#get_page_text(num) ⇒ Object
Gets all Text and Text subclass objects on the page given and returns them all as an array.
518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/accu-window.rb', line 518 def get_page_text(num) raise(ArgumentError, "Argument 1 must be a valid integer!") if (not (num.is_a? Fixnum)) array = [] @pages[num-1].each {|window| array << window.objects.dup array[-1].each {|item| if (not (item.respond_to? :set_text)) then array[-1].delete(item) end } } return array end |
#hide ⇒ Object
An alias for hide_page which always passes the current displayed page number, if it exists.
502 503 504 505 506 |
# File 'lib/accu-window.rb', line 502 def hide() if @displayed_page then hide_page(@displayed_page) end end |
#hide_page(num = nil) ⇒ Object
Hides a page by a number, defaults to doing nothing.
486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/accu-window.rb', line 486 def hide_page(num=nil) if num then raise(ArgumentError, "Argument 1 must be a valid integer!") if (not (num.is_a? Fixnum)) if num == @displayed_page then @pages[num-1].each { |item| WindowTerminal.remove_window(item) } @displayed_page = nil end end end |
#new_page(*items) ⇒ Object
Creates a new page with the passed arguments and returns the page number.
458 459 460 461 462 463 464 465 466 |
# File 'lib/accu-window.rb', line 458 def new_page(*items) @pages << [] items.each { |item| if item.is_a? Window then @pages[-1] << item end } return @pages.length end |
#remove_page(num) ⇒ Object
Delete a page by page number.
509 510 511 512 513 |
# File 'lib/accu-window.rb', line 509 def remove_page(num) raise(ArgumentError, "Argument 1 must be a valid integer!") if (not (num.is_a? Fixnum)) hide_page(num) @pages.delete_at(num-1) end |
#render ⇒ Object
An alias for the WindowTerminal method screen_render.
534 535 536 |
# File 'lib/accu-window.rb', line 534 def render() WindowTerminal.screen_render end |
#show(num = 1) ⇒ Object
Alias for display_page.
480 481 482 |
# File 'lib/accu-window.rb', line 480 def show(num=1) display_page(num) end |