class RETerm::Component

A Component is a generic widget container associated with a window. Subclasses each implement a specific UI artifact.

Attributes

activatable[W]
activate_focus[W]
highlight_focus[W]
window[R]

Public Class Methods

new(args={}) click to toggle source
# 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

activatable?() click to toggle source

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
activate!(*input) click to toggle source

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
activate_focus?() click to toggle source
# File lib/reterm/component.rb, line 103
def activate_focus?
  defined?(@activate_focus) && @activate_focus
end
cdk?() click to toggle source

Overridden by CDK components

# File lib/reterm/component.rb, line 123
def cdk?
  false
end
colored?() click to toggle source

Return a boolean indicating if a {ColorPair} has been assign to component

# File lib/reterm/component.rb, line 48
def colored?
  !!@colors
end
colors=(c) click to toggle source

Assign the specified {ColorPair} to the component

# File lib/reterm/component.rb, line 53
def colors=(c)
  @colors = c
end
deactivate!() click to toggle source

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
deactivate?() click to toggle source

Flag indicating that this component should be deactivated

# File lib/reterm/component.rb, line 84
def deactivate?
  !!(@deactivate ||= false)
end
distance_from(c) click to toggle source
# File lib/reterm/component.rb, line 17
def distance_from(c)
  window.distance_from(c.kind_of?(Window) ? c : c.window)
end
extra_padding() click to toggle source

Return extra padding to be given to component

# File lib/reterm/component.rb, line 108
def extra_padding
  (activatable? && highlight_focus?) ? 3 : 0
end
finalize!() click to toggle source

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
highlight_focus?() click to toggle source

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
reactivate!() click to toggle source

Reset deactivation

# File lib/reterm/component.rb, line 89
def reactivate!
  @deactivate = false
end
requested_cols() click to toggle source

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
requested_rows() click to toggle source

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
resize(rows, cols) click to toggle source

Dispatch to window.resize

# File lib/reterm/component.rb, line 117
def resize(rows, cols)
  window.resize(rows, cols)
  self
end
sync!() click to toggle source

Method to periodically synchronize component if needed

# File lib/reterm/component.rb, line 113
def sync!
end
sync_getch() click to toggle source
# 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
window=(w) click to toggle source
# File lib/reterm/component.rb, line 11
def window=(w)
  @window = w
  dispatch(:window_assigned)
  w
end