Class: Vedeu::Input::Capture Private
- Inherits:
-
Object
- Object
- Vedeu::Input::Capture
- Extended by:
- Forwardable
- Includes:
- Common
- Defined in:
- lib/vedeu/input/capture.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Captures input from the user terminal via ‘getch’ and translates special characters into symbols.
Class Method Summary collapse
-
.read ⇒ Array|String|Symbol
private
Instantiate Vedeu::Input::Input and capture keypress(es).
Instance Method Summary collapse
-
#click?(keys) ⇒ Boolean
private
private
Returns a boolean indicating whether a mouse click was received.
-
#command ⇒ String
private
private
Takes input from the user via the keyboard.
- #console ⇒ IO private private
-
#initialize ⇒ Vedeu::Input::Input
constructor
private
Returns a new instance of Vedeu::Input::Input.
-
#input ⇒ String
private
private
Takes input from the user via the keyboard.
-
#interface ⇒ Vedeu::Interfaces::Interface
private
private
Returns the named interface/view from the interfaces repository.
-
#keypress ⇒ String|Symbol
private
private
Returns the translated (when possible) keypress(es).
-
#name ⇒ NilClass|Symbol|String
private
private
The name of the model, the target model or the name of the associated model.
-
#read ⇒ Array|String|Symbol
private
Triggers various events dependent on the terminal mode.
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Constructor Details
#initialize ⇒ Vedeu::Input::Input
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Input::Input.
35 |
# File 'lib/vedeu/input/capture.rb', line 35 def initialize; end |
Class Method Details
.read ⇒ Array|String|Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiate Vedeu::Input::Input and capture keypress(es).
28 29 30 |
# File 'lib/vedeu/input/capture.rb', line 28 def self.read new.read end |
Instance Method Details
#click?(keys) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a mouse click was received.
121 122 123 124 125 |
# File 'lib/vedeu/input/capture.rb', line 121 def click?(keys) return false if keys.nil? || symbol?(keys) keys.is_a?(Vedeu::Cursors::Cursor) || keys.start_with?("\e[M") end |
#command ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Takes input from the user via the keyboard. Accepts special keys like the F-Keys etc, by capturing the entire sequence.
136 137 138 |
# File 'lib/vedeu/input/capture.rb', line 136 def command console.gets.chomp end |
#console ⇒ IO (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
128 129 130 |
# File 'lib/vedeu/input/capture.rb', line 128 def console @console ||= Vedeu::Terminal.console end |
#input ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Takes input from the user via the keyboard. Accepts special keys like the F-Keys etc, by capturing the entire sequence.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/vedeu/input/capture.rb', line 99 def input keys = Vedeu::Input::Raw.read if click?(keys) Vedeu::Input::Mouse.click(keys) else keys end end |
#interface ⇒ Vedeu::Interfaces::Interface (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the named interface/view from the interfaces repository.
112 113 114 |
# File 'lib/vedeu/input/capture.rb', line 112 def interface Vedeu.interfaces.by_name(name) end |
#keypress ⇒ String|Symbol (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the translated (when possible) keypress(es).
91 92 93 |
# File 'lib/vedeu/input/capture.rb', line 91 def keypress Vedeu::Input::Translator.translate(input) end |
#name ⇒ NilClass|Symbol|String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The name of the model, the target model or the name of the associated model.
141 142 143 |
# File 'lib/vedeu/input/capture.rb', line 141 def name Vedeu.focus end |
#read ⇒ Array|String|Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vedeu/input/capture.rb', line 54 def read Vedeu.log(type: :input, message: "Waiting for user input...\n") if raw_mode? Vedeu.trigger(:_keypress_, keypress) elsif fake_mode? @key ||= keypress if @key.nil? nil elsif click?(@key) Vedeu.trigger(:_mouse_event_, @key) elsif Vedeu::Input::Mapper.registered?(@key, name) Vedeu.trigger(:_keypress_, @key, name) elsif interface.editable? Vedeu.trigger(:_editor_, @key) else Vedeu.trigger(:key, @key) end elsif cooked_mode? Vedeu.trigger(:_command_, command) end end |