Module: RETerm::CDKComponent

Overview

Mixin used by CDK based component defining cdk-specific helpers

Instance Method Summary collapse

Instance Method Details

#_componentObject

Should be implemented in subclass to initialize component



19
20
21
# File 'lib/reterm/mixins/cdk_component.rb', line 19

def _component
  raise "NotImplemented"
end

#activatable?Boolean

CDK components may be activated

Returns:

  • (Boolean)


76
77
78
# File 'lib/reterm/mixins/cdk_component.rb', line 76

def activatable?
  !defined?(@activatable) || @activatable
end

#activate!(*input) ⇒ Object

Invoke CDK activation routine



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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) ⇒ Object

Override bind_key to use cdk bindings mechanism



108
109
110
111
112
113
114
115
116
# 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?Boolean

Boolean indicating this component is a cdk component

Returns:

  • (Boolean)


14
15
16
# File 'lib/reterm/mixins/cdk_component.rb', line 14

def cdk?
  true
end

#colors=(c) ⇒ Object

Assign RETerm::ColorPair to component



61
62
63
64
# File 'lib/reterm/mixins/cdk_component.rb', line 61

def colors=(c)
  super
  component.setBackgroundColor("</#{@colors.id}>")
end

#componentObject

Return completely initialized CDK component



33
34
35
36
37
38
39
40
41
42
# 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!Object



97
98
99
100
# File 'lib/reterm/mixins/cdk_component.rb', line 97

def deactivate!
  component.activate [CDK::KEY_ESC]
  dispatch :deactivated
end

#draw!Object

Invoke CDK draw routine



67
68
69
# File 'lib/reterm/mixins/cdk_component.rb', line 67

def draw!
  component.draw([])
end

#early_exit?Boolean

Return boolean indicating early exit occurred

Returns:

  • (Boolean)


50
51
52
# File 'lib/reterm/mixins/cdk_component.rb', line 50

def early_exit?
  component.exit_type == :EARLY_EXIT
end

#eraseObject



71
72
73
# File 'lib/reterm/mixins/cdk_component.rb', line 71

def erase
  component.erase
end

#escape_hit?Boolean

Return boolean indicating if escape was hit

Returns:

  • (Boolean)


45
46
47
# File 'lib/reterm/mixins/cdk_component.rb', line 45

def escape_hit?
  component.exit_type == :ESCAPE_HIT
end

#init?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/reterm/mixins/cdk_component.rb', line 23

def init?
  !!@component
end

#init_cdk(args = {}) ⇒ Object



4
5
6
# 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?Boolean

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

Returns:

  • (Boolean)


56
57
58
# File 'lib/reterm/mixins/cdk_component.rb', line 56

def normal_exit?
  component.exit_type == :NORMAL
end

#strip_formatting(str) ⇒ Object

Remove CDK formatting from string



28
29
30
# File 'lib/reterm/mixins/cdk_component.rb', line 28

def strip_formatting(str)
  str.gsub(/<.*>/, "")
end

#title_attrib=(a) ⇒ Object



8
9
10
11
# File 'lib/reterm/mixins/cdk_component.rb', line 8

def title_attrib=(a)
  @title_attrib = a
  component.title_attrib = a if defined?(@component)
end

#valueObject

Return stored value of cdk component



103
104
105
# File 'lib/reterm/mixins/cdk_component.rb', line 103

def value
  component.getValue
end