Module: RETerm::ComponentInput
- Includes:
- CommonControls, CommonKeys
- Defined in:
- lib/reterm/mixins/component_input.rb
Overview
Helper mixin defining standard input controls for custom components. ‘In House’ components included in the project may used this to standarding their usage.
Constant Summary
Constants included from CommonKeys
RETerm::CommonKeys::DEC_CONTROLS, RETerm::CommonKeys::ENTER_CONTROLS, RETerm::CommonKeys::INC_CONTROLS, RETerm::CommonKeys::QUIT_CONTROLS
Instance Attribute Summary
Attributes included from CommonControls
Instance Method Summary collapse
- #bind_key(key, kcb) ⇒ Object
-
#handle_input(*input) ⇒ Object
Helper to be internally invoked by component on activation.
- #key_bound?(key) ⇒ Boolean
-
#on_dec ⇒ Object
May be overridden in subclass, invoked when the user requests a decrement.
-
#on_enter ⇒ Object
May be overridden in subclass, invoked when the user inputs the enter key (unless quit_on_enter is true).
-
#on_inc ⇒ Object
May be overridden in subclass, invoked when the user requests an ‘increment’.
-
#on_key(ch) ⇒ Object
May be overridden in subclass, invoked with every key entered.
Methods included from CommonControls
Instance Method Details
#bind_key(key, kcb) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/reterm/mixins/component_input.rb', line 62 def bind_key(key, kcb) @bound_keys ||= {} @bound_keys[key] ||= [] @bound_keys[key] << kcb nil end |
#handle_input(*input) ⇒ Object
Helper to be internally invoked by component on activation
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/reterm/mixins/component_input.rb', line 32 def handle_input(*input) while ch = next_ch(input) quit = QUIT_CONTROLS.include?(ch) enter = ENTER_CONTROLS.include?(ch) inc = INC_CONTROLS.include?(ch) dec = DEC_CONTROLS.include?(ch) break if shutdown? || (quit && (!enter || quit_on_enter?)) if enter on_enter elsif inc on_inc elsif dec on_dec end if key_bound?(ch) invoke_key_bindings(ch) end on_key(ch) end ch end |
#key_bound?(key) ⇒ Boolean
69 70 71 72 |
# File 'lib/reterm/mixins/component_input.rb', line 69 def key_bound?(key) @bound_keys ||= {} @bound_keys.key?(key) end |
#on_dec ⇒ Object
May be overridden in subclass, invoked when the user requests a decrement
19 20 |
# File 'lib/reterm/mixins/component_input.rb', line 19 def on_dec end |
#on_enter ⇒ Object
May be overridden in subclass, invoked when the user inputs the enter key (unless quit_on_enter is true)
24 25 |
# File 'lib/reterm/mixins/component_input.rb', line 24 def on_enter end |
#on_inc ⇒ Object
May be overridden in subclass, invoked when the user requests an ‘increment’
14 15 |
# File 'lib/reterm/mixins/component_input.rb', line 14 def on_inc end |
#on_key(ch) ⇒ Object
May be overridden in subclass, invoked with every key entered
28 29 |
# File 'lib/reterm/mixins/component_input.rb', line 28 def on_key(ch) end |