module SpiritHands

Constants

CONFIG_KEYS
DEFAULT_COOLLINE
DEFAULT_HIRB
DEFAULT_LESS_COLORIZE
DEFAULT_LESS_SHOW_RAW_UNICODE
LESS_R
LESS_R_LONG
LESS_SHOW_RAW_BINFMT
VERSION

Attributes

coolline[W]

Set whether hirb is enabled (default: true)

Public Class Methods

app_name() click to toggle source
# File lib/spirit_hands/options.rb, line 61
def self.app_name
  if app.class.respond_to?(:parent_name) && \
     app.class.parent_name.respond_to?(:underscore)
    app.class.parent_name.underscore
  elsif app
    app.to_s
  else
    ::SpiritHands.app
  end
end
color() click to toggle source

Alias for Pry.color

# File lib/spirit_hands/options/color.rb, line 3
def color
  ::Pry.color
end
color=(v) click to toggle source
# File lib/spirit_hands/options/color.rb, line 7
def color=(v)
  ::Pry.color = v
end
config() click to toggle source
# File lib/spirit_hands/options.rb, line 72
def self.config
  c = CONFIG_KEYS.map do |k|
    if k == :app
      [k, app.to_s]
    else
      [k, public_send(k)]
    end
  end
  Hash[c]
end
coolline() click to toggle source

Is coolline enabled?

# File lib/spirit_hands/options/coolline.rb, line 4
def coolline
  @coolline = DEFAULT_COOLLINE if !instance_variable_defined?(:@coolline) || @coolline.nil?
  @coolline
end
hirb() click to toggle source

Is hirb enabled?

# File lib/spirit_hands/options/hirb.rb, line 6
def hirb
  ::Hirb.enabled?
end
hirb=(h) click to toggle source

Set whether hirb is enabled (default: true)

# File lib/spirit_hands/options/hirb.rb, line 11
def hirb=(h)
  h = DEFAULT_HIRB if h.nil?
  if hirb != h
    if h
      ::Hirb.enable
    else
      ::Hirb.disable
    end
  end
  @hirb = !!h
end
less_colorize() click to toggle source

Allow less to display colorized output (default: true) (If, set updates LESS env var)

# File lib/spirit_hands/options/less/colorize.rb, line 12
def less_colorize
  ENV['LESS'].to_s.shellsplit.any? { |arg| arg == LESS_R_LONG || arg =~ LESS_R }
end
less_colorize=(n) click to toggle source
true: add -R to LESS env var (default)

false: remove -R from LESS env var

nil: set to default (true)
# File lib/spirit_hands/options/less/colorize.rb, line 19
def less_colorize=(n)
  n = DEFAULT_LESS_COLORIZE if n.nil?

  args = ENV['LESS'].to_s.shellsplit.map do |arg|
    next if arg == LESS_R_LONG
    if arg =~ LESS_R
      arg = $1 + $2
    end
    arg unless arg.empty?
  end
  args << '-R' if n
  new_less = args.collect.to_a.shelljoin
  ENV['LESS'] = new_less.empty? ? nil : new_less
  @less_colorize = !!n
end
less_show_raw_unicode() click to toggle source

Allow less to display colorized output (default: true) (If, set updates LESS env var)

# File lib/spirit_hands/options/less/show_raw_unicode.rb, line 10
def less_show_raw_unicode
  ENV['LESSUTFBINFMT'] == LESS_SHOW_RAW_BINFMT
end
less_show_raw_unicode=(n) click to toggle source

true: set LESSUTFBINFMT to %*c false: unset LESSUTFBINFMT String: set custom LESSUTFBINFMT nil: set default(true)

# File lib/spirit_hands/options/less/show_raw_unicode.rb, line 18
def less_show_raw_unicode=(n)
  n = DEFAULT_LESS_SHOW_RAW_UNICODE if n.nil?
  ENV['LESSUTFBINFMT'] = if n.is_a?(String)
    n
  elsif n
    LESS_SHOW_RAW_BINFMT
  else
    nil
  end
  @less_show_raw_unicode = !!n
end
melody!(app = nil) click to toggle source

This modifies pry to play our tune

# File lib/spirit_hands/melody.rb, line 5
def melody!(app = nil)
  return false if @installed
  @installed = true

  Pry.config.should_load_plugins = false
  SpiritHands.app = app unless app.nil?
  setup_less_colorize
  setup_less_show_raw_unicode
  setup_hirb
  disable_remote
  setup_coolline # setup Pry.config.input
  setup_nav
  setup_byebug
  setup_doc

  # Use awesome_print for output, but keep pry's pager. If Hirb is
  # enabled, try printing with it first.
  ::SpiritHands::Print.install!

  # Friendlier prompt - line number, app name, nesting levels look like
  # directory paths.
  #
  # Configuration (like Pry.color) can be changed later or even during console usage.
  ::SpiritHands::Prompt.install!
end

Protected Class Methods

coolline_installed?() click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 26
def coolline_installed?
  Pry.input == @coolline_input[0]
end
input_config() click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 42
def input_config
  [Pry.input, Pry.config.completer]
end
input_config=(args) click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 38
def input_config=(args)
  Pry.input, Pry.config.completer = args
end
install_coolline!() click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 14
def install_coolline!
  return if coolline_installed?
  Pry.plugins['coolline'].activate!
  self.input_config = @coolline_input
end
setup_coolline() click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 46
def setup_coolline
  @orig_input = input_config
  require 'pry-coolline'
  @coolline_input = input_config
  Pry.hooks.add_hook(:before_session, "setup_coolline_before") do |output, binding, pry|
    setup_coolline!
  end
  Pry.hooks.add_hook(:after_eval, "setup_coolline_after") do |code, pry|
    setup_coolline!
  end
end
setup_coolline!() click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 30
def setup_coolline!
  if coolline
    install_coolline!
  else
    uninstall_coolline!
  end
end
uninstall_coolline!() click to toggle source
# File lib/spirit_hands/options/coolline.rb, line 20
def uninstall_coolline!
  return unless coolline_installed?
  Pry.plugins['coolline'].disable!
  self.input_config = @orig_input
end

Private Class Methods

disable_remote() click to toggle source
# File lib/spirit_hands/melody.rb, line 60
def disable_remote
  return if Pry.plugins['remote'].is_a? Pry::PluginManager::NoPlugin
  Pry.plugins['remote'].disable!
end
jruby?() click to toggle source
# File lib/spirit_hands/melody.rb, line 65
def jruby?
  RUBY_ENGINE == 'jruby'
end
setup_byebug() click to toggle source
# File lib/spirit_hands/melody.rb, line 44
def setup_byebug
  return if Pry.plugins['byebug'].is_a? Pry::PluginManager::NoPlugin
  require 'pry-byebug'
  if jruby?
    Pry.plugins['byebug'].disable!
  else
    Pry.plugins['byebug'].activate!
  end
rescue LoadError
end
setup_doc() click to toggle source
# File lib/spirit_hands/melody.rb, line 55
def setup_doc
  require 'pry-doc'
  Pry.plugins['doc'].activate!
end
setup_hirb() click to toggle source
# File lib/spirit_hands/options/hirb.rb, line 25
def setup_hirb
  self.hirb = nil unless @hirb
end
setup_less_colorize() click to toggle source
# File lib/spirit_hands/options/less/colorize.rb, line 37
def setup_less_colorize
  self.less_colorize = nil unless @less_colorize
end
setup_less_show_raw_unicode() click to toggle source
# File lib/spirit_hands/options/less/show_raw_unicode.rb, line 32
def setup_less_show_raw_unicode
  self.less_show_raw_unicode = nil unless @less_show_raw_unicode
end
setup_nav() click to toggle source
# File lib/spirit_hands/melody.rb, line 33
def setup_nav
  return if Pry.plugins['nav'].is_a? Pry::PluginManager::NoPlugin
  require 'pry-nav'
  if jruby?
    Pry.plugins['nav'].activate!
  else
    Pry.plugins['nav'].disable!
  end
rescue LoadError
end