Module: SpiritHands

Defined in:
lib/spirit_hands.rb,
lib/spirit_hands/print.rb,
lib/spirit_hands/prompt.rb,
lib/spirit_hands/options.rb,
lib/spirit_hands/version.rb,
lib/spirit_hands/terminal.rb,
lib/spirit_hands/prompt/base.rb,
lib/spirit_hands/prompt/main.rb,
lib/spirit_hands/options/hirb.rb,
lib/spirit_hands/prompt/multiline.rb,
lib/spirit_hands/prompt/base/render.rb,
lib/spirit_hands/options/less/colorize.rb,
lib/spirit_hands/options/less/show_raw_unicode.rb

Overview

Do this to use SpiritHands outside Rails

# .pryrc
require 'spirit_hands'
# ...

Defined Under Namespace

Modules: Print, Prompt, Terminal

Constant Summary collapse

VERSION =
'2.0.14'
DEFAULT_HIRB =
true
DEFAULT_LESS_COLORIZE =
true
LESS_R_LONG =
'--RAW-CONTROL-CHARS'.freeze
LESS_R =
/\A(.*-[^-R]*)R(.*)\z/.freeze
DEFAULT_LESS_SHOW_RAW_UNICODE =
true
LESS_SHOW_RAW_BINFMT =
'*n%c'.freeze

Class Method Summary collapse

Class Method Details

.colorObject

Alias for Pry.color



3
4
5
# File 'lib/spirit_hands/options/color.rb', line 3

def color
  ::Pry.color
end

.color=(v) ⇒ Object



7
8
9
# File 'lib/spirit_hands/options/color.rb', line 7

def color=(v)
  ::Pry.color = v
end

.hirbObject

Is hirb enabled?



6
7
8
# File 'lib/spirit_hands/options/hirb.rb', line 6

def hirb
  ::Hirb.enabled?
end

.hirb=(h) ⇒ Object

Set whether hirb is enabled (default: true)



11
12
13
14
15
16
17
18
19
20
21
# 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_colorizeObject

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



12
13
14
# 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) ⇒ Object

true: add -R to LESS env var (default) false: remove -R from LESS env var

nil: set to default (true)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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_unicodeObject

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



10
11
12
# 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) ⇒ Object

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



18
19
20
21
22
23
24
25
26
27
28
# 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) ⇒ Object

This modifies pry to play our tune



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spirit_hands/melody.rb', line 5

def melody!(app = nil)
  return false if @installed
  @installed = true

  SpiritHands.app = app unless app.nil?
  setup_less_colorize
  setup_less_show_raw_unicode
  setup_hirb

  # 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