Class: WindowTerminal::WindowManager

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeWindowManager

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

#pagesObject (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.

Raises:

  • (ArgumentError)


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.

Raises:

  • (ArgumentError)


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

#hideObject

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.

Raises:

  • (ArgumentError)


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

#renderObject

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