Class: MindControl::REPL::CoollineAdapter

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

Overview

Adapter for Coolline for use with Pry.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ CoollineAdapter

Returns a new instance of CoollineAdapter.

Parameters:

  • stdin (IO)

    The object to use for input.

  • stdout (IO)

    The object to use for output.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mind_control/repl.rb', line 61

def initialize( input, output )
  # Setup Coolline
  @cool = Coolline.new do |cool|
    cool.input  = input
    cool.output = output
    cool.word_boundaries = [ " ", "\t", ",", ";", '"', "'", "`", "<", ">", "=", ";", "|", "{", "}", "(", ")", "-" ]

    # By default Coolline will kill host program on Ctrl+c. Override it.
    ctrl_c_handler = cool.handlers.find { |handler| handler.char == ?\C-c }
    ctrl_c_handler.block = lambda { |instance|
      # XXX: Just close Pry
      instance.instance_variable_set "@should_exit", true
    }
  end
end

Instance Attribute Details

#coolObject (readonly)

Returns the value of attribute cool.



55
56
57
# File 'lib/mind_control/repl.rb', line 55

def cool
  @cool
end

Instance Method Details

#completion_proc=(proc) ⇒ Object



96
97
98
99
100
# File 'lib/mind_control/repl.rb', line 96

def completion_proc=( proc )
  cool.completion_proc = proc do
    proc.call cool.completed_word
  end
end

#getchFixnum

Read char from input in raw mode.#

Returns:

  • (Fixnum)


92
93
94
# File 'lib/mind_control/repl.rb', line 92

def getch
  cool.input.getch
end

#readline(prompt) ⇒ String

Read user input with given prompt.

Parameters:

  • prompt (String)

Returns:

  • (String)


83
84
85
# File 'lib/mind_control/repl.rb', line 83

def readline( prompt )
  cool.readline prompt
end