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
-
#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 either a ‘:command’ event with the command when the reader is in cooked mode, or when in raw mode, the keypress event with the key(s) pressed.
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)
49 50 51 |
# File 'lib/vedeu/input/capture.rb', line 49 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
#input ⇒ String (private) Also known as: command
Returns the input from the terminal.
65 66 67 |
# File 'lib/vedeu/input/capture.rb', line 65 def input @input ||= reader.read end |
#keypress ⇒ String|Symbol (private)
Returns the translated (when possible) keypress(es).
56 57 58 59 60 |
# File 'lib/vedeu/input/capture.rb', line 56 def keypress key = input Vedeu::Input::Translator.translate(key) end |
#read ⇒ Array|String|Symbol
Triggers either a ‘:command’ event with the command when the reader is in cooked mode, or when in raw mode, the keypress event with the key(s) pressed.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/input/capture.rb', line 32 def read if reader.raw_mode? Vedeu.trigger(:_keypress_, keypress) elsif reader.fake_mode? Vedeu.trigger(:_editor_, keypress) else Vedeu.trigger(:_command_, command) end end |