Class: Remedy::Interaction
- Inherits:
-
Object
- Object
- Remedy::Interaction
- Defined in:
- lib/remedy/interaction.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
- #confirm(message = 'Confirm?') ⇒ Object
- #debug! ⇒ Object
- #display(key) ⇒ Object
- #get_key ⇒ Object
-
#initialize(message = nil) ⇒ Interaction
constructor
A new instance of Interaction.
- #loop ⇒ Object
- #quit! ⇒ Object
Constructor Details
#initialize(message = nil) ⇒ Interaction
Returns a new instance of Interaction.
6 7 8 |
# File 'lib/remedy/interaction.rb', line 6 def initialize = nil @message = end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
10 11 12 |
# File 'lib/remedy/interaction.rb', line 10 def @message end |
Instance Method Details
#confirm(message = 'Confirm?') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/remedy/interaction.rb', line 12 def confirm = 'Confirm?' ANSI.cursor.home! ANSI.command.clear_line! print , ' y/n ' if Keyboard.get === :y then yield if block_given? true else false end end |
#debug! ⇒ Object
36 37 38 39 |
# File 'lib/remedy/interaction.rb', line 36 def debug! require 'pry' binding.pry end |
#display(key) ⇒ Object
41 42 43 44 |
# File 'lib/remedy/interaction.rb', line 41 def display key ANSI.command.clear_line! print " -- You pressed: #{key.inspect}" end |
#get_key ⇒ Object
67 68 69 70 71 72 |
# File 'lib/remedy/interaction.rb', line 67 def get_key print " -- #{}" if ANSI.cursor.hide! key = Keyboard.get end |
#loop ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/remedy/interaction.rb', line 46 def loop Keyboard.raise_on_control_c! super do print " -- #{}" if ANSI.cursor.hide! key = Keyboard.get if key == ?\C-q then display key quit! elsif key == ?\C-d and defined? Pry then display key debug! end yield key end end |