module JazzHands

Constants

VERSION

Public Class Methods

enable_syntax_highlighting_as_you_type()
enable_syntax_highlighting_as_you_type!() click to toggle source

Enable syntax highlighting as you type in the Rails console via coolline and coderay (MRI 1.9.3+ only). Disabled by default as it’s a bit buggy.

Call from a Rails initializer:

JazzHands.enable_syntax_highlighting_as_you_type!
# File lib/jazz_hands.rb, line 40
def enable_syntax_highlighting_as_you_type!
  raise 'Syntax highlighting only supported on 1.9.3+' unless RUBY_VERSION >= '1.9.3'

  # Use coolline with CodeRay for syntax highlighting as you type.
  # Only works on >= 1.9.3 because coolline depends on io/console.

  require 'coolline'
  require 'coderay'

  Pry.config.input = Coolline.new do |c|
    c.transform_proc = proc do
      CodeRay.scan(c.line, :ruby).term
    end

    c.completion_proc = proc do
      word = c.completed_word
      Object.constants.map(&:to_s).select { |w| w.start_with? word }
    end
  end
end