Class: Vedeu::Input::Capture
- Inherits:
-
Object
- Object
- Vedeu::Input::Capture
- Defined in:
- lib/vedeu/input/capture.rb
Overview
Captures input from the user via Terminal#input and translates special characters into symbols.
Instance Attribute Summary collapse
- #reader ⇒ IO readonly protected
Class Method Summary collapse
-
.read(reader) ⇒ Array|String|Symbol
Instantiate Vedeu::Input::Input and capture keypress(es).
Instance Method Summary collapse
-
#click?(key) ⇒ Boolean
private
Returns a boolean indicating whether a mouse click was received.
-
#initialize(reader) ⇒ Vedeu::Input::Input
constructor
Returns a new instance of Vedeu::Input::Input.
-
#input ⇒ String
(also: #command)
private
Returns the input from the terminal.
-
#keypress ⇒ String|Symbol
private
Returns the translated (when possible) keypress(es).
-
#read ⇒ Array|String|Symbol
Triggers various events dependent on the terminal mode.
Constructor Details
#initialize(reader) ⇒ Vedeu::Input::Input
Returns a new instance of Vedeu::Input::Input.
23 24 25 |
# File 'lib/vedeu/input/capture.rb', line 23 def initialize(reader) @reader = reader end |
Instance Attribute Details
#reader ⇒ IO (readonly, protected)
76 77 78 |
# File 'lib/vedeu/input/capture.rb', line 76 def reader @reader end |
Class Method Details
.read(reader) ⇒ Array|String|Symbol
Instantiate Vedeu::Input::Input and capture keypress(es).
14 15 16 |
# File 'lib/vedeu/input/capture.rb', line 14 def self.read(reader) new(reader).read end |
Instance Method Details
#click?(key) ⇒ Boolean (private)
Returns a boolean indicating whether a mouse click was received.
85 86 87 88 89 |
# File 'lib/vedeu/input/capture.rb', line 85 def click?(key) return false if key.is_a?(Symbol) key.is_a?(Vedeu::Cursors::Cursor) || key.start_with?("\e[M") end |
#input ⇒ String (private) Also known as: command
Returns the input from the terminal.
103 104 105 |
# File 'lib/vedeu/input/capture.rb', line 103 def input @input ||= reader.read end |
#keypress ⇒ String|Symbol (private)
Returns the translated (when possible) keypress(es).
94 95 96 97 98 |
# File 'lib/vedeu/input/capture.rb', line 94 def keypress key = input @keypress ||= Vedeu::Input::Translator.translate(key) end |
#read ⇒ Array|String|Symbol
Triggers various events dependent on the terminal mode.
-
When in raw mode, the :keypress event is triggered with the key(s) pressed.
-
When in fake mode, the keypress will be checked against the keymap relating to the interface/view currently in focus.
-
If registered, the :keypress event is triggered with the key(s) pressed.
-
If the keypress is not registered, we check whether the interface in focus is editable, if so, the :editor event is triggered.
-
Otherwise, the :key event is triggered for the client application to handle.
-
-
When in cooked mode, the :command event is triggered with the input given.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vedeu/input/capture.rb', line 44 def read if click?(keypress) Vedeu.trigger(:_mouse_event_, keypress) elsif reader.raw_mode? Vedeu.trigger(:_keypress_, keypress) elsif reader.fake_mode? name = Vedeu.focus interface = Vedeu.interfaces.by_name(name) key = keypress if Vedeu::Input::Mapper.registered?(key, name) Vedeu.trigger(:_keypress_, key, name) elsif interface.editable? Vedeu.trigger(:_editor_, key) else Vedeu.trigger(:key, key) end else Vedeu.trigger(:_command_, command) end end |