Class: Doublespeak::Repl

Inherits:
Object
  • Object
show all
Defined in:
lib/doublespeak/repl.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_source, options = {}) ⇒ Repl

Returns a new instance of Repl.

Raises:

  • (ArgumentError)


3
4
5
6
# File 'lib/doublespeak/repl.rb', line 3

def initialize(data_source, options = {})
  raise ArgumentError.new("Must provide a data_source") if data_source.nil?
  @core = Core.new(data_source, options)
end

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/doublespeak/repl.rb', line 8

def run
  continue = true

  while continue
    core.render
    core.display.set_cursor_visible(core.query.empty?)

    char = core.display.read
    case char
    when "\r"
      if core.saved_candidates.present?
        continue = false
        core.finish_up
      end

    when "\e[A"
      core.increment_selection(-1)

    when "\e[B"
      core.increment_selection(+1)

    when "\u007F"
      core.back_up
      core.find_candidates

    when /^[a-zA-Z0-9 ]/
      core.entry(char)
      core.find_candidates
    end
  end
end