Class: Vedeu::Editor::Capture
- Inherits:
-
Object
- Object
- Vedeu::Editor::Capture
- Defined in:
- lib/vedeu/editor/capture.rb
Overview
Capture input from the terminal via ‘getch’.
Constant Summary collapse
- ESCAPE_KEY_CODE =
e
27
Class Method Summary collapse
Instance Method Summary collapse
-
#click?(keys) ⇒ Boolean
private
Returns a boolean indicating whether a mouse click was received.
- #console ⇒ IO private
-
#initialize(console) ⇒ Vedeu::Editor::Capture
constructor
Returns a new instance of Vedeu::Editor::Capture.
- #keys ⇒ String private
- #read ⇒ String|Symbol
Constructor Details
#initialize(console) ⇒ Vedeu::Editor::Capture
Returns a new instance of Vedeu::Editor::Capture.
21 22 23 |
# File 'lib/vedeu/editor/capture.rb', line 21 def initialize(console) @console = console end |
Class Method Details
.read(console) ⇒ String|Symbol
13 14 15 |
# File 'lib/vedeu/editor/capture.rb', line 13 def self.read(console) new(console).read end |
Instance Method Details
#click?(keys) ⇒ Boolean (private)
Returns a boolean indicating whether a mouse click was received.
53 54 55 |
# File 'lib/vedeu/editor/capture.rb', line 53 def click?(keys) keys.start_with?("\e[M") end |
#console ⇒ IO (private)
58 59 60 |
# File 'lib/vedeu/editor/capture.rb', line 58 def console @console || Vedeu::Terminal.console end |
#keys ⇒ String (private)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vedeu/editor/capture.rb', line 33 def keys keys = console.getch if keys.ord == ESCAPE_KEY_CODE keys << console.read_nonblock(5) rescue nil keys << console.read_nonblock(4) rescue nil keys << console.read_nonblock(3) rescue nil keys << console.read_nonblock(2) rescue nil end return Vedeu::Input::Mouse.click(keys) if click?(keys) keys end |
#read ⇒ String|Symbol
26 27 28 |
# File 'lib/vedeu/editor/capture.rb', line 26 def read Vedeu::Input::Translator.translate(keys) end |