Parent

Files

Class/Module Index [+]

Quicksearch

Interactive::InputState

Wrap around the input options, the current answer, and the current position.

Passed to handlers, which are expected to mutate answer and position as they handle incoming events.

Attributes

answer[RW]
options[RW]
position[RW]

Public Class Methods

new(options = {}, answer = "", position = 0) click to toggle source
# File lib/interact/interactive.rb, line 35
def initialize(options = {}, answer = "", position = 0)
  @options = options
  @answer = answer
  @position = position
  @done = false
end

Public Instance Methods

back(x) click to toggle source
# File lib/interact/interactive.rb, line 65
def back(x)
  return if x == 0

  print("\b" * (x * char_size))

  @position -= x
end
censor(what) click to toggle source
# File lib/interact/interactive.rb, line 52
def censor(what)
  if with = @options[:echo]
    with * what.size
  else
    what
  end
end
clear(x) click to toggle source
# File lib/interact/interactive.rb, line 73
def clear(x)
  return if x == 0

  print(" " * (x * char_size))

  @position += x

  back(x)
end
display(what) click to toggle source
# File lib/interact/interactive.rb, line 60
def display(what)
  print(censor(what))
  @position += what.size
end
done!() click to toggle source

Call to signal to the input reader that it can stop.

# File lib/interact/interactive.rb, line 43
def done!
  @done = true
end
done?() click to toggle source

Is the input finished/complete?

# File lib/interact/interactive.rb, line 48
def done?
  @done
end
goto(pos) click to toggle source
# File lib/interact/interactive.rb, line 83
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.