Class: PI::Cli::InteractHelper::InputState
- Defined in:
- lib/cli/interact_helper.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
Returns the value of attribute answer.
-
#options ⇒ Object
Returns the value of attribute options.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #back(x) ⇒ Object
- #censor(what) ⇒ Object
- #clear(x) ⇒ Object
- #display(what) ⇒ Object
-
#done! ⇒ Object
Call to signal to the input reader that it can stop.
-
#done? ⇒ Boolean
Is the input finished/complete?.
- #goto(pos) ⇒ Object
-
#initialize(options = {}, answer = "", position = 0) ⇒ InputState
constructor
A new instance of InputState.
Constructor Details
#initialize(options = {}, answer = "", position = 0) ⇒ InputState
Returns a new instance of InputState.
30 31 32 33 34 35 |
# File 'lib/cli/interact_helper.rb', line 30 def initialize( = {}, answer = "", position = 0) @options = @answer = answer @position = position @done = false end |
Instance Attribute Details
#answer ⇒ Object
Returns the value of attribute answer.
28 29 30 |
# File 'lib/cli/interact_helper.rb', line 28 def answer @answer end |
#options ⇒ Object
Returns the value of attribute options.
28 29 30 |
# File 'lib/cli/interact_helper.rb', line 28 def @options end |
#position ⇒ Object
Returns the value of attribute position.
28 29 30 |
# File 'lib/cli/interact_helper.rb', line 28 def position @position end |
Instance Method Details
#back(x) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/cli/interact_helper.rb', line 60 def back(x) return if x == 0 print("\b" * (x * char_size)) @position -= x end |
#censor(what) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/cli/interact_helper.rb', line 47 def censor(what) if with = @options[:echo] with * what.size else what end end |
#clear(x) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/cli/interact_helper.rb', line 68 def clear(x) return if x == 0 print(" " * (x * char_size)) @position += x back(x) end |
#display(what) ⇒ Object
55 56 57 58 |
# File 'lib/cli/interact_helper.rb', line 55 def display(what) print(censor(what)) @position += what.size end |
#done! ⇒ Object
Call to signal to the input reader that it can stop.
38 39 40 |
# File 'lib/cli/interact_helper.rb', line 38 def done! @done = true end |
#done? ⇒ Boolean
Is the input finished/complete?
43 44 45 |
# File 'lib/cli/interact_helper.rb', line 43 def done? @done end |
#goto(pos) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cli/interact_helper.rb', line 78 def goto(pos) return if pos == position if pos > position display(answer[position .. pos]) else print("\b" * (position - pos) * char_size) end @position = pos end |