class RETerm::Component
A Component
is a generic widget container associated with a window. Subclasses each implement a specific UI artifact.
Attributes
Public Class Methods
# File lib/reterm/component.rb, line 21 def initialize(args={}) self.highlight_focus = args[:highlight_focus] if args.key?(:highlight_focus) self.activate_focus = args[:activate_focus] if args.key?(:activate_focus) self.activatable = args[:activatable] if args.key?(:activatable) init_cdk(args) if cdk? end
Public Instance Methods
Returns a boolean indicating if the user should be able to focus on and activate the component. By default this is false, but interactive components should override and return true.
# File lib/reterm/component.rb, line 63 def activatable? defined?(@activatable) && @activatable end
Actual activation mechanism, invoked by the navigation logic when the user has selected an activatable? component. Should be overriden by interactive subcomponents to process user inpute specific to that component
# File lib/reterm/component.rb, line 71 def activate!(*input) raise RuntimeError, "should not be activated" end
# File lib/reterm/component.rb, line 103 def activate_focus? defined?(@activate_focus) && @activate_focus end
Overridden by CDK components
# File lib/reterm/component.rb, line 123 def cdk? false end
Return a boolean indicating if a {ColorPair} has been assign to component
# File lib/reterm/component.rb, line 48 def colored? !!@colors end
Assign the specified {ColorPair} to the component
# File lib/reterm/component.rb, line 53 def colors=(c) @colors = c end
This method is invoked when component loses focus (when navigating to another component, window closed, etc). Subclasses may override to hide / cleanup resources
# File lib/reterm/component.rb, line 78 def deactivate! @deactivate = true end
Flag indicating that this component should be deactivated
# File lib/reterm/component.rb, line 84 def deactivate? !!(@deactivate ||= false) end
# File lib/reterm/component.rb, line 17 def distance_from(c) window.distance_from(c.kind_of?(Window) ? c : c.window) end
Return extra padding to be given to component
# File lib/reterm/component.rb, line 108 def extra_padding (activatable? && highlight_focus?) ? 3 : 0 end
This method is invoked to cleanup the component on shutdown. It should be be overriden by subclasses that needs to clean resources before being deallocated
# File lib/reterm/component.rb, line 43 def finalize! end
Return boolean indicating if this component should be highlighted on focus (default true)
# File lib/reterm/component.rb, line 97 def highlight_focus? !defined?(@highlight_focus) || @highlight_focus end
Reset deactivation
# File lib/reterm/component.rb, line 89 def reactivate! @deactivate = false end
This method is invoked when adding component to layout to determine cols needed
# File lib/reterm/component.rb, line 36 def requested_cols 1 end
This method is invoked when adding component to layout to determine rows needed
# File lib/reterm/component.rb, line 30 def requested_rows 1 end
Dispatch to window.resize
# File lib/reterm/component.rb, line 117 def resize(rows, cols) window.resize(rows, cols) self end
Method to periodically synchronize component if needed
# File lib/reterm/component.rb, line 113 def sync! end
# File lib/reterm/component.rb, line 127 def sync_getch c = window.sync_getch c = nil if key_bound?(c) && invoke_key_bindings(c) c end
# File lib/reterm/component.rb, line 11 def window=(w) @window = w dispatch(:window_assigned) w end