module Pry::Helpers::Text

def bold(text)

Returns:
  • (String) - _text_

Parameters:
  • text (String, #to_s) --
def bold(text)
  "\e[1m#{text}\e[0m"
end

def default(text)

Returns:
  • (String) -

Parameters:
  • text (String, #to_s) --
def default(text)
  text.to_s
end

def indent(text, chars)

Parameters:
  • chars (Fixnum) --
  • text (String) --
def indent(text, chars)
  text.lines.map { |l| "#{' ' * chars}#{l}" }.join
end

def no_color

Returns:
  • (void) -

Other tags:
    Yield: -
def no_color
  boolean = Pry.config.color
  Pry.config.color = false
  yield
ensure
  Pry.config.color = boolean
end

def no_pager

Returns:
  • (void) -

Other tags:
    Yield: -
def no_pager
  boolean = Pry.config.pager
  Pry.config.pager = false
  yield
ensure
  Pry.config.pager = boolean
end

def strip_color(text)

Returns:
  • (String) - _text_ stripped of any color codes.

Parameters:
  • text (String, #to_s) --
def strip_color(text)
  text.to_s.gsub(/(\001)?(\e\[(\d[;\d]?)*m)(\002)?/, '')
end

def with_line_numbers(text, offset, color = :blue)

Returns:
  • (String) -

Parameters:
  • offset (Fixnum) --
  • text (#each_line) --
def with_line_numbers(text, offset, color = :blue)
  lines = text.each_line.to_a
  max_width = (offset + lines.count).to_s.length
  lines.each_with_index.map do |line, index|
    adjusted_index = (index + offset).to_s.rjust(max_width)
    "#{send(color, adjusted_index)}: #{line}"
  end.join
end