Module: PryCoolline

Defined in:
lib/pry-coolline/version.rb,
lib/pry-coolline/wrapper.rb,
lib/pry-coolline/paren_match.rb

Defined Under Namespace

Modules: ParenMatch Classes: Wrapper

Constant Summary collapse

VERSION =
"0.2.6"

Class Method Summary collapse

Class Method Details

.apply_paren_matching(code, pos) ⇒ Object

Adds paren matching code for the parens that are matched at a given position. The color codes are determined using Pry.config.

Parameters:

  • code (String)
  • pos (Integer)


267
268
269
270
271
272
273
274
275
276
277
# File 'lib/pry-coolline/paren_match.rb', line 267

def apply_paren_matching(code, pos)
  pair = ParenMatch.pair_at(code, pos)

  color = pair.correctly_matched? ? Pry.config.coolline_matched_paren :
    Pry.config.coolline_mismatched_paren

  pair.insertion_positions.each do |before, after|
    code.insert after, "\e[0m"
    code.insert before, color
  end
end

.make_coollineCoolline

Returns:

  • (Coolline)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pry-coolline/wrapper.rb', line 25

def make_coolline
  Coolline.new do |cool|
    cool.completion_word_boundaries =
      [" ", "\t", ",", ";", '"', "'", "`", "<", ">",
       "=", ";", "|", "{", "}", "(", ")", "-"]

    cool.word_boundaries = cool.completion_word_boundaries +
      [".", ":"]

    pry_history_file =
      if Gem::Version.new(Pry::VERSION) >= Gem::Version.new("0.13")
        Pry.config.history_file
      else
        Pry.config.history.file
      end

    # bring saved history into coolline
    cool.history_file = File.expand_path(pry_history_file)

    cool.transform_proc = proc do
      if Pry.color
        code = CodeRay.scan(cool.line, :ruby).term

        if Pry.config.coolline_paren_matching
          PryCoolline.apply_paren_matching(code, cool.pos)
        end

        code
      else
        cool.line
      end
    end
  end
end

.make_inputWrapper

Returns An object usable as an input object for Pry.

Returns:

  • (Wrapper)

    An object usable as an input object for Pry.



61
62
63
# File 'lib/pry-coolline/wrapper.rb', line 61

def make_input
  Wrapper.new make_coolline
end