module RETerm::ComponentInput
Helper mixin defining standard input controls for custom components. 'In House' components included in the project may used this to standarding their usage.
Public Instance Methods
bind_key(key, kcb)
click to toggle source
# 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)
click to toggle source
Helper to be internally invoked by component on activation
# 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)
click to toggle source
# File lib/reterm/mixins/component_input.rb, line 69 def key_bound?(key) @bound_keys ||= {} @bound_keys.key?(key) end
on_dec()
click to toggle source
May be overridden in subclass, invoked when the user requests a decrement
# File lib/reterm/mixins/component_input.rb, line 19 def on_dec end
on_enter()
click to toggle source
May be overridden in subclass, invoked when the user inputs the enter key (unless quit_on_enter is true)
# File lib/reterm/mixins/component_input.rb, line 24 def on_enter end
on_inc()
click to toggle source
May be overridden in subclass, invoked when the user requests an 'increment'
# File lib/reterm/mixins/component_input.rb, line 14 def on_inc end
on_key(ch)
click to toggle source
May be overridden in subclass, invoked with every key entered
# File lib/reterm/mixins/component_input.rb, line 28 def on_key(ch) end
Private Instance Methods
invoke_key_bindings(key)
click to toggle source
# File lib/reterm/mixins/component_input.rb, line 81 def invoke_key_bindings(key) @bound_keys[key].each { |b| b.call self, key } end
next_ch(input)
click to toggle source
# File lib/reterm/mixins/component_input.rb, line 76 def next_ch(input) return sync_getch if input.empty? input.shift end