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
- #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
#console ⇒ IO (private)
59 60 61 |
# File 'lib/vedeu/editor/capture.rb', line 59 def console @console || Vedeu::Terminal.console end |
#keys ⇒ String (private)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vedeu/editor/capture.rb', line 33 def keys keys = console.getch if keys.ord == ESCAPE_KEY_CODE @chars = 3 begin keys << console.read_nonblock(@chars) rescue IO::WaitReadable IO.select([console]) @chars -= 1 retry rescue IO::WaitWritable IO.select(nil, [console]) @chars -= 1 retry end end keys end |
#read ⇒ String|Symbol
26 27 28 |
# File 'lib/vedeu/editor/capture.rb', line 26 def read Vedeu::Input::Translator.translate(keys) end |