module RETerm::CDKComponent

Mixin used by CDK based component defining cdk-specific helpers

Public Instance Methods

_component() click to toggle source

Should be implemented in subclass to initialize component

# File lib/reterm/mixins/cdk_component.rb, line 19
def _component
  raise "NotImplemented"
end
activatable?() click to toggle source

CDK components may be activated

# File lib/reterm/mixins/cdk_component.rb, line 76
def activatable?
  !defined?(@activatable) || @activatable
end
activate!(*input) click to toggle source

Invoke CDK activation routine

# File lib/reterm/mixins/cdk_component.rb, line 81
def activate!(*input)
  dispatch :activated
  component.resetExitType

  r = nil

  while [:EARLY_EXIT, :NEVER_ACTIVATED, :TIMEOUT].include?(component.exit_type) &&
        !shutdown?
    r = component.activate(input)
    run_sync! if sync_enabled?
  end

  dispatch :deactivated
  r
end
bind_key(key, kcb=nil, &bl) click to toggle source

Override bind_key to use cdk bindings mechanism

# File lib/reterm/mixins/cdk_component.rb, line 108
def bind_key(key, kcb=nil, &bl)
  kcb = bl if kcb.nil? && !bl.nil?

  cb = lambda do |cdktype, widget, component, key|
    kcb.call component, key
  end

  component.bind(:ENTRY, key, cb, self)
end
cdk?() click to toggle source

Boolean indicating this component is a cdk component

# File lib/reterm/mixins/cdk_component.rb, line 14
def cdk?
  true
end
colors=(c) click to toggle source

Assign {ColorPair} to component

Calls superclass method
# File lib/reterm/mixins/cdk_component.rb, line 61
def colors=(c)
  super
  component.setBackgroundColor("</#{@colors.id}>")
end
component() click to toggle source

Return completely initialized CDK component

# File lib/reterm/mixins/cdk_component.rb, line 33
def component
  enable_cdk!
  @component ||= begin
    c = _component
    c.setBackgroundColor("</#{@colors.id}>") if colored?
    c.timeout(SYNC_TIMEOUT) if sync_enabled? # XXX
    c.title_attrib = @title_attrib if @title_attrib
    c
  end
end
deactivate!() click to toggle source
# File lib/reterm/mixins/cdk_component.rb, line 97
def deactivate!
  component.activate [CDK::KEY_ESC]
  dispatch :deactivated
end
draw!() click to toggle source

Invoke CDK draw routine

# File lib/reterm/mixins/cdk_component.rb, line 67
def draw!
  component.draw([])
end
early_exit?() click to toggle source

Return boolean indicating early exit occurred

# File lib/reterm/mixins/cdk_component.rb, line 50
def early_exit?
  component.exit_type == :EARLY_EXIT
end
erase() click to toggle source
# File lib/reterm/mixins/cdk_component.rb, line 71
def erase
  component.erase
end
escape_hit?() click to toggle source

Return boolean indicating if escape was hit

# File lib/reterm/mixins/cdk_component.rb, line 45
def escape_hit?
  component.exit_type == :ESCAPE_HIT
end
init?() click to toggle source
# File lib/reterm/mixins/cdk_component.rb, line 23
def init?
  !!@component
end
init_cdk(args={}) click to toggle source
# File lib/reterm/mixins/cdk_component.rb, line 4
def init_cdk(args={})
  self.title_attrib = args[:title_attrib] if args.key?(:title_attrib)
end
normal_exit?() click to toggle source

Return boolean indicating if user selection made / normal exit was invoked

# File lib/reterm/mixins/cdk_component.rb, line 56
def normal_exit?
  component.exit_type == :NORMAL
end
strip_formatting(str) click to toggle source

Remove CDK formatting from string

# File lib/reterm/mixins/cdk_component.rb, line 28
def strip_formatting(str)
  str.gsub(/<.*>/, "")
end
title_attrib=(a) click to toggle source
# File lib/reterm/mixins/cdk_component.rb, line 8
def title_attrib=(a)
  @title_attrib = a
  component.title_attrib = a if defined?(@component)
end
value() click to toggle source

Return stored value of cdk component

# File lib/reterm/mixins/cdk_component.rb, line 103
def value
  component.getValue
end