Class: Vedeu::Input::Capture

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reader) ⇒ Vedeu::Input::Input

Returns a new instance of Vedeu::Input::Input.

Parameters:

  • reader (IO)

    An object that responds to ‘#read`. Typically, this is Vedeu::Terminal.



23
24
25
# File 'lib/vedeu/input/capture.rb', line 23

def initialize(reader)
  @reader = reader
end

Instance Attribute Details

#readerIO (readonly, protected)

Returns:

  • (IO)


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).

Parameters:

  • reader (IO)

    An object that responds to ‘#read`. Typically, this is Vedeu::Terminal.

Returns:

  • (Array|String|Symbol)


14
15
16
# File 'lib/vedeu/input/capture.rb', line 14

def self.read(reader)
  new(reader).read
end

Instance Method Details

#inputString (private) Also known as: command

Returns the input from the terminal.

Returns:

  • (String)


65
66
67
# File 'lib/vedeu/input/capture.rb', line 65

def input
  @input ||= reader.read
end

#keypressString|Symbol (private)

Returns the translated (when possible) keypress(es).

Returns:

  • (String|Symbol)


56
57
58
59
60
# File 'lib/vedeu/input/capture.rb', line 56

def keypress
  key = input

  Vedeu::Input::Translator.translate(key)
end

#readArray|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.

Returns:

  • (Array|String|Symbol)


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